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

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 28 13:26:29 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Baranov Victor (vbvictor)

<details>
<summary>Changes</summary>

WIP

Closes https://github.com/llvm/llvm-project/issues/165418.

---
Full diff: https://github.com/llvm/llvm-project/pull/165472.diff


2 Files Affected:

- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+1-1) 
- (modified) llvm/utils/git/code-format-helper.py (+64-1) 


``````````diff
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; }
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():

``````````

</details>


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


More information about the cfe-commits mailing list