-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] Add test run of 'dump_ast_matchers.py' #165472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-clang Author: Baranov Victor (vbvictor) ChangesWIP Closes #165418. Full diff: https://github.com/llvm/llvm-project/pull/165472.diff 2 Files Affected:
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():
|
|
✅ With the latest revision this PR passed the AST matchers documentation. |
|
✅ With the latest revision this PR passed the Python code formatter. |
4b503d5 to
7669f00
Compare
|
Adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…workflow" This reverts commit 5340574.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title and description need to be updated. It would be good if the branch gets updated to kick off CI again too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Probably would be good to get approval from someone on the clang side as well.
|
Disabled test on Windows because of error which makes re-generated file different from expected: This should be either fixed by tinkering with certs in win-builder or by adjusting |
|
The test shouldn't be accessing anything over the internet. That should be fixed before landing. |
We use dump_ast_matchers.py script to update this auto-generated file in case someone make changes to ASTMatchers.
This PR ensures that
dump_ast_matchers.pywas run after change in ASTMatchers.Closes #165418.