GiteaCI (#3)
All checks were successful
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 24s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 25s
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 20s
Bigfoot / Clang Format Checks (push) Successful in 9s
All checks were successful
Bigfoot / Build & Test Debug (Unity Build: OFF) (push) Successful in 24s
Bigfoot / Build & Test Debug (Unity Build: ON) (push) Successful in 25s
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 20s
Bigfoot / Clang Format Checks (push) Successful in 9s
Reviewed-on: #3 Co-authored-by: Romain BOULLARD <romain.boullard@protonmail.com> Co-committed-by: Romain BOULLARD <romain.boullard@protonmail.com>
This commit was merged in pull request #3.
This commit is contained in:
87
format.sh
87
format.sh
@@ -1,31 +1,68 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Variable that will hold the name of the clang-format command
|
||||
FMT="clang-format"
|
||||
MODE=""
|
||||
DIRS=()
|
||||
EXIT_CODE=0
|
||||
|
||||
# Function to format files
|
||||
format() {
|
||||
for f in $(find "$1" \( -name '*.h' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \)); do
|
||||
# Skip *_generated.h files
|
||||
if [[ "$f" == *_generated.h ]]; then
|
||||
continue
|
||||
# =========================
|
||||
# Parse arguments
|
||||
# =========================
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--check)
|
||||
MODE="check"
|
||||
;;
|
||||
--fix)
|
||||
MODE="fix"
|
||||
;;
|
||||
*)
|
||||
DIRS+=("$arg")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Ensure mode is set
|
||||
if [[ -z "$MODE" ]]; then
|
||||
echo "Usage: $0 --check|--fix <directory> [<directory> ...]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure at least one directory
|
||||
if [[ ${#DIRS[@]} -eq 0 ]]; then
|
||||
echo "Please provide at least one directory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# =========================
|
||||
# Process directories
|
||||
# =========================
|
||||
for DIR in "${DIRS[@]}"; do
|
||||
if [[ ! -d "$DIR" ]]; then
|
||||
echo "$DIR is not a valid directory."
|
||||
EXIT_CODE=1
|
||||
continue
|
||||
fi
|
||||
|
||||
# Find all source files safely (null-separated)
|
||||
while IFS= read -r -d '' FILE; do
|
||||
[[ "$FILE" == *_generated* ]] && continue
|
||||
|
||||
if [[ "$MODE" == "fix" ]]; then
|
||||
echo "Formatting $FILE"
|
||||
"$FMT" -i "$FILE"
|
||||
else
|
||||
echo "Checking $FILE"
|
||||
# Check mode: clang-format diagnostic only
|
||||
if ! "$FMT" --dry-run --Werror "$FILE"; then
|
||||
# clang-format prints: file:line:col: error ...
|
||||
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