зеркало из https://github.com/mozilla/gecko-dev.git
Bug 784841 - Part 8: Capture and save moz.build tree state; r=ted
This commit is contained in:
Родитель
8a34faf22a
Коммит
88203907e7
|
@ -9,8 +9,12 @@ from abc import (
|
|||
abstractmethod,
|
||||
)
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from mach.mixin.logging import LoggingMixin
|
||||
|
||||
from ..frontend.data import SandboxDerived
|
||||
from .configenvironment import ConfigEnvironment
|
||||
|
||||
|
||||
|
@ -53,6 +57,12 @@ class BuildBackend(LoggingMixin):
|
|||
for obj in objs:
|
||||
self.consume_object(obj)
|
||||
|
||||
# Write out a file indicating when this backend was last generated.
|
||||
age_file = os.path.join(self.environment.topobjdir,
|
||||
'backend.%s.built' % self.__class__.__name__)
|
||||
with open(age_file, 'a'):
|
||||
os.utime(age_file, None)
|
||||
|
||||
self.consume_finished()
|
||||
|
||||
@abstractmethod
|
||||
|
|
|
@ -36,7 +36,11 @@ class BackendMakeFile(object):
|
|||
self.fh.write(buf)
|
||||
|
||||
def close(self):
|
||||
self.fh.write('BACKEND_OUTPUT_FILES += %s\n' % ' '.join(self.outputs))
|
||||
if len(self.inputs):
|
||||
self.fh.write('BACKEND_INPUT_FILES += %s\n' % ' '.join(self.inputs))
|
||||
|
||||
if len(self.outputs):
|
||||
self.fh.write('BACKEND_OUTPUT_FILES += %s\n' % ' '.join(self.outputs))
|
||||
|
||||
self.fh.close()
|
||||
|
||||
|
@ -65,6 +69,8 @@ class RecursiveMakeBackend(BuildBackend):
|
|||
backend_file = self._backend_files.get(obj.srcdir,
|
||||
BackendMakeFile(obj.srcdir, obj.objdir))
|
||||
|
||||
backend_file.inputs |= obj.sandbox_all_paths
|
||||
|
||||
if isinstance(obj, DirectoryTraversal):
|
||||
self._process_directory_traversal(obj, backend_file)
|
||||
|
||||
|
|
|
@ -34,12 +34,19 @@ class SandboxDerived(TreeMetadata):
|
|||
__slots__ = (
|
||||
'objdir',
|
||||
'relativedir',
|
||||
'sandbox_all_paths',
|
||||
'sandbox_path',
|
||||
'srcdir',
|
||||
'topobjdir',
|
||||
'topsrcdir',
|
||||
)
|
||||
|
||||
def __init__(self, sandbox):
|
||||
# Capture the files that were evaluated to build this sandbox.
|
||||
self.sandbox_main_path = sandbox.main_path
|
||||
self.sandbox_all_paths = sandbox.all_paths
|
||||
|
||||
# Basic directory state.
|
||||
self.topsrcdir = sandbox['TOPSRCDIR']
|
||||
self.topobjdir = sandbox['TOPOBJDIR']
|
||||
|
||||
|
|
|
@ -259,6 +259,8 @@ class Sandbox(object):
|
|||
builtins=builtins)
|
||||
self._locals = LocalNamespace(self._globals)
|
||||
self._execution_stack = []
|
||||
self.main_path = None
|
||||
self.all_paths = set()
|
||||
|
||||
def exec_file(self, path):
|
||||
"""Execute code at a path in the sandbox.
|
||||
|
@ -290,6 +292,11 @@ class Sandbox(object):
|
|||
"""
|
||||
self._execution_stack.append(path)
|
||||
|
||||
if self.main_path is None:
|
||||
self.main_path = path
|
||||
|
||||
self.all_paths.add(path)
|
||||
|
||||
# We don't have to worry about bytecode generation here because we are
|
||||
# too low-level for that. However, we could add bytecode generation via
|
||||
# the marshall module if parsing performance were ever an issue.
|
||||
|
|
|
@ -20,6 +20,8 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||
def test_basic(self):
|
||||
"""Ensure the RecursiveMakeBackend works without error."""
|
||||
env = self._consume('stub0', RecursiveMakeBackend)
|
||||
self.assertTrue(os.path.exists(os.path.join(env.topobjdir,
|
||||
'backend.RecursiveMakeBackend.built')))
|
||||
|
||||
def test_output_files(self):
|
||||
"""Ensure proper files are generated."""
|
||||
|
@ -60,7 +62,7 @@ class TestRecursiveMakeBackend(BackendTester):
|
|||
|
||||
p = os.path.join(env.topobjdir, 'backend.mk')
|
||||
|
||||
lines = [l.strip() for l in open(p, 'rt').readlines()[1:-1]]
|
||||
lines = [l.strip() for l in open(p, 'rt').readlines()[1:-2]]
|
||||
self.assertEqual(lines, [
|
||||
'DIRS := dir1',
|
||||
'PARALLEL_DIRS := dir2',
|
||||
|
|
|
@ -43,6 +43,8 @@ class TestEmitterBasic(unittest.TestCase):
|
|||
self.assertEqual(o.test_tool_dirs, [])
|
||||
self.assertEqual(len(o.tier_dirs), 0)
|
||||
self.assertEqual(len(o.tier_static_dirs), 0)
|
||||
self.assertTrue(os.path.isabs(o.sandbox_main_path))
|
||||
self.assertEqual(len(o.sandbox_all_paths), 1)
|
||||
|
||||
reldirs = [o.relativedir for o in objs]
|
||||
self.assertEqual(reldirs, ['', 'foo', 'foo/biz', 'bar'])
|
||||
|
|
|
@ -117,6 +117,8 @@ class TestSandbox(unittest.TestCase):
|
|||
sandbox.exec_source('foo = True', 'foo.py')
|
||||
|
||||
self.assertNotIn('foo', sandbox)
|
||||
self.assertEqual(sandbox.main_path, 'foo.py')
|
||||
self.assertEqual(sandbox.all_paths, set(['foo.py']))
|
||||
|
||||
def test_exec_compile_error(self):
|
||||
sandbox = self.sandbox()
|
||||
|
@ -126,6 +128,7 @@ class TestSandbox(unittest.TestCase):
|
|||
|
||||
self.assertEqual(se.exception.file_stack, ['foo.py'])
|
||||
self.assertIsInstance(se.exception.exc_value, SyntaxError)
|
||||
self.assertEqual(sandbox.main_path, 'foo.py')
|
||||
|
||||
def test_exec_import_denied(self):
|
||||
sandbox = self.sandbox()
|
||||
|
@ -210,6 +213,9 @@ add_tier_dir('t1', 'bat', static=True)
|
|||
sandbox.exec_file('moz.build')
|
||||
|
||||
self.assertEqual(sandbox['DIRS'], ['foo', 'bar'])
|
||||
self.assertEqual(sandbox.main_path,
|
||||
os.path.join(sandbox['TOPSRCDIR'], 'moz.build'))
|
||||
self.assertEqual(len(sandbox.all_paths), 2)
|
||||
|
||||
def test_include_outside_topsrcdir(self):
|
||||
sandbox = self.sandbox(data_path='include-outside-topsrcdir')
|
||||
|
|
Загрузка…
Ссылка в новой задаче