]> xenbits.xensource.com Git - xen.git/commitdiff
xen/cppcheck: sort alphabetically cppcheck report entries
authorLuca Fancellu <luca.fancellu@arm.com>
Mon, 30 Jan 2023 11:01:31 +0000 (11:01 +0000)
committerStefano Stabellini <stefano.stabellini@amd.com>
Thu, 2 Feb 2023 20:02:43 +0000 (12:02 -0800)
Sort alphabetically cppcheck report entries when producing the text
report, this will help comparing different reports and will group
together findings from the same file.

The sort operation is performed with two criteria, the first one is
sorting by misra rule, the second one is sorting by file.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
[stefano: add black line for code style]
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
xen/scripts/xen_analysis/cppcheck_report_utils.py

index 02440aefdfec22e7818c5f86161e21c74ed2315b..c5f466aff14193ef4e62473cdb25df854d29fac6 100644 (file)
@@ -104,6 +104,14 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths):
                 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(":")
+
+            # 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]))
+            # merge back with : separator
+            text_report_content = [":".join(x) for x in text_report_content]
             # Write the final text report
             outfile.writelines(text_report_content)
     except OSError as e: