Commit 9239eace authored by Ramon Nou's avatar Ramon Nou
Browse files

Fix clang-tidy coverage compile flags

parent 82db825f
Loading
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -122,7 +122,38 @@ if ${RUN_CLANG_TIDY}; then
                find "${REPO_ROOT}/src" -type f \( -name '*.cpp' -o -name '*.c' \) | sort
            )
        fi
        clang-tidy --checks=-*,clang-analyzer-* -p "${BUILD_DIR}" "${SOURCES[@]}" \

        # The coverage compile database may contain GCC-only flags. Clang-tidy
        # rejects these flags before running any checks, so use a sanitized
        # temporary database while leaving the build database untouched.
        CLANG_TIDY_BUILD_DIR="$(mktemp -d)"
        trap 'rm -rf "${CLANG_TIDY_BUILD_DIR}"' EXIT
        python3 - "${BUILD_DIR}/compile_commands.json" \
                "${CLANG_TIDY_BUILD_DIR}/compile_commands.json" <<'PY'
import json
import sys

source_path, destination_path = sys.argv[1:]
with open(source_path, encoding="utf-8") as source:
    database = json.load(source)

for entry in database:
    if "arguments" in entry:
        entry["arguments"] = [
            argument
            for argument in entry["arguments"]
            if argument != "-fkeep-static-functions"
        ]
    elif "command" in entry:
        entry["command"] = entry["command"].replace(
            " -fkeep-static-functions", ""
        )

with open(destination_path, "w", encoding="utf-8") as destination:
    json.dump(database, destination)
PY

        clang-tidy --checks=-*,clang-analyzer-* -p "${CLANG_TIDY_BUILD_DIR}" "${SOURCES[@]}" \
            >"${OUTPUT_DIR}/clang-tidy.txt" 2>&1
    elif ${REQUIRE_TOOLS}; then
        die "clang-tidy is not installed"