Bug 818246 - Part 2: Support moz.build -> Makefile variable passthru; r=glandium

--HG--
extra : rebase_source : c9a914e1466e74d079383ef1162a4d1f9959a05c
This commit is contained in:
Gregory Szorc 2013-03-07 05:05:03 -08:00
parent 58b7ec0116
commit 723c59fd18
3 changed files with 36 additions and 1 deletions

View File

@ -14,6 +14,7 @@ from ..frontend.data import (
ConfigFileSubstitution,
DirectoryTraversal,
SandboxDerived,
VariablePassthru,
)
from ..util import FileAvoidWrite
@ -178,6 +179,15 @@ class RecursiveMakeBackend(BuildBackend):
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

View File

@ -120,3 +120,19 @@ class ConfigFileSubstitution(SandboxDerived):
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 = {}

View File

@ -7,8 +7,9 @@ from __future__ import unicode_literals
import os
from .data import (
DirectoryTraversal,
ConfigFileSubstitution,
DirectoryTraversal,
VariablePassthru,
ReaderSummary,
)
@ -69,6 +70,14 @@ class TreeMetadataEmitter(object):
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', [])