steakhal created this revision. steakhal added reviewers: NoQ, martong, ASDenysPetrov. Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun. Herald added a project: All. steakhal requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This encapsulates 3 changes: - `DotDumpVisitor` now aggregates strings instead of *bytes* for both `python2` and `python3`. This difference caused crashes when it tried to write out the content as *strings*, similarly described at D71746 <https://reviews.llvm.org/D71746>. - `graphviz.pipe()` expects the input in *bytes* instead of unicode strings. And it results in *bytes*. Due to string concatenations and similar operations, I'm using unicode string as the default, and converting to *bytes* on demand. - `write_temp_file()` now appends the `egraph-` prefix and more importantly, it will create the temp file in the **current working directory** instead of in the *temp*. This change makes `Firefox` be able to open the file even if the `security.sandbox.content.level` is set to the (default) most restricting `4`. See https://support.mozilla.org/si/questions/1259285 An artifact of the bad byte handling was previously in the `HTML` produced by the script that it displayed the `b'` string at the top left corner. Now it won't anymore :) I've tested that the following command works on `Ubuntu 22.04`: exploded-graph-rewriter my-egraph.dot Both `python2` and `python3` works as expected. PS: I'm not adding tests, as the current test infra does not support testing HTML outputs for this script. Check the `clang/test/Analysis/exploded-graph-rewriter/lit.local.cfg`. We always pass the `--dump-dot-only` flag to the script. Along with that, the default invocation will not only create this HTML report but also try to open it. In addition to this, I'm not sure if the buildbots have `graphviz` installed and also if this package is installed on `pip`. Unless we change some of these, we cannot test this change. Given that D71746 <https://reviews.llvm.org/D71746> had no tests, I'm not too worried about this either. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D131553 Files: clang/utils/analyzer/exploded-graph-rewriter.py Index: clang/utils/analyzer/exploded-graph-rewriter.py =================================================================== --- clang/utils/analyzer/exploded-graph-rewriter.py +++ clang/utils/analyzer/exploded-graph-rewriter.py @@ -18,7 +18,6 @@ import logging import os import re -import sys #===-----------------------------------------------------------------------===# @@ -423,10 +422,7 @@ def output(self): assert not self._dump_dot_only - if sys.version_info[0] > 2 and sys.version_info[1] >= 5: - return ''.join(self._output).encode() - else: - return ''.join(self._output) + return ''.join(self._output) def _dump(self, s): s = s.replace('&', '&') \ @@ -854,12 +850,12 @@ import sys import tempfile - def write_temp_file(suffix, data): - fd, filename = tempfile.mkstemp(suffix=suffix) + def write_temp_file(suffix, prefix, data): + fd, filename = tempfile.mkstemp(suffix, prefix, '.', True) print('Writing "%s"...' % filename) with os.fdopen(fd, 'w') as fp: fp.write(data) - print('Done! Please remember to remove the file.') + print('Done!') return filename try: @@ -873,13 +869,13 @@ print('You may also convert DOT to SVG manually via') print(' $ dot -Tsvg input.dot -o output.svg') print() - write_temp_file('.dot', self.output()) + write_temp_file('.dot', 'egraph-', self.output()) return - svg = graphviz.pipe('dot', 'svg', self.output()) + svg = graphviz.pipe('dot', 'svg', self.output().encode()).decode() filename = write_temp_file( - '.html', '<html><body bgcolor="%s">%s</body></html>' % ( + '.html', 'egraph-', '<html><body bgcolor="%s">%s</body></html>' % ( '#1a1a1a' if self._dark_mode else 'white', svg)) if sys.platform == 'win32': os.startfile(filename)
Index: clang/utils/analyzer/exploded-graph-rewriter.py =================================================================== --- clang/utils/analyzer/exploded-graph-rewriter.py +++ clang/utils/analyzer/exploded-graph-rewriter.py @@ -18,7 +18,6 @@ import logging import os import re -import sys #===-----------------------------------------------------------------------===# @@ -423,10 +422,7 @@ def output(self): assert not self._dump_dot_only - if sys.version_info[0] > 2 and sys.version_info[1] >= 5: - return ''.join(self._output).encode() - else: - return ''.join(self._output) + return ''.join(self._output) def _dump(self, s): s = s.replace('&', '&') \ @@ -854,12 +850,12 @@ import sys import tempfile - def write_temp_file(suffix, data): - fd, filename = tempfile.mkstemp(suffix=suffix) + def write_temp_file(suffix, prefix, data): + fd, filename = tempfile.mkstemp(suffix, prefix, '.', True) print('Writing "%s"...' % filename) with os.fdopen(fd, 'w') as fp: fp.write(data) - print('Done! Please remember to remove the file.') + print('Done!') return filename try: @@ -873,13 +869,13 @@ print('You may also convert DOT to SVG manually via') print(' $ dot -Tsvg input.dot -o output.svg') print() - write_temp_file('.dot', self.output()) + write_temp_file('.dot', 'egraph-', self.output()) return - svg = graphviz.pipe('dot', 'svg', self.output()) + svg = graphviz.pipe('dot', 'svg', self.output().encode()).decode() filename = write_temp_file( - '.html', '<html><body bgcolor="%s">%s</body></html>' % ( + '.html', 'egraph-', '<html><body bgcolor="%s">%s</body></html>' % ( '#1a1a1a' if self._dark_mode else 'white', svg)) if sys.platform == 'win32': os.startfile(filename)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits