Bug 1316250 - Allow functions using the fake os module to not depend on --help. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 09 Nov 2016 15:32:28 +0900
changeset 435816 2f13db72e87a6d83c5f7302344ef6e05fada873a
parent 435815 3cb4e1cb6073045baeb1a6e79e5b4de6956fae18
child 536383 4aa4e7c0c6c6f7bf9807605c041250f04d79f1ae
push id35126
push userbmo:mh+mozilla@glandium.org
push dateWed, 09 Nov 2016 06:43:04 +0000
reviewerschmanchester
bugs1316250
milestone52.0a1
Bug 1316250 - Allow functions using the fake os module to not depend on --help. r?chmanchester
python/mozbuild/mozbuild/configure/lint.py
python/mozbuild/mozbuild/test/configure/test_lint.py
--- 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()