fix script
Some checks failed
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 24s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 24s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Successful in 25s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Successful in 25s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Successful in 21s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Successful in 17s
Bigfoot / Clang Format Checks (push) Failing after 8s
Some checks failed
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 24s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 24s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: OFF) (push) Successful in 25s
Bigfoot / Build & Test RelWithDebInfo (Unity Build: ON) (push) Successful in 25s
Bigfoot / Build & Test Release (Unity Build: OFF) (push) Successful in 21s
Bigfoot / Build & Test Release (Unity Build: ON) (push) Successful in 17s
Bigfoot / Clang Format Checks (push) Failing after 8s
This commit is contained in:
82
format.sh
82
format.sh
@@ -1,31 +1,63 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Variable that will hold the name of the clang-format command
|
||||
FMT="clang-format"
|
||||
MODE=""
|
||||
DIRS=()
|
||||
|
||||
# Function to format files
|
||||
format() {
|
||||
for f in $(find "$1" \( -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \)); do
|
||||
# Skip *_generated.h files
|
||||
if [[ "$f" == *_generated* ]]; then
|
||||
continue
|
||||
# Parse arguments
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--check)
|
||||
MODE="check"
|
||||
;;
|
||||
--fix)
|
||||
MODE="fix"
|
||||
;;
|
||||
*)
|
||||
DIRS+=("$arg")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$MODE" ]]; then
|
||||
echo "Usage: $0 --check|--fix <directory> [<directory> ...]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${#DIRS[@]} -eq 0 ]]; then
|
||||
echo "Please provide at least one directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
EXIT_CODE=0
|
||||
|
||||
for DIR in "${DIRS[@]}"; do
|
||||
if [[ ! -d "$DIR" ]]; then
|
||||
echo "$DIR is not a valid directory."
|
||||
EXIT_CODE=1
|
||||
continue
|
||||
fi
|
||||
|
||||
while IFS= read -r -d '' file; do
|
||||
[[ "$file" == *_generated* ]] && continue
|
||||
|
||||
if [[ "$MODE" == "fix" ]]; then
|
||||
echo "Formatting $file"
|
||||
$FMT -i "$file"
|
||||
else
|
||||
# Check mode: run clang-format with dry-run and Werror
|
||||
# Capture stdout/stderr for diagnostic
|
||||
if ! $FMT --dry-run --Werror "$file"; then
|
||||
# clang-format will already print:
|
||||
# Bigfoot/Tests/System/Time.cpp:21:46: error: code should be clang-formatted [-Wclang-format-violations]
|
||||
# Now additionally print the diff for clarity
|
||||
diff_output=$(diff -u "$file" <($FMT -style=file "$file") || true)
|
||||
echo "$diff_output"
|
||||
EXIT_CODE=1
|
||||
fi
|
||||
fi
|
||||
echo "format ${f}"
|
||||
${FMT} -i "${f}"
|
||||
done
|
||||
echo "~~~ $1 Done ~~~"
|
||||
}
|
||||
done < <(find "$DIR" \( -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.m' -o -name '*.mm' \) -print0)
|
||||
done
|
||||
|
||||
# Check if argument is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Please provide a directory as an argument."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if directory exists
|
||||
if [ ! -d "$1" ]; then
|
||||
echo "$1 is not a valid directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
format "$1"
|
||||
exit $EXIT_CODE
|
||||
|
||||
Reference in New Issue
Block a user