[clang] [llvm] [WIP][GitHub][CI] Add running of dump_ast_matchers.py to premerge workflow (PR #165472)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 28 13:54:36 PDT 2025


https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/165472

>From 5340574a9ac6335e2effc15e73f122018ffc58a2 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Tue, 28 Oct 2025 22:33:53 +0300
Subject: [PATCH 1/3] [GitHub][CI] Add running of dump_ast_matchers.py to
 premerge workflow

---
 llvm/utils/git/code-format-helper.py | 65 +++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 1 deletion(-)

diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py
index 406a72817acb8..6de7d21ab68a6 100755
--- a/llvm/utils/git/code-format-helper.py
+++ b/llvm/utils/git/code-format-helper.py
@@ -466,7 +466,70 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
         return report
 
 
-ALL_FORMATTERS = (DarkerFormatHelper(), ClangFormatHelper(), UndefGetFormatHelper())
+class DumpASTMatchersHelper(FormatHelper):
+    name = "dump_ast_matchers"
+    friendly_name = "AST matchers documentation"
+
+    output_html = "clang/docs/LibASTMatchersReference.html"
+    script_dir = "clang/docs/tools"
+    script_name = "dump_ast_matchers.py"
+
+    @property
+    def instructions(self) -> str:
+        return f"cd {self.script_dir} && python {self.script_name}"
+
+    def should_run(self, changed_files: List[str]) -> List[str]:
+        for file in changed_files:
+            if file == "clang/include/clang/ASTMatchers/ASTMatchers.h":
+                return True
+        return False
+
+    def has_tool(self) -> bool:
+        if not os.path.exists(os.path.join(self.script_dir, self.script_name)):
+            return False
+        return True
+
+    def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str]:
+        if not self.should_run(changed_files):
+            return None
+
+        if args.verbose:
+            print(f"Running: {self.instructions}")
+
+        # Run the 'dump_ast_matchers.py' from its directory as specified in the script doc
+        proc = subprocess.run(
+            ["python", self.script_name],
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            encoding="utf-8",
+            cwd=self.script_dir,
+        )
+
+        if proc.returncode != 0:
+            return f"Execution of 'dump_ast_matchers.py' failed:\n{proc.stderr}\n{proc.stdout}"
+
+        # Check if 'LibASTMatchersReference.html' file was modified
+        cmd = ["git", "diff", "--exit-code", self.output_html]
+        proc = subprocess.run(
+            cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8"
+        )
+
+        # 'LibASTMatchersReference.html' was modified - count as failure
+        if proc.returncode != 0:
+            if args.verbose:
+                print(f"error: {self.name} exited with code {proc.returncode}")
+                print(proc.stdout.decode("utf-8"))
+            return proc.stdout.decode("utf-8")
+        else:
+            return None
+
+
+ALL_FORMATTERS = (
+    DarkerFormatHelper(),
+    ClangFormatHelper(),
+    UndefGetFormatHelper(),
+    DumpASTMatchersHelper(),
+)
 
 
 def hook_main():

>From 1e19a19d600a6238e53b19a5cc75c81e7232b93e Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Tue, 28 Oct 2025 23:25:38 +0300
Subject: [PATCH 2/3] add change to matchers

---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 98e62de2a9bfb..cc72613db4d15 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1390,7 +1390,7 @@ extern const internal::VariadicDynCastAllOfMatcher<Expr, RequiresExpr>
 
 /// Matches concept requirement body declaration.
 ///
-/// Example matches '{ *p; }'
+/// Example matches '{ * p; }'
 /// \code
 ///   template<typename T>
 ///   concept dereferencable = requires(T p) { *p; }

>From 7669f00a30207bda4bca1d78c05712375889d597 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Tue, 28 Oct 2025 23:54:20 +0300
Subject: [PATCH 3/3] use python3

---
 llvm/utils/git/code-format-helper.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py
index 6de7d21ab68a6..0ae800d4000c9 100755
--- a/llvm/utils/git/code-format-helper.py
+++ b/llvm/utils/git/code-format-helper.py
@@ -476,7 +476,7 @@ class DumpASTMatchersHelper(FormatHelper):
 
     @property
     def instructions(self) -> str:
-        return f"cd {self.script_dir} && python {self.script_name}"
+        return f"cd {self.script_dir} && python3 {self.script_name}"
 
     def should_run(self, changed_files: List[str]) -> List[str]:
         for file in changed_files:
@@ -498,7 +498,7 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
 
         # Run the 'dump_ast_matchers.py' from its directory as specified in the script doc
         proc = subprocess.run(
-            ["python", self.script_name],
+            ["python3", self.script_name],
             stdout=subprocess.PIPE,
             stderr=subprocess.PIPE,
             encoding="utf-8",
@@ -506,7 +506,7 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
         )
 
         if proc.returncode != 0:
-            return f"Execution of 'dump_ast_matchers.py' failed:\n{proc.stderr}\n{proc.stdout}"
+            return f"dump_ast_matchers.py failed with code {proc.returncode}:\n{proc.stderr}\n{proc.stdout}"
 
         # Check if 'LibASTMatchersReference.html' file was modified
         cmd = ["git", "diff", "--exit-code", self.output_html]
@@ -518,8 +518,8 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
         if proc.returncode != 0:
             if args.verbose:
                 print(f"error: {self.name} exited with code {proc.returncode}")
-                print(proc.stdout.decode("utf-8"))
-            return proc.stdout.decode("utf-8")
+                print(proc.stdout)
+            return proc.stdout
         else:
             return None
 



More information about the cfe-commits mailing list