Bug 1316250 - Allow functions using the fake os module to not depend on --help. r?chmanchester
--- a/python/mozbuild/mozbuild/configure/lint.py
+++ b/python/mozbuild/mozbuild/configure/lint.py
@@ -32,25 +32,30 @@ class LintSandbox(ConfigureSandbox):
def _missing_help_dependency(self, obj):
if isinstance(obj, CombinedDependsFunction):
return False
if isinstance(obj, DependsFunction):
if (self._help_option in obj.dependencies or
obj in (self._always, self._never)):
return False
- func = self._wrapped[obj.func]
+ func, glob = self._wrapped[obj.func]
# We allow missing --help dependencies for functions that:
# - don't use @imports
# - don't have a closure
# - don't use global variables
if func in self._imports or func.func_closure:
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
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:
@@ -64,10 +69,10 @@ class LintSandbox(ConfigureSandbox):
raise ConfigureError("Missing @depends for `%s`: '--help'" %
obj.name)
return super(LintSandbox, self)._value_for_depends(
obj, need_help_dependency)
def _prepare_function(self, func):
wrapped, glob = super(LintSandbox, self)._prepare_function(func)
if wrapped not in self._wrapped:
- self._wrapped[wrapped] = func
+ self._wrapped[wrapped] = func, glob
return wrapped, glob
--- a/python/mozbuild/mozbuild/test/configure/test_lint.py
+++ b/python/mozbuild/mozbuild/test/configure/test_lint.py
@@ -109,11 +109,24 @@ class TestLint(unittest.TestCase):
include(foo)
'''):
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
+
+ include(foo)
+ '''):
+ self.lint_test()
+
if __name__ == '__main__':
main()