Bug 1235021 - Associate a Defines instance to each ContextDerived instance. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 30 Nov 2015 07:46:05 +0900
changeset 277920 531617914786476f3d180ea787c2b245b299cee4
parent 277919 a9d167756f2fe583fd9dfaf7586095ebc256c4b9
child 277921 4d191d8983d60511bf53e74e2d4b9eda04ec28ac
push id69650
push usermh@glandium.org
push dateWed, 30 Dec 2015 22:08:21 +0000
treeherdermozilla-inbound@70708efd7d3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1235021
milestone46.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 1235021 - Associate a Defines instance to each ContextDerived instance. r=gps
python/mozbuild/mozbuild/backend/fastermake.py
python/mozbuild/mozbuild/frontend/data.py
--- a/python/mozbuild/mozbuild/backend/fastermake.py
+++ b/python/mozbuild/mozbuild/backend/fastermake.py
@@ -29,19 +29,16 @@ from itertools import chain
 import os
 import sys
 
 
 class FasterMakeBackend(CommonBackend):
     def _init(self):
         super(FasterMakeBackend, self)._init()
 
-        self._seen_directories = set()
-        self._defines = dict()
-
         self._manifest_entries = OrderedDefaultDict(set)
 
         self._install_manifests = OrderedDefaultDict(InstallManifest)
 
         self._dependencies = OrderedDefaultDict(list)
 
         self._has_xpidl = False
 
@@ -58,30 +55,22 @@ class FasterMakeBackend(CommonBackend):
             mozpath.join(obj.install_target, dest, target).replace('/', '_'))
         self._install_manifests[obj.install_target].add_preprocess(
             mozpath.join(obj.srcdir, path),
             mozpath.join(dest, target),
             depfile,
             **kwargs)
 
     def consume_object(self, obj):
-        if not isinstance(obj, Defines) and isinstance(obj, ContextDerived):
-            defines = self._defines.get(obj.objdir, {})
+        if isinstance(obj, (JARManifest, FinalTargetPreprocessedFiles)):
+            defines = obj.defines or {}
             if defines:
                 defines = defines.defines
 
-        if isinstance(obj, Defines):
-            self._defines[obj.objdir] = obj
-
-            # We're assuming below that Defines come first for a given objdir,
-            # which is kind of set in stone from the order things are treated
-            # in emitter.py.
-            assert obj.objdir not in self._seen_directories
-
-        elif isinstance(obj, JARManifest) and \
+        if isinstance(obj, JARManifest) and \
                 obj.install_target.startswith('dist/bin'):
             self._consume_jar_manifest(obj, defines)
 
         elif isinstance(obj, (FinalTargetFiles,
                               FinalTargetPreprocessedFiles)) and \
                 obj.install_target.startswith('dist/bin'):
             for path, files in obj.files.walk():
                 for f in files:
@@ -100,28 +89,19 @@ class FasterMakeBackend(CommonBackend):
             if obj.path != top_level:
                 entry = 'manifest %s' % mozpath.relpath(obj.path,
                                                         obj.install_target)
                 self._manifest_entries[top_level].add(entry)
             self._manifest_entries[obj.path].add(str(obj.entry))
 
         elif isinstance(obj, XPIDLFile):
             self._has_xpidl = True
-            # XPIDL are emitted before Defines, which breaks the assert in the
-            # branch for Defines. OTOH, we don't actually care about the
-            # XPIDLFile objects just yet, so we can just pretend we didn't see
-            # an object in the directory yet.
-            return True
 
-        else:
-            # We currently ignore a lot of object types, so just acknowledge
-            # everything.
-            return True
-
-        self._seen_directories.add(obj.objdir)
+        # We currently ignore a lot of object types, so just acknowledge
+        # everything.
         return True
 
     def _consume_jar_manifest(self, obj, defines):
         # Ideally, this would all be handled somehow in the emitter, but
         # this would require all the magic surrounding l10n and addons in
         # the recursive make backend to die, which is not going to happen
         # any time soon enough.
         # Notably missing:
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -73,20 +73,32 @@ class ContextDerived(TreeMetadata):
 
         self._context = context
 
     @property
     def install_target(self):
         return self._context['FINAL_TARGET']
 
     @property
+    def defines(self):
+        defines = self._context.get('DEFINES')
+        return Defines(self._context, defines) if defines else None
+
+    @property
     def relobjdir(self):
         return mozpath.relpath(self.objdir, self.topobjdir)
 
 
+class HostMixin(object):
+    @property
+    def defines(self):
+        defines = self._context.get('HOST_DEFINES')
+        return HostDefines(self._context, defines) if defines else None
+
+
 class DirectoryTraversal(ContextDerived):
     """Describes how directory traversal for building should work.
 
     This build object is likely only of interest to the recursive make backend.
     Other build backends should (ideally) not attempt to mimic the behavior of
     the recursive make backend. The only reason this exists is to support the
     existing recursive make backend while the transition to mozbuild frontend
     files is complete and we move to a more optimal build backend.
@@ -369,29 +381,29 @@ class BaseProgram(Linkable):
 
 
 class Program(BaseProgram):
     """Context derived container object for PROGRAM"""
     SUFFIX_VAR = 'BIN_SUFFIX'
     KIND = 'target'
 
 
-class HostProgram(BaseProgram):
+class HostProgram(HostMixin, BaseProgram):
     """Context derived container object for HOST_PROGRAM"""
     SUFFIX_VAR = 'HOST_BIN_SUFFIX'
     KIND = 'host'
 
 
 class SimpleProgram(BaseProgram):
     """Context derived container object for each program in SIMPLE_PROGRAMS"""
     SUFFIX_VAR = 'BIN_SUFFIX'
     KIND = 'target'
 
 
-class HostSimpleProgram(BaseProgram):
+class HostSimpleProgram(HostMixin, BaseProgram):
     """Context derived container object for each program in
     HOST_SIMPLE_PROGRAMS"""
     SUFFIX_VAR = 'HOST_BIN_SUFFIX'
     KIND = 'host'
 
 
 class BaseLibrary(Linkable):
     """Generic context derived container object for libraries."""
@@ -495,17 +507,17 @@ class ExternalStaticLibrary(StaticLibrar
     build system."""
 
 
 class ExternalSharedLibrary(SharedLibrary, ExternalLibrary):
     """Context derived container for shared libraries built by an external
     build system."""
 
 
-class HostLibrary(BaseLibrary):
+class HostLibrary(HostMixin, BaseLibrary):
     """Context derived container object for a host library"""
     KIND = 'host'
 
 
 class TestManifest(ContextDerived):
     """Represents a manifest file containing information about tests."""
 
     __slots__ = (
@@ -689,17 +701,17 @@ class Sources(BaseSources):
 
 class GeneratedSources(BaseSources):
     """Represents generated files to be compiled during the build."""
 
     def __init__(self, context, files, canonical_suffix):
         BaseSources.__init__(self, context, files, canonical_suffix)
 
 
-class HostSources(BaseSources):
+class HostSources(HostMixin, BaseSources):
     """Represents files to be compiled for the host during the build."""
 
     def __init__(self, context, files, canonical_suffix):
         BaseSources.__init__(self, context, files, canonical_suffix)
 
 
 class UnifiedSources(BaseSources):
     """Represents files to be compiled in a unified fashion during the build."""