-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makefile: alias
format
to cargo fmt
, add format-check
command
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`).
- Loading branch information
1 parent
5a65d68
commit 12ae6a1
Showing
3 changed files
with
68 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Licensed under the Apache License, Version 2.0 or the MIT License. | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
# Copyright Tock Contributors 2023. | ||
# | ||
# Author: Leon Schuermann <[email protected]> | ||
# Author: Pat Pannuto <[email protected]> | ||
# Author: Brad Campbell <[email protected]> | ||
# | ||
set -e | ||
|
||
# Verify that we're running in the base directory | ||
if [ ! -x tools/check_format.sh ]; then | ||
echo ERROR: $0 must be run from the tock repository root. | ||
echo "" | ||
exit 1 | ||
fi | ||
|
||
set +e | ||
let FAIL=0 | ||
set -e | ||
|
||
# Run `cargo fmt --check` in the workspace root, which will check all | ||
# crates in the workspace. | ||
echo "Running \`cargo fmt --check\`..." | ||
CARGO_FMT_CHECK_EXIT_CODE=0 | ||
cargo fmt --check || CARGO_FMT_CHECK_EXIT_CODE=$? | ||
if [[ $CARGO_FMT_CHECK_EXIT_CODE -ne 0 ]]; then | ||
let FAIL=FAIL+1 | ||
else | ||
echo "\`cargo fmt --check\` suceeded." | ||
fi | ||
printf "\n" | ||
|
||
# Check for tab characters in Rust source files that haven't been | ||
# removed by rustfmt | ||
echo "Checking for Rust source files with tab characters..." | ||
RUST_FILES_WITH_TABS="$(git grep --files-with-matches $'\t' -- '*.rs' || grep -lr --include '*.rs' $'\t' . || true)" | ||
if [ "$RUST_FILES_WITH_TABS" != "" ]; then | ||
echo "ERROR: The following files contain tab characters, please use spaces instead:" | ||
echo "$RUST_FILES_WITH_TABS" | sed 's/^/ -> /' | ||
let FAIL=FAIL+1 | ||
else | ||
echo "No Rust source file containing tab characters found." | ||
fi | ||
|
||
if [[ $FAIL -ne 0 ]]; then | ||
printf "\n" | ||
echo "$(tput bold)Formatting errors.$(tput sgr0)" | ||
echo "See above for details. You can try running \`cargo fmt\` to correct them." | ||
fi | ||
exit $FAIL |
This file was deleted.
Oops, something went wrong.