Bug 1287023 - Allow to use delayed_getattr in more cases. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 15 Jul 2016 12:26:58 +0900
changeset 330219 1665eb58981dbe6aa91c9be1bd4410f3e5843b80
parent 330218 8d1b225b7a5a25d2dd8a72b56d7bcdf263ede7fe
child 330220 7792f6453b843b82835a104cc58674f2de01e947
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 itself depends on --help.
+    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)