Bug 1316250 - Allow functions using the fake os module to not depend on --help. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 09 Nov 2016 15:32:28 +0900
changeset 348543 fb579bc49c2f153e61cf06b34bcd6a03a409e6c4
parent 348542 53f988e1c1fd34ca2ff5f42a59fa05b4a768a1e5
child 348544 b737f14975c2a83bf6c3753528641e0f51745778
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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()