Bug 818246 - Part 2: Support moz.build -> Makefile variable passthru; r=glandium
authorGregory Szorc <gps@mozilla.com>
Thu, 07 Mar 2013 05:05:03 -0800
changeset 130532 c22a331c755f3158cf26ad8d8d75b26dbe18bf25
parent 130531 b04032e5289ea7d016eae56e0c8202367761c2a2
child 130533 872cb5946d2f9b9232ba41df388e44564e0f619b
push idunknown
push userunknown
push dateunknown
reviewersglandium
bugs818246
milestone22.0a1
Bug 818246 - Part 2: Support moz.build -> Makefile variable passthru; r=glandium
python/mozbuild/mozbuild/backend/recursivemake.py
python/mozbuild/mozbuild/frontend/data.py
python/mozbuild/mozbuild/frontend/emitter.py
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -9,16 +9,17 @@ import logging
 import os
 import types
 
 from .base import BuildBackend
 from ..frontend.data import (
     ConfigFileSubstitution,
     DirectoryTraversal,
     SandboxDerived,
+    VariablePassthru,
 )
 from ..util import FileAvoidWrite
 
 
 class BackendMakeFile(object):
     """Represents a generated backend.mk file.
 
     This is both a wrapper around a file handle as well as a container that
@@ -173,16 +174,25 @@ class RecursiveMakeBackend(BuildBackend)
 
         if isinstance(obj, DirectoryTraversal):
             self._process_directory_traversal(obj, backend_file)
         elif isinstance(obj, ConfigFileSubstitution):
             backend_file.write('SUBSTITUTE_FILES += %s\n' % obj.relpath)
             self._update_from_avoid_write(
                 backend_file.environment.create_config_file(obj.output_path))
             self.summary.managed_count += 1
+        elif isinstance(obj, VariablePassthru):
+            # Sorted so output is consistent and we don't bump mtimes.
+            for k, v in sorted(obj.variables.items()):
+                if isinstance(v, list):
+                    for item in v:
+                        backend_file.write('%s += %s\n' % (k, item))
+
+                else:
+                    backend_file.write('%s := %s\n' % (k, v))
 
         self._backend_files[obj.srcdir] = backend_file
 
     def consume_finished(self):
         for srcdir in sorted(self._backend_files.keys()):
             bf = self._backend_files[srcdir]
 
             if not os.path.exists(bf.objdir):
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -115,8 +115,24 @@ class ConfigFileSubstitution(SandboxDeri
 
     def __init__(self, sandbox):
         SandboxDerived.__init__(self, sandbox)
 
         self.input_path = None
         self.output_path = None
         self.relpath = None
 
+
+class VariablePassthru(SandboxDerived):
+    """A dict of variables to pass through to backend.mk unaltered.
+
+    The purpose of this object is to facilitate rapid transitioning of
+    variables from Makefile.in to moz.build. In the ideal world, this class
+    does not exist and every variable has a richer class representing it.
+    As long as we rely on this class, we lose the ability to have flexibility
+    in our build backends since we will continue to be tied to our rules.mk.
+    """
+    __slots__ = ('variables')
+
+    def __init__(self, sandbox):
+        SandboxDerived.__init__(self, sandbox)
+        self.variables = {}
+
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -2,18 +2,19 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import unicode_literals
 
 import os
 
 from .data import (
+    ConfigFileSubstitution,
     DirectoryTraversal,
-    ConfigFileSubstitution,
+    VariablePassthru,
     ReaderSummary,
 )
 
 from .reader import MozbuildSandbox
 
 
 class TreeMetadataEmitter(object):
     """Converts the executed mozbuild files into data structures.
@@ -64,16 +65,24 @@ class TreeMetadataEmitter(object):
                 path = path[1:]
 
             sub = ConfigFileSubstitution(sandbox)
             sub.input_path = os.path.join(sandbox['SRCDIR'], '%s.in' % path)
             sub.output_path = os.path.join(sandbox['OBJDIR'], path)
             sub.relpath = path
             yield sub
 
+        # Proxy some variables as-is until we have richer classes to represent
+        # them. We should aim to keep this set small because it violates the
+        # desired abstraction of the build definition away from makefiles.
+        passthru = VariablePassthru(sandbox)
+
+        if passthru.variables:
+            yield passthru
+
     def _emit_directory_traversal_from_sandbox(self, sandbox):
         o = DirectoryTraversal(sandbox)
         o.dirs = sandbox.get('DIRS', [])
         o.parallel_dirs = sandbox.get('PARALLEL_DIRS', [])
         o.tool_dirs = sandbox.get('TOOL_DIRS', [])
         o.test_dirs = sandbox.get('TEST_DIRS', [])
         o.test_tool_dirs = sandbox.get('TEST_TOOL_DIRS', [])
         o.external_make_dirs = sandbox.get('EXTERNAL_MAKE_DIRS', [])