Bug 1416239 - Use GCOV_PREFIX_STRIP to strip prefix from the gcda target path. r=jmaher
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Sat, 11 Nov 2017 12:00:50 +0100
changeset 391569 0d54bbebadb2879bf73f492e9bf216a458e22878
parent 391568 e3e146e9bf9c1f9706597c4a656f73618348c99b
child 391570 15fa308daad34deadae4bf219cb984cf559578c2
push id32893
push userncsoregi@mozilla.com
push dateMon, 13 Nov 2017 22:58:13 +0000
treeherdermozilla-central@c9f889585dd8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1416239
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1416239 - Use GCOV_PREFIX_STRIP to strip prefix from the gcda target path. r=jmaher
testing/mozharness/mozharness/mozilla/testing/codecoverage.py
--- a/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
+++ b/testing/mozharness/mozharness/mozilla/testing/codecoverage.py
@@ -40,16 +40,17 @@ code_coverage_config_options = [
 
 class CodeCoverageMixin(object):
     """
     Mixin for setting GCOV_PREFIX during test execution, packaging up
     the resulting .gcda files and uploading them to blobber.
     """
     gcov_dir = None
     jsvm_dir = None
+    prefix = None
 
     @property
     def code_coverage_enabled(self):
         try:
             if self.config.get('code_coverage'):
                 return True
 
             # XXX workaround because bug 1110465 is hard
@@ -76,16 +77,28 @@ class CodeCoverageMixin(object):
             return 'jsdcov' in self.buildbot_config['properties']['stage_platform']
         except (AttributeError, KeyError, TypeError):
             return False
 
     @PreScriptAction('run-tests')
     def _set_gcov_prefix(self, action):
         if not self.code_coverage_enabled:
             return
+
+        if mozinfo.os == 'linux':
+            self.prefix = '/builds/worker/workspace/build/src/'
+            strip_count = self.prefix.count('/')
+        elif mozinfo.os == 'win':
+            self.prefix = 'z:/build/build/src/'
+            # Add 1 as on Windows the path where the compiler tries to write the
+            # gcda files has an additional 'obj-firefox' component.
+            strip_count = self.prefix.count('/') + 1
+
+        os.environ['GCOV_PREFIX_STRIP'] = str(strip_count)
+
         # Set the GCOV directory.
         self.gcov_dir = tempfile.mkdtemp()
         os.environ['GCOV_PREFIX'] = self.gcov_dir
 
         # Set JSVM directory.
         self.jsvm_dir = tempfile.mkdtemp()
         os.environ['JS_CODE_COVERAGE_OUTPUT_DIR'] = self.jsvm_dir
 
@@ -134,60 +147,40 @@ class CodeCoverageMixin(object):
                     os.remove(os.path.join(jsdcov_dir, filename))
 
             self.info("Completed compression of JSDCov artifacts!")
             self.info("Path to JSDCov compressed artifacts: " + zipFile)
 
         if not self.code_coverage_enabled:
             return
 
+        del os.environ['GCOV_PREFIX_STRIP']
         del os.environ['GCOV_PREFIX']
         del os.environ['JS_CODE_COVERAGE_OUTPUT_DIR']
 
         if not self.ccov_upload_disabled:
-            # TODO This is fragile, find rel_topsrcdir properly somehow
-            # We need to find the path relative to the gecko topsrcdir. Use
-            # some known gecko directories as a test.
-            canary_dirs = ['browser', 'docshell', 'dom', 'js', 'layout', 'toolkit', 'xpcom', 'xpfe']
-            rel_topsrcdir = None
-            for root, dirs, files in os.walk(self.gcov_dir):
-                # need to use 'any' in case no gcda data was generated in that subdir.
-                if any(d in dirs for d in canary_dirs):
-                    rel_topsrcdir = root
-                    break
-
-            if rel_topsrcdir is None:
-                # Unable to upload code coverage files. Since this is the whole
-                # point of code coverage, making this fatal.
-                self.fatal("Could not find relative topsrcdir in code coverage data!")
-
             dirs = self.query_abs_dirs()
 
             # Package GCOV coverage data.
             file_path_gcda = os.path.join(dirs['abs_blob_upload_dir'], 'code-coverage-gcda.zip')
-            self.run_command(['zip', '-r', file_path_gcda, '.'], cwd=rel_topsrcdir)
+            self.run_command(['zip', '-r', file_path_gcda, '.'], cwd=self.gcov_dir)
 
             # Package JSVM coverage data.
             file_path_jsvm = os.path.join(dirs['abs_blob_upload_dir'], 'code-coverage-jsvm.zip')
             self.run_command(['zip', '-r', file_path_jsvm, '.'], cwd=self.jsvm_dir)
 
             # GRCOV post-processing
             # Download the gcno fom the build machine.
             self.download_file(self.url_to_gcno, file_name=None, parent_dir=self.grcov_dir)
 
-            if mozinfo.os == 'linux':
-                prefix = '/builds/worker/workspace/build/src/'
-            elif mozinfo.os == 'win':
-                prefix = 'z:/build/build/src/'
-
             # Run grcov on the zipped .gcno and .gcda files.
             grcov_command = [
                 os.path.join(self.grcov_dir, 'grcov'),
                 '-t', 'lcov',
-                '-p', prefix,
+                '-p', self.prefix,
                 '--ignore-dir', 'gcc',
                 os.path.join(self.grcov_dir, 'target.code-coverage-gcno.zip'), file_path_gcda
             ]
 
             # 'grcov_output' will be a tuple, the first variable is the path to the lcov output,
             # the other is the path to the standard error output.
             grcov_output = self.get_output_from_command(
                 grcov_command,