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
|
#!/bin/bash
|
||||||
|
|
||||||
# Configuration
|
# 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")
|
TARGET_DIRS=("Source" "Private" "Public" "Classes")
|
||||||
FILE_EXTS=("*.h" "*.cpp" "*.hpp" "*.c")
|
FILE_EXTS=("*.h" "*.cpp" "*.hpp" "*.c")
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
|
@ -20,16 +21,17 @@ done
|
||||||
# Find all source files
|
# Find all source files
|
||||||
FILES=()
|
FILES=()
|
||||||
|
|
||||||
for dir in "../${TARGET_DIRS[@]}"; do
|
for dir in "${TARGET_DIRS[@]}"; do
|
||||||
for ext in "${FILE_EXTS[@]}"; do
|
full_dir="$ROOT_DIR/$dir"
|
||||||
|
if [ -d "$full_dir" ]; then
|
||||||
while IFS= read -r -d $'\0' file; do
|
while IFS= read -r -d $'\0' file; do
|
||||||
FILES+=("$file")
|
FILES+=("$file")
|
||||||
done < <(find "$(pwd)/$dir" -name "$ext" -print0)
|
done < <(find "$full_dir" -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.hpp" -o -name "*.c" \) -print0)
|
||||||
done
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Formatting command
|
# 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"
|
$DRY_RUN && FORMAT_CMD+=" --dry-run --Werror"
|
||||||
|
|
||||||
# Execute formatting
|
# Execute formatting
|
||||||
|
@ -47,6 +49,6 @@ if [ $ERRORS -gt 0 ]; then
|
||||||
echo "❌ $ERRORS files need formatting!"
|
echo "❌ $ERRORS files need formatting!"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "✅ All files formatted correctly!"
|
echo "✅ All ${#FILES[@]} files formatted correctly!"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
Loading…
Reference in a new issue