mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 784841 - Part 11: Add CONFIGURE_SUBST_FILES to moz.build files; r=ted
This commit is contained in:
parent
f018b82438
commit
155fdfa487
@ -8,7 +8,10 @@ import logging
|
||||
import os
|
||||
|
||||
from .base import BuildBackend
|
||||
from ..frontend.data import DirectoryTraversal
|
||||
from ..frontend.data import (
|
||||
ConfigFileSubstitution,
|
||||
DirectoryTraversal,
|
||||
)
|
||||
from ..util import FileAvoidWrite
|
||||
|
||||
|
||||
@ -73,6 +76,10 @@ class RecursiveMakeBackend(BuildBackend):
|
||||
|
||||
if isinstance(obj, DirectoryTraversal):
|
||||
self._process_directory_traversal(obj, backend_file)
|
||||
elif isinstance(obj, ConfigFileSubstitution):
|
||||
backend_file.inputs.add(obj.input_path)
|
||||
backend_file.outputs.add(obj.output_path)
|
||||
self.environment.create_config_file(obj.output_path)
|
||||
|
||||
self._backend_files[obj.srcdir] = backend_file
|
||||
|
||||
|
@ -91,3 +91,22 @@ class DirectoryTraversal(SandboxDerived):
|
||||
self.tier_static_dirs = OrderedDict()
|
||||
self.external_make_dirs = []
|
||||
self.parallel_external_make_dirs = []
|
||||
|
||||
|
||||
class ConfigFileSubstitution(SandboxDerived):
|
||||
"""Describes a config file that will be generated using substitutions.
|
||||
|
||||
The output_path attribute defines the relative path from topsrcdir of the
|
||||
output file to generate.
|
||||
"""
|
||||
__slots__ = (
|
||||
'input_path',
|
||||
'output_path',
|
||||
)
|
||||
|
||||
def __init__(self, sandbox):
|
||||
SandboxDerived.__init__(self, sandbox)
|
||||
|
||||
self.input_path = None
|
||||
self.output_path = None
|
||||
|
||||
|
@ -4,7 +4,13 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .data import DirectoryTraversal
|
||||
import os
|
||||
|
||||
from .data import (
|
||||
DirectoryTraversal,
|
||||
ConfigFileSubstitution,
|
||||
)
|
||||
|
||||
from .reader import MozbuildSandbox
|
||||
|
||||
|
||||
@ -42,6 +48,15 @@ class TreeMetadataEmitter(object):
|
||||
# the recursive make backend.
|
||||
for o in self._emit_directory_traversal_from_sandbox(sandbox): yield o
|
||||
|
||||
for path in sandbox['CONFIGURE_SUBST_FILES']:
|
||||
if os.path.isabs(path):
|
||||
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)
|
||||
yield sub
|
||||
|
||||
def _emit_directory_traversal_from_sandbox(self, sandbox):
|
||||
o = DirectoryTraversal(sandbox)
|
||||
o.dirs = sandbox.get('DIRS', [])
|
||||
|
@ -130,6 +130,16 @@ VARIABLES = {
|
||||
'PARALLEL_EXTERNAL_MAKE_DIRS': (list, [],
|
||||
"""Parallel version of EXTERNAL_MAKE_DIRS.
|
||||
"""),
|
||||
|
||||
'CONFIGURE_SUBST_FILES': (list, [],
|
||||
"""Output files that will be generated using configure-like substitution.
|
||||
|
||||
This is a substitute for AC_OUTPUT in autoconf. For each path in this
|
||||
list, we will search for a file in the srcdir having the name
|
||||
{path}.in. The contents of this file will be read and variable patterns
|
||||
like @foo@ will be substituted with the values of the AC_SUBST
|
||||
variables declared during configure.
|
||||
"""),
|
||||
}
|
||||
|
||||
# The set of functions exposed to the sandbox.
|
||||
|
@ -45,6 +45,14 @@ CONFIGS = {
|
||||
'non_global_defines': [],
|
||||
'substs': [],
|
||||
},
|
||||
'substitute_config_files': {
|
||||
'defines': [],
|
||||
'non_global_defines': [],
|
||||
'substs': [
|
||||
('MOZ_FOO', 'foo'),
|
||||
('MOZ_BAR', 'bar'),
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
TEST = @MOZ_FOO@
|
@ -0,0 +1,4 @@
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
CONFIGURE_SUBST_FILES = ['foo']
|
@ -101,5 +101,17 @@ class TestRecursiveMakeBackend(BackendTester):
|
||||
'PARALLEL_DIRS += p_external',
|
||||
])
|
||||
|
||||
def test_substitute_config_files(self):
|
||||
"""Ensure substituted config files are produced."""
|
||||
env = self._consume('substitute_config_files', RecursiveMakeBackend)
|
||||
|
||||
p = os.path.join(env.topobjdir, 'foo')
|
||||
self.assertTrue(os.path.exists(p))
|
||||
lines = [l.strip() for l in open(p, 'rt').readlines()]
|
||||
self.assertEqual(lines, [
|
||||
'TEST = foo',
|
||||
])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -0,0 +1,5 @@
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
CONFIGURE_SUBST_FILES += ['foo']
|
||||
CONFIGURE_SUBST_FILES += ['bar']
|
@ -9,7 +9,10 @@ import unittest
|
||||
|
||||
from mozunit import main
|
||||
|
||||
from mozbuild.frontend.data import DirectoryTraversal
|
||||
from mozbuild.frontend.data import (
|
||||
ConfigFileSubstitution,
|
||||
DirectoryTraversal,
|
||||
)
|
||||
from mozbuild.frontend.emitter import TreeMetadataEmitter
|
||||
from mozbuild.frontend.reader import BuildReader
|
||||
|
||||
@ -90,6 +93,23 @@ class TestEmitterBasic(unittest.TestCase):
|
||||
self.assertEqual(reldirs, ['', 'foo', 'foo/biz', 'foo_static', 'bar',
|
||||
'baz'])
|
||||
|
||||
def test_config_file_substitution(self):
|
||||
reader = self.reader('config-file-substitution')
|
||||
emitter = TreeMetadataEmitter(reader.config)
|
||||
|
||||
objs = list(emitter.emit(reader.read_topsrcdir()))
|
||||
self.assertEqual(len(objs), 3)
|
||||
|
||||
self.assertIsInstance(objs[0], DirectoryTraversal)
|
||||
self.assertIsInstance(objs[1], ConfigFileSubstitution)
|
||||
self.assertIsInstance(objs[2], ConfigFileSubstitution)
|
||||
|
||||
topobjdir = reader.config.topobjdir
|
||||
self.assertEqual(objs[1].output_path,
|
||||
os.path.normpath(os.path.join(topobjdir, 'foo')))
|
||||
self.assertEqual(objs[2].output_path,
|
||||
os.path.normpath(os.path.join(topobjdir, 'bar')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -293,6 +293,13 @@ add_tier_dir('t1', 'bat', static=True)
|
||||
e = sce.exception
|
||||
self.assertEqual(e.message, 'This is an error.')
|
||||
|
||||
def test_substitute_config_files(self):
|
||||
sandbox = self.sandbox()
|
||||
|
||||
sandbox.exec_source('CONFIGURE_SUBST_FILES += ["foo", "bar"]',
|
||||
'test.py')
|
||||
self.assertEqual(sandbox['CONFIGURE_SUBST_FILES'], ['foo', 'bar'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user