Make the script always based on git root directory
This commit is contained in:
parent
8727015356
commit
ba998dda99
1 changed files with 9 additions and 7 deletions
|
@ -1,7 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
CONFIG_FILE="$(dirname "$0")/.clang-format"
|
||||
ROOT_DIR=$(git rev-parse --show-toplevel)
|
||||
CONFIG_FILE="$ROOT_DIR/.tools/.clang-format"
|
||||
TARGET_DIRS=("Source" "Private" "Public" "Classes")
|
||||
FILE_EXTS=("*.h" "*.cpp" "*.hpp" "*.c")
|
||||
DRY_RUN=false
|
||||
|
@ -20,16 +21,17 @@ done
|
|||
# Find all source files
|
||||
FILES=()
|
||||
|
||||
for dir in "../${TARGET_DIRS[@]}"; do
|
||||
for ext in "${FILE_EXTS[@]}"; do
|
||||
for dir in "${TARGET_DIRS[@]}"; do
|
||||
full_dir="$ROOT_DIR/$dir"
|
||||
if [ -d "$full_dir" ]; then
|
||||
while IFS= read -r -d $'\0' file; do
|
||||
FILES+=("$file")
|
||||
done < <(find "$(pwd)/$dir" -name "$ext" -print0)
|
||||
done
|
||||
done < <(find "$full_dir" -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.hpp" -o -name "*.c" \) -print0)
|
||||
fi
|
||||
done
|
||||
|
||||
# Formatting command
|
||||
FORMAT_CMD="./clang-format -style=file:$CONFIG_FILE -i"
|
||||
FORMAT_CMD="$ROOT_DIR/.tools/clang-format -style=file:$CONFIG_FILE -i"
|
||||
$DRY_RUN && FORMAT_CMD+=" --dry-run --Werror"
|
||||
|
||||
# Execute formatting
|
||||
|
@ -47,6 +49,6 @@ if [ $ERRORS -gt 0 ]; then
|
|||
echo "❌ $ERRORS files need formatting!"
|
||||
exit 1
|
||||
else
|
||||
echo "✅ All files formatted correctly!"
|
||||
echo "✅ All ${#FILES[@]} files formatted correctly!"
|
||||
exit 0
|
||||
fi
|
Loading…
Reference in a new issue