summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrianna Fan <bfan2@apple.com>2024-02-14 18:53:07 -0800
committerArtem Dergachev <adergachev@apple.com>2024-02-14 19:08:07 -0800
commitdcbb574cfc3445251ff1c751f27b52ed6503bead (patch)
tree30b33ed6674d89a936632b7c49d884651c9f772e
parent6fce42f89a2c3f12b019bd3d7fef3e8db2d4671f (diff)
[analyzer] Teach scan-build to filter reports by file.
That's a new GUI bell-and-whistle in the index.html page.
-rw-r--r--clang/test/Analysis/scan-build/html_output.test8
-rwxr-xr-xclang/tools/scan-build/bin/scan-build11
-rw-r--r--clang/tools/scan-build/share/scan-build/sorttable.js20
3 files changed, 36 insertions, 3 deletions
diff --git a/clang/test/Analysis/scan-build/html_output.test b/clang/test/Analysis/scan-build/html_output.test
index eed2051d4df6..add35d83b958 100644
--- a/clang/test/Analysis/scan-build/html_output.test
+++ b/clang/test/Analysis/scan-build/html_output.test
@@ -19,13 +19,17 @@ CHECK-FILENAMES: report-{{.*}}.html
CHECK-FILENAMES: scanview.css
CHECK-FILENAMES: sorttable.js
-
-// The index should have a link to the report for the single issue.
+// Tests for the front page.
RUN: cat %t.output_dir/*/index.html \
RUN: | FileCheck %s -check-prefix CHECK-INDEX-HTML
+// Let's confirm that the new filtering facility is present.
+CHECK-INDEX-HTML: Filter Results by File
+
+// The index should have a link to the report for the single issue.
CHECK-INDEX-HTML: <!-- REPORTBUG id="report-{{.*}}.html" -->
+
// The report should describe the issue.
RUN: cat %t.output_dir/*/report-*.html \
RUN: | FileCheck %s -check-prefix CHECK-REPORT-HTML
diff --git a/clang/tools/scan-build/bin/scan-build b/clang/tools/scan-build/bin/scan-build
index 04734d9cfa9a..37241c6d85c5 100755
--- a/clang/tools/scan-build/bin/scan-build
+++ b/clang/tools/scan-build/bin/scan-build
@@ -722,9 +722,18 @@ ENDTEXT
print OUT <<ENDTEXT;
</table>
+
+<h2>Filter Results by File</h2>
+<input
+ type="text"
+ id="file_input"
+ onkeyup="searchFiles()"
+ placeholder="Enter a path or filename"
+ title="Enter a path or filename">
+
<h2>Reports</h2>
-<table class="sortable" style="table-layout:automatic">
+<table id="reports_table" class="sortable" style="table-layout:automatic">
<thead><tr>
<td>Bug Group</td>
<td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span></td>
diff --git a/clang/tools/scan-build/share/scan-build/sorttable.js b/clang/tools/scan-build/share/scan-build/sorttable.js
index 32faa078d899..e608daa9e39b 100644
--- a/clang/tools/scan-build/share/scan-build/sorttable.js
+++ b/clang/tools/scan-build/share/scan-build/sorttable.js
@@ -490,3 +490,23 @@ var forEach = function(object, block, context) {
resolve.forEach(object, block, context);
}
};
+
+// filter results by filename
+const searchFiles = () => {
+ const columns = [
+ { name: 'Filename', index: 2, isFilter: true },
+ ]
+ const filterColumns = columns.filter(c => c.isFilter).map(c => c.index)
+ const trs = document.querySelectorAll(`#reports_table tr:not(.header)`)
+ const filter = document.querySelector('#file_input').value
+ const regex = new RegExp(escape(filter), 'i')
+ const isFoundInTds = td => regex.test(td.innerHTML)
+ const isFound = childrenArr => childrenArr.some(isFoundInTds)
+ const setTrStyleDisplay = ({ style, children }) => {
+ style.display = isFound([
+ ...filterColumns.map(c => children[c])
+ ]) ? '' : 'none'
+ }
+
+ trs.forEach(setTrStyleDisplay)
+}