]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix clang-tidy analysis
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 20 Oct 2023 15:32:10 +0000 (17:32 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 30 Oct 2023 08:14:59 +0000 (09:14 +0100)
.github/scripts/git-filter.py
.github/scripts/helpers.py
.github/scripts/normalize_paths_in_compilation_database.py [deleted file]
.github/workflows/codeql-analysis.yml
tasks.py

index aa05904f0a5e6de7638081f7c63d0df966feb9ac..d1206cd65a6a42664504170803729b2bacd908b1 100755 (executable)
@@ -7,35 +7,69 @@ the current directory.
 
 """
 
+import argparse
 import os
 import sys
+from pathlib import Path
 
 import helpers
 import unidiff
 
+def create_argument_parser():
+    """Create command-line argument parser."""
+    parser = argparse.ArgumentParser(
+        description="Filter git diff files that are not in the product"
+    )
+    parser.add_argument(
+        "--product",
+        type=str,
+        required=True,
+        help="Product (auth, dnsdist or rec)",
+    )
+    return parser.parse_args()
+
 
 def main():
     """Start the script."""
-    # It might be tempting to normalize the paths here instead of
-    # rewriting the compilation database, but then clang-tidy
-    # loses the depth of files in the repository, outputing for
-    # example "credentials.cc" instead of "pdns/credentials.cc"
+    args = create_argument_parser()
+    product = args.product
+
     compdb = helpers.load_compdb("compile_commands.json")
     compdb = helpers.index_compdb(compdb)
 
-    pdns_path = os.path.join("pdns", "")
-    cwd = os.getcwd()
-    root = helpers.get_repo_root()
+    cwd = Path(os.getcwd())
 
     diff = sys.stdin.read()
     patch_set = unidiff.PatchSet(diff)
     for patch in patch_set:
-        path = os.path.join(root, patch.path)
-        if path in compdb:
-            print(patch)
+        path = Path(patch.path)
+        if product == 'auth':
+            path = Path(cwd).joinpath(path)
         else:
-            msg = f"Skipping {path}: it is not in the compilation db"
-            print(msg, file=sys.stderr)
+            if str(path).startswith('modules'):
+                print(f'Skipping {path}: modules do not apply to {product}', file=sys.stderr)
+                continue
+
+            if str(path).startswith('ext'):
+                subpath = Path(cwd).joinpath(path)
+            else:
+                subpath = Path(cwd).joinpath(path.name)
+
+            if not subpath.exists():
+                print(f'Skipping {path}: does not exist for {product} ({subpath})', file=sys.stderr)
+                continue
+
+            path = subpath
+            if patch.source_file is not None:
+                patch.source_file = str(path)
+            patch.target_file = str(path)
+
+        if not str(path) in compdb:
+            print(f'Skipping {path}: it is not in the compilation db', file=sys.stderr)
+            continue
+
+        print(patch, file=sys.stderr)
+        print(patch)
 
     return 0
 
index 36969c8060f3cc1b217bab1c2b93339f8298a47c..cc170d1eed5ca2c027db400793ba277e29ada478 100644 (file)
@@ -1,9 +1,7 @@
 """Helpers for dealing with git, compilation databases, etc."""
 
-import pathlib
 import json
 import os
-import sys
 
 import git
 import yaml
@@ -48,28 +46,3 @@ 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
deleted file mode 100644 (file)
index f5645fb..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/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 104b12d47557cee79c1f3882f99bcd28a07a1b8c..adb93696189c930d4c70d763a07beb1fd77e106e 100644 (file)
@@ -110,13 +110,9 @@ jobs:
         inv ci-auth-make-bear
     - run: ln -s .clang-tidy.full .clang-tidy
       if: matrix.product == 'auth'
-    - run: cp ./pdns/compile_commands.json .
-      if: matrix.product == 'auth'
-    - run: cat compile_commands.json
-      if: matrix.product == 'auth'
     - name: Run clang-tidy for auth
       if: matrix.product == 'auth'
-      run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-auth.yml
+      run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py --product auth | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p0 -export-fixes clang-tidy-auth.yml
     - name: Print clang-tidy fixes YAML for auth
       if: matrix.product == 'auth'
       shell: bash
@@ -160,17 +156,16 @@ jobs:
       working-directory: ./pdns/dnsdistdist/
       run: |
         inv ci-dnsdist-make-bear
-    - run: ln -s .clang-tidy.full .clang-tidy
-      if: matrix.product == 'dnsdist'
-    - run: cp ./pdns/dnsdistdist/compile_commands.json .
-      if: matrix.product == 'dnsdist'
-    - run: cat compile_commands.json
+    - run: ln -s ../../.clang-tidy.full .clang-tidy
       if: matrix.product == 'dnsdist'
+      working-directory: ./pdns/dnsdistdist/
     - name: Run clang-tidy for dnsdist
       if: matrix.product == 'dnsdist'
-      run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-dnsdist.yml
+      working-directory: ./pdns/dnsdistdist/
+      run: git diff -U0 HEAD^..HEAD | python3 ../../.github/scripts/git-filter.py --product dnsdist | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p0 -export-fixes clang-tidy-dnsdist.yml
     - name: Print clang-tidy fixes YAML for dnsdist
       if: matrix.product == 'dnsdist'
+      working-directory: ./pdns/dnsdistdist/
       shell: bash
       run: |
         if [ -f clang-tidy-dnsdist.yml ]; then
@@ -179,11 +174,12 @@ jobs:
     - name: Result annotations for dnsdist
       if: matrix.product == 'dnsdist'
       id: clang-tidy-annotations-dnsdist
+      working-directory: ./pdns/dnsdistdist/
       shell: bash
       run: |
         if [ -f clang-tidy-dnsdist.yml ]; then
           set +e
-          python3 .github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml
+          python3 ../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-dnsdist.yml
           echo "failed=$?" >> $GITHUB_OUTPUT
         fi
 
@@ -209,17 +205,16 @@ jobs:
       working-directory: ./pdns/recursordist/
       run: |
         CONCURRENCY=4 inv ci-rec-make-bear
-    - run: ln -s .clang-tidy.full .clang-tidy
-      if: matrix.product == 'rec'
-    - run: cp ./pdns/recursordist/compile_commands.json .
-      if: matrix.product == 'rec'
-    - run: cat compile_commands.json
+    - run: ln -s ../../.clang-tidy.full .clang-tidy
       if: matrix.product == 'rec'
+      working-directory: ./pdns/recursordist/
     - name: Run clang-tidy for rec
       if: matrix.product == 'rec'
-      run: git diff -U0 HEAD^..HEAD | python3 .github/scripts/git-filter.py | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p1 -export-fixes clang-tidy-rec.yml
+      working-directory: ./pdns/recursordist/
+      run: git diff -U0 HEAD^..HEAD | python3 ../../.github/scripts/git-filter.py --product rec | /usr/bin/clang-tidy-diff-${CLANG_VERSION}.py -clang-tidy-binary /usr/bin/clang-tidy-${CLANG_VERSION} -extra-arg=-ferror-limit=0 -p0 -export-fixes clang-tidy-rec.yml
     - name: Print clang-tidy fixes YAML for rec
       if: matrix.product == 'rec'
+      working-directory: ./pdns/recursordist/
       shell: bash
       run: |
         if [ -f clang-tidy-rec.yml ]; then
@@ -228,11 +223,12 @@ jobs:
     - name: Result annotations for rec
       if: matrix.product == 'rec'
       id: clang-tidy-annotations-rec
+      working-directory: ./pdns/recursordist/
       shell: bash
       run: |
         if [ -f clang-tidy-rec.yml ]; then
           set +e
-          python3 .github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml
+          python3 ../../.github/scripts/clang-tidy.py --fixes-file clang-tidy-rec.yml
           echo "failed=$?" >> $GITHUB_OUTPUT
         fi
 
index 66cc25e929ef7b985c0a281d3ce58dc693ee1aba..00e7dd160a6cab5f7a50db88649656f8e30e0b3b 100644 (file)
--- a/tasks.py
+++ b/tasks.py
@@ -596,9 +596,7 @@ def ci_auth_make(c):
 @task
 def ci_auth_make_bear(c):
     concurrency = os.getenv('CONCURRENCY', 8)
-    # Needed for clang-tidy -line-filter vs project structure shenanigans
-    with c.cd('pdns'):
-        c.run(f'bear --append -- make -j{concurrency} -k V=1 -C ..')
+    c.run(f'bear --append -- make -j{concurrency} -k V=1')
 
 @task
 def ci_rec_make(c):