Bug 1322025 - Enforce --help requirement on option's when argument. r=chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 25 Jan 2017 14:37:34 +0900
changeset 467000 f9158bc3711f98a09d6537a73859d56890d7601e
parent 466999 6dee89eae3b2b77f2b2f05c4d979f825147198df
child 467001 1db43252c94cf50bbf256e098d587939a4416e7d
push id43083
push userbmo:mh+mozilla@glandium.org
push dateFri, 27 Jan 2017 00:32:10 +0000
reviewerschmanchester
bugs1322025, 1316957
milestone54.0a1
Bug 1322025 - Enforce --help requirement on option's when argument. r=chmanchester Options with a `when` argument (either directly, or inherited through only_when() or an include) require --help per _value_for_option, but that code path is not exercised during a lint pass. With this change, along the previous one, we now correctly detect that bug 1316957 was not supposed to work as is.
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
@@ -109,16 +109,23 @@ class LintSandbox(ConfigureSandbox):
                         % (obj.name, arg.name, arg.name))
         elif ((self._help or need_help_dependency) and
               self._missing_help_dependency(obj)):
             raise ConfigureError("Missing @depends for `%s`: '--help'" %
                                  obj.name)
         return super(LintSandbox, self)._value_for_depends(
             obj, need_help_dependency)
 
+    def option_impl(self, *args, **kwargs):
+        result = super(LintSandbox, self).option_impl(*args, **kwargs)
+        when = self._conditions.get(result)
+        if when:
+            self._value_for(when, need_help_dependency=True)
+        return result
+
     def unwrap(self, func):
         glob = func.func_globals
         while func in self._wrapped:
             if isinstance(func.func_globals, SandboxedGlobal):
                 glob = func.func_globals
             func = self._wrapped[func]
         return func, glob
 
--- a/python/mozbuild/mozbuild/test/configure/test_lint.py
+++ b/python/mozbuild/mozbuild/test/configure/test_lint.py
@@ -128,16 +128,31 @@ class TestLint(unittest.TestCase):
 
                 include(bar)
             '''):
                 self.lint_test()
 
         self.assertEquals(e.exception.message,
                           "Missing @depends for `foo`: '--help'")
 
+        with self.assertRaises(ConfigureError) as e:
+            with self.moz_configure('''
+                option('--foo', help='foo')
+                @depends('--foo')
+                @imports('os')
+                def foo(value):
+                    return value
+
+                option('--bar', help='bar', when=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