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: