Skip to content

[analyzer] Allow egraph rewriter not to open the generated HTML directly #85515

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

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

Snape3058
Copy link
Member

@Snape3058 Snape3058 commented Mar 16, 2024

When developing on a headless device through SSH, we do not have a browser or even an X environment. Hence, it would be more convenient if the rewriter could stop before attempting to open the generated HTML file. Then, it can be opened remotely through an HTML server.

This patch adds a new option --dump-html-only to make the rewriter stop before opening the generated HTML in a browser. The new option is marked in conflict with the existing --dump-dot-only option to prevent unexpected behaviors.

@Snape3058 Snape3058 requested a review from haoNoQ March 16, 2024 11:08
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Mar 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 16, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ella Ma (Snape3058)

Changes

When developing on a headless device through SSH, we do not have a browser or even an X environment. Hence, it would be more convenient if the rewriter could stop before attempting to open the generated HTML file. Then, it can be opened remotely through an HTML server.

This patch adds a new option --dump-html-only with a shortcut -x to make the rewriter stop before opening the generated HTML in a browser. The new option is marked in conflict with the existing --dump-dot-only option to prevent unexpected behaviors.


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

1 Files Affected:

  • (modified) clang/utils/analyzer/exploded-graph-rewriter.py (+17-3)
diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py
index c7c6315a0a27d1..ffec964d8ef09a 100755
--- a/clang/utils/analyzer/exploded-graph-rewriter.py
+++ b/clang/utils/analyzer/exploded-graph-rewriter.py
@@ -479,12 +479,14 @@ def add_raw_line(self, raw_line):
 # A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
 # syntax highlighing.
 class DotDumpVisitor:
-    def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only):
+    def __init__(self, do_diffs, dark_mode, gray_mode, topo_mode, dump_dot_only,
+            dump_html_only):
         self._do_diffs = do_diffs
         self._dark_mode = dark_mode
         self._gray_mode = gray_mode
         self._topo_mode = topo_mode
         self._dump_dot_only = dump_dot_only
+        self._dump_html_only = dump_html_only
         self._output = []
 
     def _dump_raw(self, s):
@@ -998,6 +1000,8 @@ def write_temp_file(suffix, prefix, data):
                 '<html><body bgcolor="%s">%s</body></html>'
                 % ("#1a1a1a" if self._dark_mode else "white", svg),
             )
+            if self._dump_html_only:
+                return
             if sys.platform == "win32":
                 os.startfile(filename)
             elif sys.platform == "darwin":
@@ -1176,7 +1180,8 @@ def main():
         default=False,
         help="black-and-white mode",
     )
-    parser.add_argument(
+    dump_conflict = parser.add_mutually_exclusive_group()
+    dump_conflict.add_argument(
         "--dump-dot-only",
         action="store_const",
         dest="dump_dot_only",
@@ -1186,6 +1191,14 @@ def main():
         "displaying it, dump the rewritten dot file "
         "to stdout",
     )
+    dump_conflict.add_argument(
+        "--dump-html-only",
+        action="store_const",
+        dest="dump_html_only",
+        const=True,
+        default=False,
+        help="do not open the generated HTML immediately",
+    )
     args = parser.parse_args()
     logging.basicConfig(level=args.loglevel)
 
@@ -1206,7 +1219,8 @@ def main():
     explorer = BasicExplorer()
 
     visitor = DotDumpVisitor(
-        args.diff, args.dark, args.gray, args.topology, args.dump_dot_only
+        args.diff, args.dark, args.gray, args.topology, args.dump_dot_only,
+        args.dump_html_only
     )
 
     for trimmer in trimmers:

Copy link

github-actions bot commented Mar 16, 2024

✅ With the latest revision this PR passed the Python code formatter.

@Snape3058
Copy link
Member Author

Updated as suggested.

Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Snape3058 Snape3058 merged commit 0c3e24f into llvm:main Mar 26, 2024
@Snape3058 Snape3058 deleted the html-only branch March 26, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants