Bug 1287023 - Allow to use delayed_getattr in more cases. r?chmanchester
Until now, it's not been possible to do something as straightforward as:
option('--foo', default=delayed_getattr(milestone, 'is_nightly'))
The reason is that option's default needs what it's given, if it's a
@depends function, to depend on --help.
But we can't have every delayed_getattr add dependencies on --help,
because that would make unwanted things to depend on --help and run
when displaying the help.
Until we can totally remove --help dependencies, this change makes the
resulting @depends function created by delayed_getattr depend on --help
if the @depends function it's given already depends on --help.
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -132,24 +132,31 @@ def namespace(**kwargs):
# such as `set_config`. But those functions do not take immediate values.
# The `delayed_getattr` function allows access to attributes from the result
# of a @depends function in a non-immediate manner.
# @depends('--option')
# def option(value)
# return namespace(foo=value)
# set_config('FOO', delayed_getattr(option, 'foo')
@template
+@imports('__sandbox__')
def delayed_getattr(func, key):
- @depends(func)
- def result(value):
+ _, deps = __sandbox__._depends.get(func, (None, ()))
+
+ def result(value, _=None):
# The @depends function we're being passed may have returned
# None, or an object that simply doesn't have the wanted key.
# In that case, just return None.
return getattr(value, key, None)
- return result
+
+ # Automatically add a dependency on --help when the given @depends
+ # function.
+ if __sandbox__._help_option in deps:
+ return depends(func, '--help')(result)
+ return depends(func)(result)
# Like @depends, but the decorated function is only called if one of the
# arguments it would be called with has a positive value (bool(value) is True)
@template
def depends_if(*args):
def decorator(func):
@depends(*args)