diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-06-17 12:42:05 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2019-06-17 13:35:47 +0200 |
commit | 24ee8c3566c7ef5469df762c1daa21b330e2dd82 (patch) | |
tree | 646a7952fbfc134a3fdce10cdbf33cfb7395c307 /misc/scripts/fix_style.sh | |
parent | 0d61fc2c0f1d7625c866c79b6c4044fbab61a768 (diff) |
Add script to fix style issues and copyright headers
This is only meant to check the validity of the whole codebase every
now and then, or to apply clang-format config changes when relevant.
Diffstat (limited to 'misc/scripts/fix_style.sh')
-rwxr-xr-x | misc/scripts/fix_style.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/misc/scripts/fix_style.sh b/misc/scripts/fix_style.sh new file mode 100755 index 0000000000..7a335c21ea --- /dev/null +++ b/misc/scripts/fix_style.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Command line arguments +run_clang_format=false +run_fix_headers=false +usage="Invalid argument. Usage:\n$0 <option>\n\t--clang-format|-c\n\t--headers|-h\n\t--all|-a" + +if [ -z "$1" ]; then + echo -e $usage + exit 0 +fi + +while [ $# -gt 0 ]; do + case "$1" in + --clang-format|-c) + run_clang_format=true + ;; + --headers|-h) + run_fix_headers=true + ;; + --all|-a) + run_clang_format=true + run_fix_headers=true + ;; + *) + echo -e $usage + exit 0 + esac + shift +done + +echo "Removing generated files, some have binary data and make clang-format freeze." +find -name "*.gen.*" -delete + +# Apply clang-format +if $run_clang_format; then + # Sync list with pre-commit hook + FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc .java .glsl" + + for extension in ${FILE_EXTS}; do + echo -e "Formatting ${extension} files..." + find \( -path "./.git" \ + -o -path "./thirdparty" \ + -o -path "./platform/android/java/src/com" \ + \) -prune \ + -o -name "*${extension}" \ + -exec clang-format -i {} \; + done +fi + +# Add missing copyright headers +if $run_fix_headers; then + echo "Fixing copyright headers in Godot code files..." + find \( -path "./.git" -o -path "./thirdparty" \) -prune \ + -o -regex '.*\.\(c\|h\|cpp\|hpp\|cc\|hh\|cxx\|m\|mm\|java\)' \ + > tmp-files + cat tmp-files | grep -v ".git\|thirdparty\|theme_data.h\|platform/android/java/src/com\|platform/android/java/src/org/godotengine/godot/input/InputManager" > files + python misc/scripts/fix_headers.py + rm -f tmp-files files +fi |