bug 1241272 - Allow error() in moz.build files to be treated as non-fatal. r=gps

Calling error() in moz.build files to indicate unsupported configurations is
useful, but readers using EmptyConfig will trigger them currently. This patch
allows a Config to have an `error_is_fatal` attribute, which will make
error emit a warning instead.
This commit is contained in:
Ted Mielczarek 2016-01-20 15:11:49 -05:00
parent 03fdbe102e
commit fcc08f9802
4 changed files with 25 additions and 4 deletions

View File

@ -128,6 +128,11 @@ class Context(KeyedDefaultDict):
if path not in self._all_paths:
self._all_paths.insert(0, path)
@property
def error_is_fatal(self):
"""Returns True if the error function should be fatal."""
return self.config and getattr(self.config, 'error_is_fatal', True)
@property
def all_paths(self):
"""Returns all paths ever added to the context."""

View File

@ -134,6 +134,7 @@ class EmptyConfig(object):
self.substs_unicode = self.PopulateOnGetDict(EmptyValue, udict)
self.defines = self.substs
self.external_source_dir = None
self.error_is_fatal = False
def is_read_allowed(path, config):
@ -325,7 +326,10 @@ class MozbuildSandbox(Sandbox):
print('WARNING: %s' % message, file=sys.stderr)
def _error(self, message):
raise SandboxCalledError(self._context.source_stack, message)
if self._context.error_is_fatal:
raise SandboxCalledError(self._context.source_stack, message)
else:
self._warning(message)
def _template_decorator(self, func):
"""Registers a template function."""

View File

@ -18,7 +18,11 @@ log_manager.add_terminal_logging()
# mozconfig is not a reusable type (it's actually a module) so, we
# have to mock it.
class MockConfig(object):
def __init__(self, topsrcdir='/path/to/topsrcdir', extra_substs={}):
def __init__(self,
topsrcdir='/path/to/topsrcdir',
extra_substs={},
error_is_fatal=True,
):
self.topsrcdir = mozpath.abspath(topsrcdir)
self.topobjdir = mozpath.abspath('/path/to/topobjdir')
@ -41,3 +45,4 @@ class MockConfig(object):
self.import_suffix = '.so'
self.dll_prefix = 'lib'
self.dll_suffix = '.so'
self.error_is_fatal = error_is_fatal

View File

@ -42,11 +42,13 @@ class TestBuildReader(unittest.TestCase):
return MockConfig(path, **kwargs)
def reader(self, name, enable_tests=False, **kwargs):
def reader(self, name, enable_tests=False, error_is_fatal=True, **kwargs):
extra = {}
if enable_tests:
extra['ENABLE_TESTS'] = '1'
config = self.config(name, extra_substs=extra)
config = self.config(name,
extra_substs=extra,
error_is_fatal=error_is_fatal)
return BuildReader(config, **kwargs)
@ -239,6 +241,11 @@ class TestBuildReader(unittest.TestCase):
self.assertIn('A moz.build file called the error() function.', str(e))
self.assertIn(' Some error.', str(e))
def test_error_error_func_ok(self):
reader = self.reader('reader-error-error-func', error_is_fatal=False)
contexts = list(reader.read_topsrcdir())
def test_inheriting_variables(self):
reader = self.reader('inheriting-variables')