From: Remi Gacogne Date: Mon, 2 Oct 2023 08:48:18 +0000 (+0200) Subject: build-and-test-all: Fix clang-tidy now that we build in dist dirs X-Git-Tag: rec-5.0.0-alpha2~19^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16fa78918dfd6fcdb28708d942dec9523838ceb7;p=thirdparty%2Fpdns.git build-and-test-all: Fix clang-tidy now that we build in dist dirs --- diff --git a/.github/scripts/helpers.py b/.github/scripts/helpers.py index cc170d1eed..36969c8060 100644 --- a/.github/scripts/helpers.py +++ b/.github/scripts/helpers.py @@ -1,7 +1,9 @@ """Helpers for dealing with git, compilation databases, etc.""" +import pathlib import json import os +import sys import git import yaml @@ -46,3 +48,28 @@ def index_compdb(file_contents): filename = os.path.join(item["directory"], item["file"]) result.add(filename) return result + +def normalize_dist_dir(version, distPath): + """Map the path of a source file from inside the dist directory + to its path in the git repository.""" + # get rid of the distdir path, to get file paths as they are in the repository + repositoryPath = pathlib.Path(get_repo_root()).resolve() + distPath = pathlib.Path(distPath).resolve() + if f'pdns-{version}' in distPath.parts: + # authoritative or tool + authPath = repositoryPath.joinpath(f'pdns-{version}').resolve() + relativeToAuth = distPath.relative_to(authPath) + return str(repositoryPath.joinpath(relativeToAuth)) + + if f'pdns-recursor-{version}' in distPath.parts: + recPath = repositoryPath.joinpath('pdns', 'recursordist', f'pdns-recursor-{version}').resolve() + relativeToRec = distPath.relative_to(recPath) + return str(repositoryPath.joinpath('pdns', 'recursordist', relativeToRec).resolve()) + + if f'dnsdist-{version}' in distPath.parts: + dnsdistPath = repositoryPath.joinpath('pdns', 'dnsdistdist', f'dnsdist-{version}').resolve() + relativeToDist = distPath.relative_to(dnsdistPath) + return str(repositoryPath.joinpath('pdns', 'dnsdistdist', relativeToDist).resolve()) + + print(f'Unable to map {distPath}', file=sys.stderr) + return str(distPath) diff --git a/.github/scripts/normalize_paths_in_compilation_database.py b/.github/scripts/normalize_paths_in_compilation_database.py new file mode 100644 index 0000000000..f5645fb390 --- /dev/null +++ b/.github/scripts/normalize_paths_in_compilation_database.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import argparse +import os + +import json + +import helpers + +def create_argument_parser(): + """Create command-line argument parser.""" + parser = argparse.ArgumentParser( + description="Normalize paths in compilation database" + ) + parser.add_argument( + "--version", + type=str, + required=True, + help="Version number of the current build", + ) + parser.add_argument('database') + return parser.parse_args() + +if __name__ == "__main__": + """Start the script.""" + args = create_argument_parser() + + compDB = helpers.load_compdb(args.database) + for entry in compDB: + for key in ['file', 'directory']: + if key in entry: + entry[key] = helpers.normalize_dist_dir(args.version, entry[key]) + + with open(args.database + '.temp', 'w', encoding='utf-8') as outputFile: + json.dump(compDB, outputFile, ensure_ascii=False, indent=2) + + os.rename(args.database + '.temp', args.database) diff --git a/.github/workflows/build-and-test-all.yml b/.github/workflows/build-and-test-all.yml index bd7d62b248..3b80c182b5 100644 --- a/.github/workflows/build-and-test-all.yml +++ b/.github/workflows/build-and-test-all.yml @@ -62,12 +62,19 @@ jobs: working-directory: . - run: inv ci-auth-configure - run: inv ci-auth-make-bear # This runs under pdns-$BUILDER_VERSION/pdns/ - - run: ln -s ../clang-tidy.full .clang-tidy + - name: Normalize paths in compilation DB + working-directory: . + run: python3 .github/scripts/normalize_paths_in_compilation_database.py --version $BUILDER_VERSION pdns-$BUILDER_VERSION/pdns/compile_commands.json + - name: Copy the compilation DB + working-directory: . + run: cp pdns-$BUILDER_VERSION/pdns/compile_commands.json . + - run: ln -s .clang-tidy.full .clang-tidy + working-directory: . - name: Run clang-tidy - working-directory: ./pdns-${{ env.BUILDER_VERSION }}/pdns - run: git diff -U0 HEAD^..HEAD | python3 ../../.github/scripts/git-filter.py | python3 /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p2 -export-fixes clang-tidy-auth.yml + working-directory: . + run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | python3 .github/scripts/clang-tidy-diff.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-auth.yml - name: Print clang-tidy fixes YAML - working-directory: ./pdns-${{ env.BUILDER_VERSION }}/pdns + working-directory: . shell: bash run: | if [ -f clang-tidy-auth.yml ]; then @@ -75,12 +82,12 @@ jobs: fi - name: Result annotations id: clang-tidy-annotations + working-directory: . shell: bash - working-directory: ./pdns-${{ env.BUILDER_VERSION }}/pdns run: | if [ -f clang-tidy-auth.yml ]; then set +e - python3 ../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-auth.yml + python3 .github/scripts/clang-tidy.py --fixes-file clang-tidy-auth.yml echo "failed=$?" >> $GITHUB_OUTPUT fi - run: inv ci-auth-install-remotebackend-test-deps @@ -143,10 +150,19 @@ jobs: working-directory: ./pdns/recursordist/ - run: inv ci-rec-configure - run: inv ci-rec-make-bear - - run: ln -s ../../../.clang-tidy.full .clang-tidy + - name: Normalize paths in compilation DB + working-directory: . + run: python3 .github/scripts/normalize_paths_in_compilation_database.py --version $BUILDER_VERSION ./pdns/recursordist/pdns-recursor-$BUILDER_VERSION/compile_commands.json + - name: Copy compilation DB + working-directory: . + run: cp ./pdns/recursordist/pdns-recursor-$BUILDER_VERSION/compile_commands.json . + - run: ln -s .clang-tidy.full .clang-tidy + working-directory: . - name: Run clang-tidy - run: git diff -U0 HEAD^..HEAD | python3 ../../../.github/scripts/git-filter.py | python3 /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p3 -export-fixes clang-tidy-rec.yml + working-directory: . + run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | python3 .github/scripts/clang-tidy-diff.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-rec.yml - name: Print clang-tidy fixes YAML + working-directory: . shell: bash run: | if [ -f clang-tidy-rec.yml ]; then @@ -154,11 +170,12 @@ jobs: fi - name: Result annotations id: clang-tidy-annotations + working-directory: . shell: bash run: | if [ -f clang-tidy-rec.yml ]; then set +e - python ../../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml + python .github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml echo "failed=$?" >> $GITHUB_OUTPUT fi - run: inv ci-rec-run-unit-tests @@ -223,10 +240,19 @@ jobs: working-directory: ./pdns/dnsdistdist/ - run: inv ci-dnsdist-configure ${{ matrix.features }} - run: inv ci-dnsdist-make-bear - - run: ln -s ../../../.clang-tidy.full .clang-tidy + - name: Normalize paths in compilation DB + working-directory: . + run: python3 .github/scripts/normalize_paths_in_compilation_database.py --version $BUILDER_VERSION ./pdns/dnsdistdist/dnsdist-$BUILDER_VERSION/compile_commands.json + - name: Copy compilation DB + run: cp ./pdns/dnsdistdist/dnsdist-$BUILDER_VERSION/compile_commands.json compile_commands.json + working-directory: . + - run: ln -s .clang-tidy.full .clang-tidy + working-directory: . - name: Run clang-tidy - run: git diff -U0 HEAD^..HEAD | python3 ../../../.github/scripts/git-filter.py | python3 /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p3 -export-fixes clang-tidy-dnsdist.yml + working-directory: . + run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | python3 .github/scripts/clang-tidy-diff.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-dnsdist.yml - name: Print clang-tidy fixes YAML + working-directory: . shell: bash run: | if [ -f clang-tidy-dnsdist.yml ]; then @@ -234,11 +260,12 @@ jobs: fi - name: Result annotations id: clang-tidy-annotations + working-directory: . shell: bash run: | if [ -f clang-tidy-dnsdist.yml ]; then set +e - python ../../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml + python .github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml echo "failed=$?" >> $GITHUB_OUTPUT fi - run: inv ci-dnsdist-run-unit-tests