xen/misra: xen-analysis.py: Fix cppcheck report relative paths

Fix the generation of the relative path from the repo, for cppcheck
reports, when the script is launching make with in-tree build.

Fixes: b046f7e374 ("xen/misra: xen-analysis.py: use the relative path from the ...")
Reported-by: Michal Orzel <michal.orzel@amd.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
Luca Fancellu authored and Jan Beulich committed 2023-05-30 11:57:17 +02:00
1 parent 8bd504290b
commit ca045140d9
1 file changed
+21 -4
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os
import os, re
from . import settings
from xml.etree import ElementTree
class CppcheckHTMLReportError(Exception):
@@ -101,12 +102,28 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths):
text_report_content = list(text_report_content)
# Strip path from report lines
for i in list(range(0, len(text_report_content))):
for path in strip_paths:
text_report_content[i] = text_report_content[i].replace(
path + "/", "")
# Split by : separator
text_report_content[i] = text_report_content[i].split(":")
for path in strip_paths:
text_report_content[i][0] = \
text_report_content[i][0].replace(path + "/", "")
# When the compilation is in-tree, the makefile places
# the directory in /xen/xen, making cppcheck produce
# relative path from there, so check if "xen/" is a prefix
# of the path and if it's not, check if it can be added to
# have a relative path from the repository instead of from
# /xen/xen
if not text_report_content[i][0].startswith("xen/"):
# cppcheck first entry is in this format:
# path/to/file(line,cols), remove (line,cols)
cppcheck_file = re.sub(r'\(.*\)', '',
text_report_content[i][0])
if os.path.isfile(settings.xen_dir + "/" + cppcheck_file):
text_report_content[i][0] = \
"xen/" + text_report_content[i][0]
# sort alphabetically for second field (misra rule) and as second
# criteria for the first field (file name)
text_report_content.sort(key = lambda x: (x[1], x[0]))
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.