8000 Makefile: remove `format` command in favor of simpler `format-check` by lschuermann · Pull Request #4037 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Makefile: remove format command in favor of simpler format-check #4037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2024

Conversation

lschuermann
Copy link
Member

Pull Request Overview

This removes the make format command which, in essence, runs some bash magic to achieve the exact same job that cargo fmt does, if its run within workspace instead of a particular crate. Besides this, many people's editors have a native rustfmt integration anyways, which makes this script and its prompt for unstaged files largely redundant.

Instead, we replace it with the more useful make format-check and the associated tools/check_format.sh. This script does more than cargo fmt --check does, for instance also ensuring that no Rust source file contains tab characters (which rustfmt sometimes leaves behind).

As part of make prepush, check-format is now more in line with the other jobs, such as cargo check or Clippy: it'll complain, but not touch any source code.

This also removes an optimization that uses Make's logic to check for changed files in order to skip formatting. However, I doubt that this will meaningfully impact users (make format-check completes in about 2sec and does not take a meaningful amount of time compared to the other jobs executed as part of prepush).

Testing Strategy

CI / running make commands.

TODO or Help Wanted

N/A

Documentation Updated

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

Formatting

  • Ran make prepush.

@lschuermann lschuermann requested a review from bradjc June 18, 2024 18:51
Copy link
Member
@ppannuto ppannuto left a comment

Choose a reason for hiding this comment

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

This seems fine to me.

I have one concern in current form. If I understand correctly, we can be in a situation where cargo fmt runs but then make format-check fails, because of tab characters? It seems a bit of a regression that there's no command I can run that results in "force everything to conform to the format checker".

Might still need a wrapper bash script around cargo fmt, albeit a simpler one, for the tab issue?

Makefile Outdated
@./tools/run_cargo_fmt.sh $(TOCK_FORMAT_MODE)
@touch tools/.format_fresh
.PHONY: fmt format-check
fmt format-check:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt format-check:
format-check:

or, if we're committed to keeping a shorthand fmt-chk, but fmt alone is a verb that formats IMHO, which this no longer does IIUC

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I completely missed this shorthand. Happy to update.

@lschuermann
Copy link
Member Author

Might still need a wrapper bash script around cargo fmt, albeit a simpler one, for the tab issue?

It's a rare enough issue that I don't think we'll hit it much in practice, but I'll let the jury decide.

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.

I need make fmt to be an alias for cargo fmt. We might as well also keep make format as well.

@bradjc
Copy link
Contributor
bradjc commented Jun 18, 2024

Might still need a wrapper bash script around cargo fmt, albeit a simpler one, for the tab issue?

It's a rare enough issue that I don't think we'll hit it much in practice, but I'll let the jury decide.

I think as long as CI ensures it's fixed we're fine.

@bradjc
Copy link
Contributor
bradjc commented Jun 18, 2024

I need make fmt to be an alias for cargo fmt. We might as well also keep make format as well.

Those commands date to 2016: d4f62cf (Also wow my attitude on commands has changed! Now I say shorter the better! But code should be descriptive.)

@lschuermann
Copy link
Member Author

I need make fmt to be an alias for cargo fmt. We might as well also keep make format as well.

Sure, will re-add. From the discussion in the slack #core channel I reckon that for this explicit command (when it's not invoked as part of another) we don't need the git prompt though?

In that case I'll literally alias it to cargo fmt, which will do the right thing(TM).

In the future this make fmt command will also allow us to add additional formatting steps, like removing tab characters (maybe, if we're confident this can't break anything), reflowing Markdown, adding TOCs, etc.

This removes the previous `make format` command which, in essence,
runs some bash magic to achieve the exact same job that `cargo fmt`
does, if its run within workspace instead of a particular
crate. Besides this, many people's editors have a native rustfmt
integration anyways, which makes this script and its prompt for
unstaged files largely redundant.

Instead, we replace it with the more useful `make format-check` and
the associated `tools/check_format.sh`. This script does more than
`cargo fmt --check` does, for instance also ensuring that no Rust
source file contains tab characters (which rustfmt sometimes leaves
behind).

As part of `make prepush`, `check-format` is now more in line with the
other jobs, such as `cargo check` or Clippy: it'll complain, but not
touch any source code.

To retain compatibility, we introduce a `make format` and `make fmt`,
aliased to `cargo fmt` -- without prompting the user.

This also removes an optimization that uses Make's logic to check for
changed files in order to skip formatting. However, I doubt that this
will meaningfully impact users (`make format-check` completes in about
2sec and does not take a meaningful amount of time compared to the
other jobs executed as part of `prepush`).
@lschuermann
Copy link
Member Author

Should be good to go then!

Co-authored-by: Brad Campbell <bradjc5@gmail.com>
@bradjc bradjc added the last-call Final review period for a pull request. label Jul 5, 2024
@ppannuto ppannuto added this pull request to the merge queue Jul 5, 2024
Merged via the queue into tock:master with commit 7d53362 Jul 5, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
last-call Final review period for a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0