]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
build-and-test-all: Fix clang-tidy now that we build in dist dirs
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 2 Oct 2023 08:48:18 +0000 (10:48 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 5 Oct 2023 08:31:40 +0000 (10:31 +0200)
.github/scripts/helpers.py
.github/scripts/normalize_paths_in_compilation_database.py [new file with mode: 0644]
.github/workflows/build-and-test-all.yml

index cc170d1eed5ca2c027db400793ba277e29ada478..36969c8060f3cc1b217bab1c2b93339f8298a47c 100644 (file)
@@ -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 (file)
index 0000000..f5645fb
--- /dev/null
@@ -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)
index bd7d62b248ec4c476a8de5dd8e4c0c6247b1b30e..3b80c182b57372e6c54ac7cba092e8235a574d29 100644 (file)
@@ -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