From cd3055975d551a503fee07f91158e17edf29ab52 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Tue, 30 Jul 2019 06:44:52 +0000 Subject: [PATCH] Bug 1568771 - Output paths relative to repository in ./mach static-analysis check-coverity, r=andi Differential Revision: https://phabricator.services.mozilla.com/D39306 --HG-- extra : moz-landing-system : lando --- .../mozbuild/mozbuild/code-analysis/mach_commands.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 4e93cefbdb97..c3015ae52533 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -405,6 +405,13 @@ class StaticAnalysis(MachCommandBase): def dump_cov_artifact(self, cov_results, source, output): # Parse Coverity json into structured issues + + def relpath(path): + '''Build path relative to repository root''' + if path.startswith(self.topsrcdir): + return os.path.relpath(path, self.topsrcdir) + return path + with open(cov_results) as f: result = json.load(f) @@ -435,7 +442,7 @@ class StaticAnalysis(MachCommandBase): # Embed all events into extra message for event in issue['events']: dict_issue['extra']['stack'].append( - {'file_path': event['strippedFilePathname'], + {'file_path': relpath(event['strippedFilePathname']), 'line_number': event['lineNumber'], 'path_type': event['eventTag'], 'description': event['eventDescription']}) @@ -453,6 +460,7 @@ class StaticAnalysis(MachCommandBase): issue['strippedMainEventFilePathname']) ) continue + path = relpath(path) if path in files_list: files_list[path]['warnings'].append(build_element(issue)) else: