-
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.
Merge pull request tock#4037 from lschuermann/dev/make-format-check
Makefile: remove `format` command in favor of simpler `format-check`
- Loading branch information
Showing
3 changed files
with
71 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,56 @@ | ||
#!/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. | ||
# | ||
# Runs `rustfmt --check` on the workspace and check for tabs in Rust files. | ||
# Must be run from root Tock directory. | ||
# | ||
# 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.