Skip to content

Commit a601c8d

Browse files
authored
Fix #15295 (report : new html-report with dashboard) (#9100)
1 parent 6a4fedd commit a601c8d

21 files changed

Lines changed: 3613 additions & 30 deletions

File tree

‎.codacy.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude_paths:
22
- addons/test/**
33
- addons/y2038/test/*.c
4-
- htmlreport/example.cc
4+
- reports/htmlreport/example.cc
55
- samples/**/bad.c
66
- samples/**/bad.cpp
77
- test/cfg/*.c

‎.github/workflows/release-windows.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
# TODO: include in installer?
128128
- name: Compile cppcheck-htmlreport executable
129129
run: |
130-
cd htmlreport || exit /b !errorlevel!
130+
cd reports\htmlreport || exit /b !errorlevel!
131131
pyinstaller cppcheck-htmlreport || exit /b !errorlevel!
132132
del *.spec || exit /b !errorlevel!
133133
@@ -153,7 +153,7 @@ jobs:
153153
del win_installer\files\platforms\*.rng || exit /b !errorlevel!
154154
del win_installer\files\translations\*.qm || exit /b !errorlevel!
155155
move build\gui\*.qm win_installer\files\translations || exit /b !errorlevel!
156-
copy htmlreport\dist\cppcheck-htmlreport\*.* win_installer\files || exit /b !errorlevel!
156+
copy reports\htmlreport\dist\cppcheck-htmlreport\*.* win_installer\files || exit /b !errorlevel!
157157
:: copy libcrypto-3-x64.dll and libssl-3-x64.dll
158158
copy %RUNNER_WORKSPACE%\Qt\Tools\OpenSSLv3\Win_x64\bin\lib*.dll win_installer\files || exit /b !errorlevel!
159159

‎.github/workflows/scriptcheck.yml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
if: matrix.python-latest
110110
run: |
111111
shopt -s globstar
112-
pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py htmlreport/cppcheck-htmlreport htmlreport/**/*.py test/**/*.py tools/**/*.py
112+
pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py reports/htmlreport/cppcheck-htmlreport reports/**/*.py test/**/*.py tools/**/*.py
113113
114114
- name: check .json files
115115
if: matrix.python-latest
@@ -125,8 +125,8 @@ jobs:
125125
run: |
126126
shopt -s globstar
127127
python -m py_compile addons/**/*.py
128-
python -m py_compile htmlreport/cppcheck-htmlreport
129-
python -m py_compile htmlreport/**/*.py
128+
python -m py_compile reports/htmlreport/cppcheck-htmlreport
129+
python -m py_compile reports/**/*.py
130130
python -m py_compile test/**/*.py
131131
python -m py_compile tools/**/*.py
132132
@@ -167,7 +167,7 @@ jobs:
167167
python -m venv venv
168168
source venv/bin/activate
169169
python -m pip install -U pip
170-
pip install ./htmlreport/
170+
pip install ./reports/htmlreport/
171171
which cppcheck-htmlreport
172172
PIP_PACKAGE_TEST=1 test/tools/htmlreport/test_htmlreport.py
173173
# TODO: does not test the pip binary
@@ -199,6 +199,12 @@ jobs:
199199
env:
200200
PYTHONPATH: ./tools
201201

202+
# the javascript tests use the node that is installed on the runner
203+
- name: test explorer report
204+
run: |
205+
node --version
206+
python -m pytest -Werror --strict-markers -vv test/tools/explorer/
207+
202208
- name: Show all ignored files
203209
if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched
204210
run: |

