This simple script merges XML files generated by cppcheck.
$ python merge_cppcheck_reports.py -h
usage: merge_cppcheck_reports.py [-h] [-r] file [file ...]
Merge cppcheck XML reports.
positional arguments:
file list of XML files
optional arguments:
-h, --help show this help message and exit
-r remove duplicates
Considering the following two examples (examples/report_1.xml
and examples/report_2.xml
, respectively):
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.82"/>
<errors>
Checking main.c ...
<error id="uninitvar" severity="error" msg="Uninitialized variable: p" verbose="Uninitialized variable: p" cwe="908">
<location file="main.c" line="4"/>
</error>
</errors>
</results>
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.82"/>
<errors>
Checking main.c ...
<error id="uninitvar" severity="error" msg="Uninitialized variable: p" verbose="Uninitialized variable: p" cwe="908">
<location file="main.c" line="4"/>
</error>
<error id="uninitvar" severity="error" msg="Uninitialized variable: p" verbose="Uninitialized variable: p2" cwe="908">
<location file="main.c" line="5"/>
</error>
</errors>
</results>
The script produces the following two outputs (without options and using option -r
, respectively):
$ python merge_cppcheck_reports.py examples/report_1.xml examples/report_2.xml
<results version="2">
<cppcheck version="1.82" />
<errors>
Checking main.c ...
<error cwe="908" id="uninitvar" msg="Uninitialized variable: p" severity="error" verbose="Uninitialized variable: p">
<location file="main.c" line="4" />
</error>
<error cwe="908" id="uninitvar" msg="Uninitialized variable: p" severity="error" verbose="Uninitialized variable: p">
<location file="main.c" line="4" />
</error>
<error cwe="908" id="uninitvar" msg="Uninitialized variable: p" severity="error" verbose="Uninitialized variable: p2">
<location file="main.c" line="5" />
</error>
</errors>
</results>
$ python merge_cppcheck_reports.py examples/report_1.xml examples/report_2.xml -r
<results version="2">
<cppcheck version="1.82" />
<errors>
Checking main.c ...
<error cwe="908" id="uninitvar" msg="Uninitialized variable: p" severity="error" verbose="Uninitialized variable: p">
<location file="main.c" line="4" />
</error>
<error cwe="908" id="uninitvar" msg="Uninitialized variable: p" severity="error" verbose="Uninitialized variable: p2">
<location file="main.c" line="5" />
</error>
</errors>
</results>