Bug 1287023 - Allow to use delayed_getattr in more cases. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 15 Jul 2016 12:26:58 +0900
changeset 387938 bfd832c02bde2bc570a921f330a8b0afa5d96d41
parent 387865 7beb114f146d8d1ca802f08cfa4d865fd550c20a
child 525489 b977604f3af19deef2253399c3f31e9efff973c0
push id23112
push userbmo:mh+mozilla@glandium.org
push dateFri, 15 Jul 2016 03:38:58 +0000
reviewerschmanchester
bugs1287023
milestone50.0a1
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.
build/moz.configure/util.configure
--- 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)