‎.gitignore‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ stage
113113
**/*.egg-info/
114114

115115
# cppcheck-htmlreport auto files
116-
/htmlreport/cppcheck_htmlreport/run.py
116+
/reports/htmlreport/cppcheck_htmlreport/run.py
117117

118118
# GDB configuration
119119
.gdbinit
120120

121121
# pyinstaller output
122122
/addons/dist
123123
/addons/misra.spec
124-
/htmlreport/cppcheck-htmlreport.spec
125-
/htmlreport/dist
124+
/reports/htmlreport/cppcheck-htmlreport.spec
125+
/reports/htmlreport/dist
126126

127127
# ccache folder in CI
128128
/.ccache

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ tags:
414414
install: cppcheck
415415
install -d ${BIN}
416416
install cppcheck ${BIN}
417-
install htmlreport/cppcheck-htmlreport ${BIN}
417+
install reports/htmlreport/cppcheck-htmlreport ${BIN}
418418
ifdef FILESDIR
419419
install -d ${DESTDIR}${FILESDIR}
420420
install -d ${DESTDIR}${FILESDIR}/addons

‎cli/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if (BUILD_CLI)
4343
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
4444
COMPONENT applications)
4545

46-
install(PROGRAMS ${CMAKE_SOURCE_DIR}/htmlreport/cppcheck-htmlreport
46+
install(PROGRAMS ${CMAKE_SOURCE_DIR}/reports/htmlreport/cppcheck-htmlreport
4747
DESTINATION ${CMAKE_INSTALL_BINDIR}
4848
COMPONENT applications)
4949

‎man/manual-ja.docbook‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,11 +1814,11 @@ for arg in sys.argv[1:]:
18141814
<chapter>
18151815
<title>HTML 形式での報告</title>
18161816

1817-
<para>cppcheckのXML出力をHTML形式に変更できます。これを利用するには、Python と pygments module (<ulink url="http://pygments.org/">http://pygments.org/</ulink>) が必要です。Cppcheckのソースツリーに<filename class="directory">htmlreport</filename>というフォルダがあります。このフォルダには、CppcheckのXMLファイルをHTML出力に変換するスクリプトがあります。</para>
1817+
<para>cppcheckのXML出力をHTML形式に変更できます。これを利用するには、Python と pygments module (<ulink url="http://pygments.org/">http://pygments.org/</ulink>) が必要です。Cppcheckのソースツリーに<filename class="directory">reports/htmlreport</filename>というフォルダがあります。このフォルダには、CppcheckのXMLファイルをHTML出力に変換するスクリプトがあります。</para>
18181818

18191819
<para>このコマンドでヘルプ画面を生成するには次のように実行します。</para>
18201820

1821-
<programlisting>htmlreport/cppcheck-htmlreport -h</programlisting>
1821+
<programlisting>reports/htmlreport/cppcheck-htmlreport -h</programlisting>
18221822

18231823
<para>出力画面には次の内容が表示されます。:</para>
18241824

@@ -1836,7 +1836,7 @@ Options:
18361836
<para>使用例:</para>
18371837

18381838
<programlisting>./cppcheck gui/test.cpp --xml 2&gt; err.xml
1839-
htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.</programlisting>
1839+
reports/htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.</programlisting>
18401840
</chapter>
18411841

18421842
<chapter>

‎man/manual.md‎

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,11 +1341,22 @@ The `.cfg` file format is documented in the `Reference: Cppcheck .cfg format` (<
13411341

13421342
# HTML report
13431343

1344-
You can convert the XML output from Cppcheck into a HTML report. You'll need Python and the pygments module (<http://pygments.org/>) for this to work. In the Cppcheck source tree there is a folder htmlreport that contains a script that transforms a Cppcheck XML file into HTML output.
1344+
## Overview
1345+
1346+
Using AI, you can easily and quickly create a script that converts the Cppcheck XML output into a nice-looking HTML report with any features you want.
1347+
1348+
We provide 2 ready made scripts:
1349+
1350+
* htmlreport: results view
1351+
* explorer: dashboard, results view, metrics (if available)
1352+
1353+
## htmlreport
1354+
1355+
The script `cppcheck-htmlreport` converts a Cppcheck XML file into a HTML output. You'll need Python and the pygments module (<http://pygments.org/>) for this to work.
13451356

13461357
This command generates the help screen:
13471358

1348-
htmlreport/cppcheck-htmlreport -h
1359+
reports/htmlreport/cppcheck-htmlreport -h
13491360

13501361
The output screen says:
13511362

@@ -1374,7 +1385,7 @@ or
13741385
cppcheck-htmlreport --file=err.xml --report-dir=test1 \
13751386
--source-dir=https://github.com/<username>/<repo>/blob/<branch>/
13761387

1377-
## Choosing between local annotated HTML and remote repository links
1388+
### Choosing between local annotated HTML and remote repository links
13781389

13791390
`cppcheck-htmlreport` supports two modes for linking to source files:
13801391

@@ -1394,6 +1405,81 @@ handled by the hosting service.
13941405
In general, local mode fits air-gapped environments, while remote mode works
13951406
best for CI workflows and large or private repositories.
13961407

1408+
## Explorer report
1409+
1410+
The script `reports/explorer/report.py` creates a Cppcheck Explorer report. The report has a dashboard with graphs, and a results view where you can filter the warnings and see the related source code. If the XML file contains metrics, these are shown as well. The report is designed to be responsive also when there are thousands of warnings.
1411+
1412+
You only need Python to run the script, no extra modules are required.
1413+
1414+
### Generating a report
1415+
1416+
First analyze the code and save the results in an XML file, then generate the report:
1417+
1418+
cppcheck --enable=style --xml src 2> results.xml
1419+
python3 reports/explorer/report.py results.xml -o cppcheck-report
1420+
1421+
Open `cppcheck-report/index.html` in a browser. To share the report, copy the whole `cppcheck-report` folder. Note that the report contains the source code.
1422+
1423+
The source files are searched for in the current folder and in the folder of the XML file. Use `--source-dir` if they are located somewhere else:
1424+
1425+
python3 reports/explorer/report.py results.xml --source-dir=path/to/project -o cppcheck-report
1426+
1427+
### New and old warnings
1428+
1429+
If you provide the XML results from an earlier analysis as a baseline, then the report shows which warnings are new:
1430+
1431+
# Analyze the code and save the results as a baseline
1432+
cppcheck --enable=style --xml src 2> baseline.xml
1433+
1434+
# Later: analyze the code again and compare with the baseline
1435+
cppcheck --enable=style --xml src 2> results.xml
1436+
python3 reports/explorer/report.py results.xml --baseline=baseline.xml -o cppcheck-report
1437+
1438+
### Trend graphs
1439+
1440+
Save the XML results from each analysis in a folder and use `--history` to get trend graphs. The results are ordered by the date in the filename:
1441+
1442+
mkdir -p history
1443+
cppcheck --enable=style --xml src 2> history/results-2026-05-01.xml
1444+
1445+
# Later: analyze the code again and show the trend
1446+
cppcheck --enable=style --xml src 2> results.xml
1447+
python3 reports/explorer/report.py results.xml --history=history -o cppcheck-report
1448+
1449+
If no `--baseline` is given, then the newest report in the history is used as baseline.
1450+
1451+
::: {.content-visible when-profile="premium"}
1452+
1453+
### Metrics
1454+
1455+
To generate metrics, add option `--premium=metrics`. The metrics are saved in the XML v3 report.
1456+
Example:
1457+
1458+
cppcheck --premium=metrics test.c --xml-version=3 2> res.xml
1459+
python3 reports/explorer/report.py res.xml -o cppcheck-report
1460+
1461+
The dashboard shows a summary of the metrics and the metrics view shows the values for each
1462+
function and file. Values that exceed the thresholds are highlighted.
1463+
1464+
The default thresholds are the HIS limits. You can change them by providing a JSON file. Example `thresholds.json`:
1465+
1466+
{
1467+
"cyclomaticComplexity": {"max": 15},
1468+
"HISCOMF": {"min": 10}
1469+
}
1470+
1471+
Use the option `--metrics-thresholds` to load the file:
1472+
1473+
python3 reports/explorer/report.py res.xml --metrics-thresholds=thresholds.json -o cppcheck-report
1474+
1475+
:::
1476+
1477+
### All options
1478+
1479+
To see all options, run:
1480+
1481+
python3 reports/explorer/report.py -h
1482+
13971483
# Check level
13981484

13991485
## Reduced
@@ -1550,16 +1636,15 @@ Example:
15501636

15511637
cppcheck --premium=metrics test.c --xml-version=3 2> res.xml
15521638

1553-
We provide a small simple python script that creates a metrics report in CSV format:
1639+
A report that shows the metrics can be created, for example see the chapter [Explorer report](#explorer-report).
1640+
1641+
If you want the metrics in CSV format, we provide a small simple python script for that:
15541642

15551643
python3 HISReport.py -f res.xml -j path/to/cppcheck-id-mapping.json -o test.csv
15561644

15571645
The `cppcheck-id-mapping.json` is provided in the Cppcheck premium installation folder, i.e.
15581646
`/opt/cppcheckpremium` or `C:\Program Files\Cppcheck Premium`.
15591647

1560-
We do not have a ready-made solution to generate a HTML/pdf report. You can easily tweak our
1561-
`HISReport.py` script so that it generates HTML and get the report exactly as you want.
1562-
15631648
## Licenses
15641649

15651650
### Commercial terms

‎reports/explorer/README.md‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
2+
# Report
3+
4+
## Overview
5+
6+
This folder contains a script report.py that converts a cppcheck xml report into a html report.
7+
8+
Only the python standard libraries are used. No extra dependencies shall be needed.
9+
10+
The html report is interactive, there are toggle buttons and stuff.
11+
12+
## Performance
13+
14+
Very important. The report needs to be responsive for large projects with thousands of warnings. It's preferable that multiple files are created instead of a single HTML that contains everything.
15+
16+
## Themes
17+
18+
There will be different themes. light/dark/etc
19+
20+
## Dashboard
21+
22+
A dashboard shows an overview of warnings. The dashboard is designed for a team-leader that wants to see status. The dashboard should primarily present information in graphs.
23+
24+
### Sections
25+
26+
- Executive summary: A text summary. Green/Red Badge if there are undefined behavior. A Green/red badge if there are security/safety issues (misra/cert). The badge is gray if misra/cert was not checked.
27+
- Product filter strip: Buttons per "product". Products are guessed from the directory (src/core/ becomes "Core"), or set with --product-map. Clicking one filters the whole dashboard. Hide this if all source files are in the same folder.
28+
- If several reports are provided we can show trend graphs.
29+
- Show graphs both for "new" warnings and "all" warnings.
30+
- 5 KPI tiles: Errors, warnings, style+perf+portability, total and affected files, with "+N vs previous".
31+
- Quality trend over time: Line chart of total/errors/warnings across snapshots (--history DIR or --snapshot). With "new" warnings selected it shows the new warnings in each report, compared with the report before. Hide this if there is only 1 result file.
32+
- Warnings by product: Bar chart. Hide this if there is only one product, or if a product is selected.
33+
- Risk domain breakdown: Bar chart of IDs grouped into made-up groups ("Memory & Crash Safety", "Security", "Maintainability"…) by keyword matching or by CWE.
34+
- If there are metrics then show some summary about that.
35+
36+
## Result details
37+
38+
There is a result details view. All results are shown here. It's possible to toggle different warnings severities. It's possible to toggle IDs.
39+
40+
All warnings are shown in a list and if a warning is clicked the related code is shown in a tab.
41+
42+
## Metrics
43+
44+
If there are metrics, a metrics report.
45+
46+
# Baseline : New and old warnings
47+
48+
Each warning has a hash in the xml report, if old baseline report(s) are provided then those warnings are "old". A warning in a new report is "new" if its hash does not match any baseline warning.
49+
50+
It should be indicated in the dashboard how many new/old warnings there are. It should be possible to see if warnings are new in the results view and it should be possible to hide old warnings.
51+
52+
## Classification/guideline mode (MISRA, CERT, Cppcheck Premium)
53+
54+
When the XML has classification attributes, the report switches to a different mode:
55+
56+
- In the results list the severity is replaced by Classification and Guideline columns. Click on a column header to sort.
57+
- A filter bar for Mandatory, Required, Advisory, Document, Disapplied and L1/L2/L3 replaces the severity filter. Classifications that are not used in the report are disabled.
58+
- The dashboard graphs and KPI tiles use the classification instead of the severity, and there is a graph of the most violated guidelines.
59+
- The severity is still shown in the warning details.
60+
61+
62+
# Usage
63+
64+
cppcheck --xml ... 2> results.xml
65+
python3 report.py results.xml -o cppcheck-report
66+
67+
# mark new/old warnings by comparing with a previous report
68+
python3 report.py results.xml --baseline old-results.xml -o cppcheck-report
69+
70+
# trend graphs: older reports in a directory (results-2026-05-01.xml, ...)
71+
python3 report.py results.xml --history history -o cppcheck-report
72+
73+
# metrics (Cppcheck Premium)
74+
cppcheck --premium=metrics --xml-version=3 ... 2> results.xml
75+
python3 report.py results.xml -o cppcheck-report
76+
77+
Then open `cppcheck-report/index.html` in a browser.
78+
79+
Options:
80+
81+
* `-o DIR`, `--output-dir DIR` directory where the report is written (default: cppcheck-report)
82+
* `--xml FILE` xml report (xml files can also be given as positional arguments)
83+
* `--baseline FILE` baseline xml report, warnings that are not in the baseline are new (can be given several times). `--old` is an alias. If it is not given, the newest `--history`/`--snapshot` report is used.
84+
* `--history DIR` directory with older xml reports for the trend graphs. They are ordered by the date in the file name (`results-2026-05-01.xml`), or by file time.
85+
* `--snapshot FILE` older xml report for the trend graphs (can be given several times, oldest first)
86+
* `--product-map FILE` json file that maps path prefixes to product names: `{"src/core": "Core", "lib/net": "Network"}`. Without it, products are guessed from the first directory below the common source directory (`src/core/x.cpp` becomes "Core").
87+
* `--metrics-thresholds FILE` json file with metric thresholds, overrides the defaults: `{"cyclomaticComplexity": {"max": 15}, "HISCOMF": {"min": 10}}`
88+
* `--source-dir DIR` where the source files are located (can be given several times). By default the current directory and the directories of the xml files are searched.
89+
* `--source-encoding ENCODING` encoding of the source files (default: utf-8)
90+
* `--title TITLE` report title
91+
* `--theme THEME` default theme: light, apple, microsoft, dark, midnight, solarized (the viewer can switch theme in the report)
92+
93+
## Report directory
94+
95+
index.html open this in a browser
96+
report.css
97+
report.js
98+
data/results.js all warnings, trend data
99+
data/metrics.js metrics (if the xml has metrics), loaded when needed
100+
data/src/<n>.js source code, one file per source file, loaded when it is shown
101+
102+
The report works directly from the file system (no web server needed). Copy the whole directory to share it.
103+
104+
## Combining several XML files
105+
106+
Multiple xml files can be provided: `--xml file1.xml --xml file2.xml`. Duplicate warnings (same hash and location) are only shown once.
107+
108+
## Metric thresholds
109+
110+
The default thresholds are the HIS limits (same as Cppcheck Premium `HISReport.py`):
111+
112+
| Metric | Id | Threshold |
113+
|---|---|---|
114+
| Cyclomatic complexity v(G) | cyclomaticComplexity | max 10 |
115+
| Statements STMT | HISStmt | max 50 |
116+
| Execution paths PATH | HISPath | max 80 |
117+
| Nesting depth LEVEL | HISLevel | max 4 |
118+
| Called functions CALLS | HISCall | max 7 |
119+
| Calling functions CALLING | HISCalling | max 5 |
120+
| Parameters PARAM | HISParam | max 5 |
121+
| Return points RETURN | HISReturn | max 1 |
122+
| Goto statements GOTO | HISGoto | max 0 |
123+
| Language scope VOCF | HISVOCF | max 4 (computed from HISVocf_N / HISVocf_D) |
124+
| Comment density COMF % | HISCOMF | min 20 (computed from HISComment / HISStmtFile) |
125+
126+
They can be changed with `--metrics-thresholds`.
127+

0 commit comments

Comments
 (0)