From 8ee287cc7c904d2a8b7e34127d3d640cb2095a6d Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 18 Jan 2018 12:52:48 +0100 Subject: [PATCH] Bug 1431349 - Store some information about build configuration in chrome-map.json, so that the lcov rewriter doesn't need to import buildconfig. r=chmanchester --HG-- extra : rebase_source : b84ea5953a64b367cb31c253a30842e698118e81 --- .../mozbuild/codecoverage/chrome_map.py | 9 +++- .../mozbuild/codecoverage/lcov_rewriter.py | 43 +++++++++---------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/python/mozbuild/mozbuild/codecoverage/chrome_map.py b/python/mozbuild/mozbuild/codecoverage/chrome_map.py index 9ad2bdaaeb9b..0be1a9121de7 100644 --- a/python/mozbuild/mozbuild/codecoverage/chrome_map.py +++ b/python/mozbuild/mozbuild/codecoverage/chrome_map.py @@ -149,13 +149,14 @@ class ChromeMapBackend(CommonBackend): pp_info = None self._install_mapping[dest] = src.path, pp_info - # Our result has three parts: + # Our result has four parts: # A map from url prefixes to objdir directories: # { "chrome://mozapps/content/": [ "dist/bin/chrome/toolkit/content/mozapps" ], ... } # A map of overrides. # A map from objdir paths to sourcedir paths, and an object storing mapping information for preprocessed files: # { "dist/bin/browser/chrome/browser/content/browser/aboutSessionRestore.js": # [ "$topsrcdir/browser/components/sessionstore/content/aboutSessionRestore.js", {} ], ... } + # An object containing build configuration information. outputfile = os.path.join(self.environment.topobjdir, 'chrome-map.json') with self._write_file(outputfile) as fh: chrome_mapping = self.manifest_handler.chrome_mapping @@ -164,4 +165,10 @@ class ChromeMapBackend(CommonBackend): {k: list(v) for k, v in chrome_mapping.iteritems()}, overrides, self._install_mapping, + { + 'topobjdir': mozpath.normpath(self.environment.topobjdir), + 'MOZ_APP_NAME': self.environment.substs.get('MOZ_APP_NAME'), + 'OMNIJAR_NAME': self.environment.substs.get('OMNIJAR_NAME'), + 'MOZ_MACBUNDLE_NAME': self.environment.substs.get('MOZ_MACBUNDLE_NAME'), + } ], fh, sort_keys=True, indent=2) diff --git a/python/mozbuild/mozbuild/codecoverage/lcov_rewriter.py b/python/mozbuild/mozbuild/codecoverage/lcov_rewriter.py index 37a900176099..d1a7a5062611 100644 --- a/python/mozbuild/mozbuild/codecoverage/lcov_rewriter.py +++ b/python/mozbuild/mozbuild/codecoverage/lcov_rewriter.py @@ -11,8 +11,6 @@ from mozpack.chrome.manifest import parse_manifest import mozpack.path as mozpath from chrome_map import ChromeManifestHandler -import buildconfig - class LcovRecord(object): __slots__ = ("test_name", "source_file", @@ -404,23 +402,22 @@ class UrlFinder(object): # Given a "chrome://" or "resource://" url, uses data from the UrlMapBackend # and install manifests to find a path to the source file and the corresponding # (potentially pre-processed) file in the objdir. - def __init__(self, appdir, gredir, extra_chrome_manifests): - # Normalized for "startswith" checks below. - self.topobjdir = mozpath.normpath(buildconfig.topobjdir) - + def __init__(self, chrome_map_path, appdir, gredir, extra_chrome_manifests): # Cached entries self._final_mapping = {} - info_file = os.path.join(self.topobjdir, 'chrome-map.json') - try: - with open(info_file) as fh: - url_prefixes, overrides, install_info = json.load(fh) + with open(chrome_map_path) as fh: + url_prefixes, overrides, install_info, buildconfig = json.load(fh) except IOError: print("Error reading %s. Run |./mach build-backend -b ChromeMap| to " - "populate the ChromeMap backend." % info_file) + "populate the ChromeMap backend." % chrome_map_path) raise + self.topobjdir = buildconfig['topobjdir'] + self.MOZ_APP_NAME = buildconfig['MOZ_APP_NAME'] + self.OMNIJAR_NAME = buildconfig['OMNIJAR_NAME'] + # These are added dynamically in nsIResProtocolHandler, we might # need to get them at run time. if "resource:///" not in url_prefixes: @@ -433,13 +430,18 @@ class UrlFinder(object): self._respath = None - mac_bundle_name = buildconfig.substs.get('MOZ_MACBUNDLE_NAME') + mac_bundle_name = buildconfig['MOZ_MACBUNDLE_NAME'] if mac_bundle_name: self._respath = mozpath.join('dist', mac_bundle_name, 'Contents', 'Resources') + if not extra_chrome_manifests: + extra_path = os.path.join(self.topobjdir, '_tests', 'extra.manifest') + if os.path.isfile(extra_path): + extra_chrome_manifests = [extra_path] + if extra_chrome_manifests: self._populate_chrome(extra_chrome_manifests) @@ -556,8 +558,8 @@ class UrlFinder(object): url_obj = urlparse.urlparse(url) if url_obj.scheme == 'jar': - app_name = buildconfig.substs.get('MOZ_APP_NAME') - omnijar_name = buildconfig.substs.get('OMNIJAR_NAME') + app_name = self.MOZ_APP_NAME + omnijar_name = self.OMNIJAR_NAME if app_name in url: if omnijar_name in url: @@ -603,8 +605,8 @@ class UrlFinder(object): class LcovFileRewriter(object): # Class for partial parses of LCOV format and rewriting to resolve urls # and preprocessed file lines. - def __init__(self, appdir, gredir, extra_chrome_manifests): - self.url_finder = UrlFinder(appdir, gredir, extra_chrome_manifests) + def __init__(self, chrome_map_path, appdir, gredir, extra_chrome_manifests): + self.url_finder = UrlFinder(chrome_map_path, appdir, gredir, extra_chrome_manifests) self.pp_rewriter = RecordRewriter() def rewrite_files(self, in_paths, output_file, output_suffix): @@ -652,6 +654,8 @@ def main(): "by spidermonkey's code coverage, re-maps file urls " "back to source files and lines in preprocessed files " "back to their original locations.") + parser.add_argument("--chrome-map-path", default="chrome-map.json", + help="Path to the chrome-map.json file.") parser.add_argument("--app-dir", default="dist/bin/browser/", help="Prefix of the appdir in use. This is used to map " "urls starting with resource:///. It may differ by " @@ -670,13 +674,8 @@ def main(): help="The set of files to process.") args = parser.parse_args() - if not args.extra_chrome_manifests: - extra_path = os.path.join(buildconfig.topobjdir, '_tests', - 'extra.manifest') - if os.path.isfile(extra_path): - args.extra_chrome_manifests = [extra_path] - rewriter = LcovFileRewriter(args.app_dir, args.gre_dir, + rewriter = LcovFileRewriter(args.chrome_map_path, args.app_dir, args.gre_dir, args.extra_chrome_manifests) files = []