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.
--- 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