Bug 1568776 - Output paths relative to repository in coverity, r=andi,jcj
authorBastien Abadie <bastien@mozilla.com>
Thu, 25 Jul 2019 20:42:49 +0000
changeset 15238 c29b58d70d289686cede10f67acd106afdc7c2d6
parent 15237 221c90384c9ad5ad92e24073ce2f31003b7f13e5
child 15239 d57bae1204fa4643d75ca20e3a5b518a4e21c6df
push id3450
push userjjones@mozilla.com
push dateThu, 25 Jul 2019 20:43:00 +0000
reviewersandi, jcj
bugs1568776
Bug 1568776 - Output paths relative to repository in coverity, r=andi,jcj Differential Revision: https://phabricator.services.mozilla.com/D39311
mach
--- a/mach
+++ b/mach
@@ -192,16 +192,23 @@ class coverityAction(argparse.Action):
 
     def cov_is_file_in_source(self, abs_path):
         if os.path.islink(abs_path):
             abs_path = os.path.realpath(abs_path)
         return abs_path
 
     def dump_cov_artifact(self, cov_results, source, output):
         import json
+
+        def relpath(path):
+            '''Build path relative to repository root'''
+            if path.startswith(cwd):
+                return os.path.relpath(path, cwd)
+            return path
+
         # Parse Coverity json into structured issues
         with open(cov_results) as f:
             result = json.load(f)
 
             # Parse the issues to a standard json format
             issues_dict = {'files': {}}
 
             files_list = issues_dict['files']
@@ -218,30 +225,31 @@ class coverityAction(argparse.Action):
                         'category': issue['checkerProperties']['category'],
                         'stateOnServer': issue['stateOnServer'],
                         'stack': []
                     }
                 }
 
                 # Embed all events into extra message
                 for event in issue['events']:
-                    dict_issue['extra']['stack'].append({'file_path': event['strippedFilePathname'],
+                    dict_issue['extra']['stack'].append({'file_path': relpath(event['strippedFilePathname']),
                                                          'line_number': event['lineNumber'],
                                                          'path_type': event['eventTag'],
                                                          'description': event['eventDescription']})
 
                 return dict_issue
 
             for issue in result['issues']:
                 path = self.cov_is_file_in_source(issue['strippedMainEventFilePathname'])
                 if path is None:
                     # Since we skip a result we should log it
                     print('Skipping CID: {0} from file: {1} since it\'s not related with the current patch.'.format(
                         issue['stateOnServer']['cid'], issue['strippedMainEventFilePathname']))
                     continue
+                path = relpath(path)
                 if path in files_list:
                     files_list[path]['warnings'].append(build_element(issue))
                 else:
                     files_list[path] = {'warnings': [build_element(issue)]}
 
             with open(output, 'w') as f:
                 json.dump(issues_dict, f)