[clang] [analyzer] Allow egraph rewriter not to open the generated HTML directly (PR #85515)

via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 16 04:09:08 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Ella Ma (Snape3058)

<details>
<summary>Changes</summary>

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
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:

``````````

</details>


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


More information about the cfe-commits mailing list