From bfce9a9e10d348fe7f9d8ba588f83d0a28ad19e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Tue, 10 Dec 2024 15:30:22 +0100 Subject: [PATCH 1/2] clang-format: Use config directly instead of modifying repository --- clang_format/run_clang_format.sh | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/clang_format/run_clang_format.sh b/clang_format/run_clang_format.sh index bb1861d..3442e76 100755 --- a/clang_format/run_clang_format.sh +++ b/clang_format/run_clang_format.sh @@ -8,25 +8,17 @@ format_all() { CLANG_FORMAT_CONFIG=$(realpath $1) cd $BUILD_WORKSPACE_DIRECTORY - if ! test -f .clang-format; then - echo ".clang-format file not found. Bazel will copy the default .clang-format file." - cp $CLANG_FORMAT_CONFIG . - fi git ls-files '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \ - | xargs -r $CLANG_FORMAT_BIN -i + | xargs -r $CLANG_FORMAT_BIN -i --style=file:$CLANG_FORMAT_CONFIG } format_diff() { CLANG_FORMAT_CONFIG=$(realpath $1) cd $BUILD_WORKSPACE_DIRECTORY - if ! test -f .clang-format; then - echo ".clang-format file not found. Bazel will copy the default .clang-format file." - cp $CLANG_FORMAT_CONFIG . - fi git describe --tags --abbrev=0 --always \ | xargs -rI % git diff --diff-filter=ACMRTUXB --name-only --line-prefix=`git rev-parse --show-toplevel`/ % -- '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \ - | xargs -r $CLANG_FORMAT_BIN -i + | xargs -r $CLANG_FORMAT_BIN -i --style=file:$CLANG_FORMAT_CONFIG } check_file() { From ea8076f2ba5b94a571d7d4e52e299edbc84b14d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Tue, 10 Dec 2024 17:38:48 +0100 Subject: [PATCH 2/2] Fix shellcheck smells --- clang_format/run_clang_format.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/clang_format/run_clang_format.sh b/clang_format/run_clang_format.sh index 3442e76..422616c 100755 --- a/clang_format/run_clang_format.sh +++ b/clang_format/run_clang_format.sh @@ -5,20 +5,20 @@ set -ue format_all() { - CLANG_FORMAT_CONFIG=$(realpath $1) + CLANG_FORMAT_CONFIG=$(realpath "$1") - cd $BUILD_WORKSPACE_DIRECTORY + cd "$BUILD_WORKSPACE_DIRECTORY" git ls-files '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \ - | xargs -r $CLANG_FORMAT_BIN -i --style=file:$CLANG_FORMAT_CONFIG + | xargs -r "$CLANG_FORMAT_BIN" -i --style=file:"$CLANG_FORMAT_CONFIG" } format_diff() { - CLANG_FORMAT_CONFIG=$(realpath $1) + CLANG_FORMAT_CONFIG=$(realpath "$1") - cd $BUILD_WORKSPACE_DIRECTORY + cd "$BUILD_WORKSPACE_DIRECTORY" git describe --tags --abbrev=0 --always \ - | xargs -rI % git diff --diff-filter=ACMRTUXB --name-only --line-prefix=`git rev-parse --show-toplevel`/ % -- '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \ - | xargs -r $CLANG_FORMAT_BIN -i --style=file:$CLANG_FORMAT_CONFIG + | xargs -rI % git diff --diff-filter=ACMRTUXB --name-only --line-prefix="$(git rev-parse --show-toplevel)"/ % -- '*.[ch]' '*.cpp' '*.cxx' '*.cc' '*.hpp' '*.hxx' \ + | xargs -r "$CLANG_FORMAT_BIN" -i --style=file:"$CLANG_FORMAT_CONFIG" } check_file() { @@ -28,14 +28,14 @@ check_file() { # .clang-format config file has to be placed in the current working directory if [ ! -f ".clang-format" ]; then - ln -s $CONFIG .clang-format + ln -s "$CONFIG" .clang-format fi - $CLANG_FORMAT_BIN $INPUT --dry-run -Werror > $OUTPUT + $CLANG_FORMAT_BIN "$INPUT" --dry-run -Werror > "$OUTPUT" } ARG=$1 -CLANG_FORMAT_BIN=$(realpath $2) +CLANG_FORMAT_BIN=$(realpath "$2") shift 2 if [ "$ARG" == "format_diff" ]; then