Bug 1365786 - Avoid missing --help dep error when a @depends function uses builtins. r?chmanchester
--- a/python/mozbuild/mozbuild/configure/lint.py
+++ b/python/mozbuild/mozbuild/configure/lint.py
@@ -89,16 +89,18 @@ class LintSandbox(ConfigureSandbox):
return True
for op, arg in disassemble_as_iter(func):
if op in ('LOAD_GLOBAL', 'STORE_GLOBAL'):
# There is a fake os module when one is not imported,
# and it's allowed for functions without a --help
# dependency.
if arg == 'os' and glob.get('os') is self.OS:
continue
+ if arg in self.BUILTINS:
+ continue
return True
return False
@memoize
def _value_for_depends(self, obj, need_help_dependency=False):
with_help = self._help_option in obj.dependencies
if with_help:
for arg in obj.dependencies:
--- a/python/mozbuild/mozbuild/test/configure/test_lint.py
+++ b/python/mozbuild/mozbuild/test/configure/test_lint.py
@@ -143,16 +143,49 @@ class TestLint(unittest.TestCase):
option('--bar', help='bar', when=foo)
'''):
self.lint_test()
self.assertEquals(e.exception.message,
"Missing @depends for `foo`: '--help'")
+ # This would have failed with "Missing @depends for `foo`: '--help'"
+ # in the past, because of the reference to the builtin False.
+ with self.moz_configure('''
+ option('--foo', help='foo')
+ @depends('--foo')
+ def foo(value):
+ return False or value
+
+ option('--bar', help='bar', when=foo)
+ '''):
+ self.lint_test()
+
+ # However, when something that is normally a builtin is overridden,
+ # we should still want the dependency on --help.
+ with self.assertRaises(ConfigureError) as e:
+ with self.moz_configure('''
+ @template
+ def tmpl():
+ False = 42
+
+ option('--foo', help='foo')
+ @depends('--foo')
+ def foo(value):
+ return False
+
+ option('--bar', help='bar', when=foo)
+ tmpl()
+ '''):
+ self.lint_test()
+
+ self.assertEquals(e.exception.message,
+ "Missing @depends for `foo`: '--help'")
+
# There is a default restricted `os` module when there is no explicit
# @imports, and it's fine to use it without a dependency on --help.
with self.moz_configure('''
option('--foo', help='foo')
@depends('--foo')
def foo(value):
os
return value