From 5abebd12645bc38c187a1c4b9e57e73fe7cd07b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Thu, 23 Apr 2026 19:12:29 +0200 Subject: [PATCH 1/3] Improve o2checkcode --- o2checkcode.sh | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/o2checkcode.sh b/o2checkcode.sh index b796756dfe..85ffebef4b 100644 --- a/o2checkcode.sh +++ b/o2checkcode.sh @@ -25,7 +25,7 @@ O2_SRC=$(python3 -c 'import json, os; print(os.path.commonpath([x["file"] for x # We have something to compare our working directory to (ALIBUILD_BASE_HASH). We check only the # changed files (including the untracked ones) if the list of relevant files that changed is up to # 50 entries long -if [[ $ALIBUILD_BASE_HASH ]]; then +if [[ -n "${ALIBUILD_BASE_HASH:-}" ]]; then pushd "$O2_SRC" [[ -d .git ]] ( git diff --name-only $ALIBUILD_BASE_HASH${ALIBUILD_HEAD_HASH:+...$ALIBUILD_HEAD_HASH} || true ; git ls-files --others --exclude-standard ) | ( grep -E '\.cxx$|\.h$' || true ) | sort -u > $BUILDDIR/changed @@ -46,44 +46,24 @@ fi ThinCompilationsDatabase.py -exclude-files '(?:.*G\_\_.*\.cxx|.*\.pb.cc|.*\_amalgamated\..*)' ${O2_CHECKCODE_CHANGEDFILES:+-use-files ${O2_CHECKCODE_CHANGEDFILES}} cp thinned_compile_commands.json compile_commands.json -# List of explicitely enabled C++ checks (make sure they are all green) -CHECKS="${O2_CHECKER_CHECKS:--*\ -,modernize-avoid-bind\ -,modernize-deprecated-headers\ -,modernize-make-shared\ -,modernize-raw-string-literal\ -,modernize-redundant-void-arg\ -,modernize-replace-auto-ptr\ -,modernize-replace-random-shuffle\ -,modernize-shrink-to-fit\ -,modernize-unary-static-assert\ -,modernize-use-equals-default\ -,modernize-use-noexcept\ -,modernize-use-nullptr\ -,modernize-use-override\ -,modernize-use-transparent-functors\ -,modernize-use-uncaught-exceptions\ -,readability-braces-around-statements\ -,-clang-diagnostic-vla-cxx-extension\ -}" - -echo $CHECKS -$CLANG_ROOT/bin-safe/clang-tidy --load $O2CODECHECKER_ROOT/lib/libclangTidyAliceO2Module.so --list-checks -checks="*" +pushd "$O2_SRC" # Needed to auto-detect .clang-tidy in the source directory. +[[ -e .clang-tidy ]] && echo "Found configuration file: $O2_SRC/.clang-tidy" +echo "Additional checks on command line: \"${O2_CHECKER_CHECKS=""}\"" +$CLANG_ROOT/bin-safe/clang-tidy --load $O2CODECHECKER_ROOT/lib/libclangTidyAliceO2Module.so --list-checks --checks="$O2_CHECKER_CHECKS" # Run C++ checks run_O2CodeChecker.py ${JOBS+-j $JOBS} \ - -clang-tidy-binary $CLANG_ROOT/bin-safe/clang-tidy \ - -clang-apply-replacements-binary "$CLANG_ROOT/bin-safe/clang-apply-replacements" \ + -clang-tidy-binary $CLANG_ROOT/bin-safe/clang-tidy \ + -clang-apply-replacements-binary "$CLANG_ROOT/bin-safe/clang-apply-replacements" \ -extra-args="--load $O2CODECHECKER_ROOT/lib/libclangTidyAliceO2Module.so ${GCC_TOOLCHAIN_REVISION:+--extra-arg=--gcc-install-dir=$(find \"$GCC_TOOLCHAIN_ROOT/lib\" -name crtbegin.o -exec dirname {} \;)}" \ - -header-filter='.*SOURCES(?!.*/3rdparty/).*' \ - ${O2_CHECKER_FIX:+-fix} -checks="$CHECKS" 2>&1 | tee error-log.txt - -# Turn warnings into errors -sed -e 's/ warning:/ error:/g' error-log.txt > error-log.txt.0 && mv error-log.txt.0 error-log.txt + -header-filter='.*SOURCES(?!.*/3rdparty/).*' \ + -p="${BUILDDIR}" \ + ${O2_CHECKER_FIX:+-fix} -checks="$O2_CHECKER_CHECKS" 2>&1 | tee "${BUILDDIR}/error-log.txt" +popd # Show only errors from the log, break in case some were found -echo ; echo ; echo "========== List of errors found ==========" +echo -e "\n\n========== List of errors found ==========" GRERR=0 -grep -v clang-diagnostic-error error-log.txt | grep " error:" || GRERR=$? +grep -v clang-diagnostic-error error-log.txt | grep -E ".+: (warning|error): " || GRERR=$? [[ $GRERR == 0 ]] && exit 1 # Dummy modulefile From 7339556e9173736d652377e5984332cbb2260002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Tue, 23 Jun 2026 17:38:28 +0200 Subject: [PATCH 2/3] Exit gracefully if git diff fails. --- o2checkcode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/o2checkcode.sh b/o2checkcode.sh index 85ffebef4b..ae0f2f76ea 100644 --- a/o2checkcode.sh +++ b/o2checkcode.sh @@ -28,7 +28,7 @@ O2_SRC=$(python3 -c 'import json, os; print(os.path.commonpath([x["file"] for x if [[ -n "${ALIBUILD_BASE_HASH:-}" ]]; then pushd "$O2_SRC" [[ -d .git ]] - ( git diff --name-only $ALIBUILD_BASE_HASH${ALIBUILD_HEAD_HASH:+...$ALIBUILD_HEAD_HASH} || true ; git ls-files --others --exclude-standard ) | ( grep -E '\.cxx$|\.h$' || true ) | sort -u > $BUILDDIR/changed + ( git diff --name-only $ALIBUILD_BASE_HASH${ALIBUILD_HEAD_HASH:+...$ALIBUILD_HEAD_HASH} || { echo "Git diff failed."; exit 0; } ; git ls-files --others --exclude-standard ) | ( grep -E '\.cxx$|\.h$' || true ) | sort -u > $BUILDDIR/changed if [[ $(cat $BUILDDIR/changed | wc -l) -le 50 ]]; then O2_CHECKCODE_CHANGEDFILES=$(while read FILE; do [[ -e "$O2_SRC/$FILE" ]] && echo "$FILE" || true; done < <(cat $BUILDDIR/changed) | \ xargs echo | sed -e 's/ /:/g') From 2a891cc80e811e0e6f70c112be68e804c8da014c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Wed, 1 Jul 2026 01:14:22 +0200 Subject: [PATCH 3/3] Report errors and warnings separately. Fail on errors only. --- o2checkcode.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/o2checkcode.sh b/o2checkcode.sh index ae0f2f76ea..d611781a8d 100644 --- a/o2checkcode.sh +++ b/o2checkcode.sh @@ -62,9 +62,14 @@ popd # Show only errors from the log, break in case some were found echo -e "\n\n========== List of errors found ==========" -GRERR=0 -grep -v clang-diagnostic-error error-log.txt | grep -E ".+: (warning|error): " || GRERR=$? -[[ $GRERR == 0 ]] && exit 1 +grep -v clang-diagnostic-error error-log.txt | grep -E ".+: error: " | sort -V | uniq > errors.txt || true +grep -v clang-diagnostic-error error-log.txt | grep -E ".+: warning: " | sort -V | uniq > warnings.txt || true +N_ERROR=$(wc -l < errors.txt) +N_WARNING=$(wc -l < warnings.txt) +echo "Found $N_ERROR errors and $N_WARNING warnings." +[[ $N_ERROR -gt 0 ]] && cat errors.txt +[[ $N_WARNING -gt 0 ]] && cat warnings.txt +[[ $N_ERROR -gt 0 ]] && exit 1 # Dummy modulefile mkdir -p $INSTALLROOT/etc/modulefiles