Skip to content

Commit 70909e7

Browse files
committed
Fix #15295 (report : new html-report with dashboard)
1 parent c3665c5 commit 70909e7

18 files changed

Lines changed: 3209 additions & 29 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
if: matrix.python-latest
108108
run: |
109109
shopt -s globstar
110-
pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py htmlreport/cppcheck-htmlreport htmlreport/**/*.py test/**/*.py tools/**/*.py
110+
pylint --jobs $(nproc) --py-version 3.7 addons/**/*.py reports/htmlreport/cppcheck-htmlreport reports/htmlreport/**/*.py test/**/*.py tools/**/*.py
111111
112112
- name: check .json files
113113
if: matrix.python-latest
@@ -123,8 +123,8 @@ jobs:
123123
run: |
124124
shopt -s globstar
125125
python -m py_compile addons/**/*.py
126-
python -m py_compile htmlreport/cppcheck-htmlreport
127-
python -m py_compile htmlreport/**/*.py
126+
python -m py_compile reports/htmlreport/cppcheck-htmlreport
127+
python -m py_compile reports/htmlreport/**/*.py
128128
python -m py_compile test/**/*.py
129129
python -m py_compile tools/**/*.py
130130
@@ -165,7 +165,7 @@ jobs:
165165
python -m venv venv
166166
source venv/bin/activate
167167
python -m pip install -U pip
168-
pip install ./htmlreport/
168+
pip install ./reports/htmlreport/
169169
which cppcheck-htmlreport
170170
PIP_PACKAGE_TEST=1 test/tools/htmlreport/test_htmlreport.py
171171
# TODO: does not test the pip binary

‎.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: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,11 +1341,11 @@ 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+
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 reports/htmlreport that contains a script that transforms a Cppcheck XML file into HTML output.
13451345

13461346
This command generates the help screen:
13471347

1348-
htmlreport/cppcheck-htmlreport -h
1348+
reports/htmlreport/cppcheck-htmlreport -h
13491349

13501350
The output screen says:
13511351

@@ -1394,6 +1394,53 @@ handled by the hosting service.
13941394
In general, local mode fits air-gapped environments, while remote mode works
13951395
best for CI workflows and large or private repositories.
13961396

1397+
# Cppcheck Explorer report
1398+
1399+
The script `reports/explorer/report.py` in the Cppcheck source tree converts Cppcheck XML output into a Cppcheck Explorer report, which you view in a browser. The report has a dashboard with graphs, and a results view where you can filter the warnings and see the related source code. It is designed to be responsive also when there are thousands of warnings.
1400+
1401+
You only need Python to run the script, no extra modules are required.
1402+
1403+
## Generating a report
1404+
1405+
First analyze the code and save the results in a XML file, then generate the report:
1406+
1407+
cppcheck --enable=style --xml src 2> results.xml
1408+
python3 reports/explorer/report.py results.xml -o cppcheck-report
1409+
1410+
Open `cppcheck-report/index.html` in a browser. No web server is needed. To share the report, copy the whole `cppcheck-report` folder. Note that the report contains the source code.
1411+
1412+
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:
1413+
1414+
python3 reports/explorer/report.py results.xml --source-dir=path/to/project -o cppcheck-report
1415+
1416+
## New and old warnings
1417+
1418+
If you provide the XML results from an earlier analysis as a baseline, then the report shows which warnings are new:
1419+
1420+
# Analyze the code and save the results as a baseline
1421+
cppcheck --enable=style --xml src 2> baseline.xml
1422+
1423+
# Later: analyze the code again and compare with the baseline
1424+
cppcheck --enable=style --xml src 2> results.xml
1425+
python3 reports/explorer/report.py results.xml --baseline=baseline.xml -o cppcheck-report
1426+
1427+
## Trend graphs
1428+
1429+
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:
1430+
1431+
mkdir -p history
1432+
cppcheck --enable=style --xml src 2> history/results-2026-05-01.xml
1433+
1434+
# Later: analyze the code again and show the trend
1435+
cppcheck --enable=style --xml src 2> results.xml
1436+
python3 reports/explorer/report.py results.xml --history=history -o cppcheck-report
1437+
1438+
If no `--baseline` is given, then the newest report in the history is used as baseline.
1439+
1440+
To see all options, run:
1441+
1442+
python3 reports/explorer/report.py -h
1443+
13971444
# Check level
13981445

13991446
## Reduced
@@ -1550,16 +1597,31 @@ Example:
15501597

15511598
cppcheck --premium=metrics test.c --xml-version=3 2> res.xml
15521599

1553-
We provide a small simple python script that creates a metrics report in CSV format:
1600+
To view the metrics, it is recommended that you generate a [Cppcheck Explorer report](#cppcheck-explorer-report):
1601+
1602+
python3 reports/explorer/report.py res.xml -o cppcheck-report
1603+
1604+
Open `cppcheck-report/index.html` in a browser. The dashboard shows a summary of the metrics and the metrics view shows
1605+
the values for each function and file. Values that exceed the thresholds are highlighted.
1606+
1607+
The default thresholds are the HIS limits. You can change them by providing a JSON file. Example `thresholds.json`:
1608+
1609+
{
1610+
"cyclomaticComplexity": {"max": 15},
1611+
"HISCOMF": {"min": 10}
1612+
}
1613+
1614+
Use the option `--metrics-thresholds` to load the file:
1615+
1616+
python3 reports/explorer/report.py res.xml --metrics-thresholds=thresholds.json -o cppcheck-report
1617+
1618+
If you want the metrics in CSV format, we provide a small simple python script for that:
15541619

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

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

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-
15631625
## Licenses
15641626

15651627
### 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)