Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

lschuermann
Copy link
Member

@lschuermann lschuermann commented Feb 6, 2021

Pull Request Overview

This pull request removes tab characters from Tock's Rust codebase, most of which have been accidentally introduced by me. Whoops, sorry!

While I don't want to "police" anyone's code style, Tock's codebase uses almost exclusively spaces. rustfmt seems to replace tabs by spaces pretty consistently, but it appears to have a hard time in macro invocations and some other places. Given that there is no defined standard width for representing tabs in Tock's Rust files, and we're interleaving tabs with spaces, this makes for a very inconsistent indentation depending on the editor's configuration.

Furthermore, this adds a check for tab characters in the codebase to the run_cargo_fmt.sh script. It uses git grep if available, and falls back to the system's grep otherwise. It has been tested with GNU grep and might require small modifications for BSD grep. The check's overhead isn't noticeable (compared to the cargo fmt invocations), even on some low-end systems of mine.

Output prior to removing the tab characters from the codebase:

$ make format
Formatting complete.                                        
ERROR: The following files contain tab characters, please use spaces instead:
    -> boards/components/src/led.rs
    -> boards/components/src/led_matrix.rs
    -> capsules/src/l3gd20.rs
    -> capsules/src/lsm303agr.rs
    -> capsules/src/lsm303dlhc.rs
    -> capsules/src/mlx90614.rs
    -> chips/stm32f303xc/src/i2c.rs
    -> kernel/src/debug.rs

Formatting errors.
See above for details
make: *** [Makefile:166: tools/.format_fresh] Error 1

Testing Strategy

This pull request was tested by running the script against the codebase with tab characters, and against the properly formatted one. It requires testing on a machine with BSD grep (such as macOS).

TODO or Help Wanted

I'd appreciate someone with access to a machine having BSD grep to test the fallback to the system's installed grep.

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@lschuermann lschuermann requested a review from bradjc February 6, 2021 11:46
@github-actions github-actions bot added kernel chips/stm32 Change pertains to the stm32 family of MCUSs labels Feb 6, 2021
Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change, just too bad we still have to do this in 2021!

@@ -377,9 +377,9 @@ impl Driver for L3gd20Spi<'_> {
) -> ReturnCode {
match subscribe_num {
0 /* set the one shot callback */ => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI this is a known rustfmt issue: rust-lang/rustfmt#4119

phil-levis
phil-levis previously approved these changes Feb 8, 2021
Copy link
Contributor

@phil-levis phil-levis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good once Brad's comment is addressed.

Some tab characters will not be replaced by spaces through rustfmt. To
avoid these making it into the repository, add an additional check for
tab characters.

If available, the fast "git grep" will be used, otherwise it will
fall back to the system grep. This has been tested with GNU grep.
It appears that rustfmt does not always remove tab characters, in
particular as part of macro invocations. This removes (accidentally)
inserted tab characters for a consistent code style.
@bradjc
Copy link
Contributor

bradjc commented Feb 10, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 10, 2021

@bors bors bot merged commit 3d9ccc3 into tock:master Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chips/stm32 Change pertains to the stm32 family of MCUSs kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants