Rename format_all.sh as format_rust.sh

This commit is contained in:
jiangjianfeng 2026-01-15 07:34:27 +00:00
parent c4ccee8e28
commit 6befa7f242
2 changed files with 36 additions and 9 deletions

View File

@ -314,7 +314,7 @@ book:
.PHONY: format
format:
@./tools/format_all.sh
@./tools/format_rust.sh
@$(MAKE) --no-print-directory -C distro format
@$(MAKE) --no-print-directory -C test/initramfs format
@$(MAKE) --no-print-directory -C test/nixos format
@ -322,7 +322,7 @@ format:
.PHONY: check
check: initramfs $(CARGO_OSDK)
@# Check formatting issues of the Rust code
@./tools/format_all.sh --check
@./tools/format_rust.sh --check
@
@# Check compilation of the Rust code
@$(MAKE) --no-print-directory -C kernel check

View File

@ -4,6 +4,24 @@
set -e
# --- Help message ---
show_help() {
cat << EOF
Usage: $0 [OPTION]
Format all Rust code in the workspace, including excluded crates and special files.
OPTIONS:
--check Check if code is formatted (do not modify files)
--help Display this help message and exit
EXAMPLES:
$0 # Format all applicable Rust code
$0 --check # Check formatting without modifying files
EOF
}
WORKSPACE_ROOT="$(dirname "$(readlink -f "$0")")/.."
EXCLUDED_CRATES=$(sed -n -e 's/#.*//; /^\s*$/d' -e '/^\[workspace\]/,/^\[.*\]/{/exclude = \[/,/\]/p}' "$WORKSPACE_ROOT/Cargo.toml" | grep -v "exclude = \[" | tr -d '", \]')
@ -11,14 +29,23 @@ EXCLUDED_CRATES=$(sed -n -e 's/#.*//; /^\s*$/d' -e '/^\[workspace\]/,/^\[.*\]/{/
CHECK_MODE=false
if [ "$#" -eq 1 ]; then
if [ "$1" == "--check" ]; then
CHECK_MODE=true
else
echo "Error: Invalid argument. Only '--check' is allowed."
exit 1
fi
case "$1" in
--help)
show_help
exit 0
;;
--check)
CHECK_MODE=true
;;
*)
echo "Error: Invalid argument '$1'."
echo "Run '$0 --help' for usage."
exit 1
;;
esac
elif [ "$#" -gt 1 ]; then
echo "Error: Too many arguments. Only '--check' is allowed."
echo "Error: Too many arguments."
echo "Run '$0 --help' for usage."
exit 1
fi