]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix clang-tidy-diff not finding module and ext files 12945/head
authorFred Morcos <fred.morcos@open-xchange.com>
Thu, 22 Jun 2023 12:39:06 +0000 (14:39 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Fri, 23 Jun 2023 08:27:47 +0000 (10:27 +0200)
.github/scripts/git-filter.py

index 533111606d046fb9d9dd53dca9047e44c962c91d..14033eb38edaaec0e940131e32f4c5c76819235e 100755 (executable)
@@ -19,6 +19,8 @@ def main():
     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()
 
     diff = sys.stdin.read()
@@ -26,7 +28,29 @@ def main():
     for patch in patch_set:
         path = os.path.join(root, patch.path)
         if path in compdb:
+            if not patch.path.startswith(pdns_path):
+                # If the file being diffed is not under the pdns/ directory, we
+                # need to reconstruct its filename in the patch adding extra
+                # paths that clang-tidy-diff will get rid of: this way
+                # clang-tidy can work with the correct file path.
+                #
+                # Example with a source file under modules/:
+                #   patch.path = modules/foo/foo.cc
+                #   path       = /home/user/workspace/pdns/modules/foo/foo.cc
+                #   cwd        = /home/user/workspace/pdns/pdns/
+                #   relpath    = ../modules/foo/foo.cc
+                #
+                # Then the patch filenames would be:
+                #   patch.source_file = a/pdns/../modules/foo/foo.cc
+                #   patch.target_file = b/pdns/../modules/foo/foo.cc
+                relpath = os.path.relpath(path, cwd)
+                if patch.source_file is not None:
+                    patch.source_file = os.path.join("a", "pdns", relpath)
+                patch.target_file = os.path.join("b", "pdns", relpath)
             print(patch)
+        else:
+            msg = f"Skipping {path}: it is not in the compilation db"
+            print(msg, file=sys.stderr)
 
     return 0