[clang] dcbb574 - [analyzer] Teach scan-build to filter reports by file.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 14 19:08:20 PST 2024
Author: Brianna Fan
Date: 2024-02-14T19:08:07-08:00
New Revision: dcbb574cfc3445251ff1c751f27b52ed6503bead
URL: https://github.com/llvm/llvm-project/commit/dcbb574cfc3445251ff1c751f27b52ed6503bead
DIFF: https://github.com/llvm/llvm-project/commit/dcbb574cfc3445251ff1c751f27b52ed6503bead.diff
LOG: [analyzer] Teach scan-build to filter reports by file.
That's a new GUI bell-and-whistle in the index.html page.
Added:
Modified:
clang/test/Analysis/scan-build/html_output.test
clang/tools/scan-build/bin/scan-build
clang/tools/scan-build/share/scan-build/sorttable.js
Removed:
################################################################################
diff --git a/clang/test/Analysis/scan-build/html_output.test b/clang/test/Analysis/scan-build/html_output.test
index eed2051d4df627..add35d83b95887 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 04734d9cfa9af6..37241c6d85c5b2 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"> ▾</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 32faa078d89934..e608daa9e39bc5 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)
+}
More information about the cfe-commits
mailing list