Bug 1365786 - Avoid missing --help dep error when a @depends function uses builtins. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 18 May 2017 09:32:39 +0900
changeset 579923 7d0170c9ff3fa468b0dc34ad87b8d1de0351bb63
parent 579873 f3b98c909414b02100ba3022030c9dab3185b3f3
child 629153 8c974e95d356514bf30d26de5e7afbb8e09e1ffd
push id59407
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 May 2017 00:33:07 +0000
reviewerschmanchester
bugs1365786
milestone55.0a1
Bug 1365786 - Avoid missing --help dep error when a @depends function uses builtins. 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
@@ -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