From 5167781e4464e7d4e1c19888cfb4f11cb37abc05 Mon Sep 17 00:00:00 2001 From: Andi Drebes Date: Tue, 8 Jun 2021 15:20:22 +0200 Subject: [PATCH] ci(compiler): Add option --fix to lint_cpp.sh Add an option `--fix` to `lint_cpp.sh` advising `clang-tidy` to apply suggested fixes. --- .github/workflows/scripts/lint_cpp.sh | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scripts/lint_cpp.sh b/.github/workflows/scripts/lint_cpp.sh index cdf1414a1..0ba57f8e7 100755 --- a/.github/workflows/scripts/lint_cpp.sh +++ b/.github/workflows/scripts/lint_cpp.sh @@ -1,5 +1,16 @@ #!/bin/bash +print_usage() { + local FD=$1 + echo "Usage: $0 [OPTION]" >&$FD + echo "Check if the sources comply with the checks from .clang-tidy" >&$FD + echo "" >&$FD + echo "Options:" >&$FD + echo " -f, --fix Advise clang-tidy to fix any issue" >&$FD + echo " found." >&$FD + echo " -h, --help Print this help." >&$FD +} + die() { echo "$@" >&2 exit 1 @@ -13,6 +24,28 @@ check_buildfile() { "directory." } +CLANG_TIDY_EXTRA_ARGS=() + +# Parse arguments +while [ $# -gt 0 ] +do + case $1 in + -f|--fix) + CLANG_TIDY_EXTRA_ARGS+=("--fix") + ;; + -h|--help) + print_usage 1 + exit 0 + ;; + *) + print_usage 2 + exit 1 + ;; + esac + + shift +done + check_buildfile "CMakeFiles/CMakeDirectoryInformation.cmake" check_buildfile "compile_commands.json" @@ -29,4 +62,5 @@ TOP_SRCDIR=$(grep -o 'set\s*(\s*CMAKE_RELATIVE_PATH_TOP_SOURCE\s\+"[^"]\+")' \ find "$TOP_SRCDIR/"{include,lib,src} \ \( -iname "*.h" -o -iname "*.cpp" -o -iname "*.cc" \) | \ - xargs clang-tidy -p . -header-filter="$TOP_SRCDIR/include/.*\.h" + xargs clang-tidy -p . -header-filter="$TOP_SRCDIR/include/.*\.h" \ + "${CLANG_TIDY_EXTRA_ARGS[@]}"