Bug 1269513 - Add a template to execute a depends function only when a given value is present. r=glandium
authorChris Manchester <cmanchester@mozilla.com>
Tue, 17 May 2016 14:40:03 -0700
changeset 297799 59d454cec87fd6ddc8ea92bba1dcd79aa8256e82
parent 297798 bb06914d6e8b96ea7d5c318da326febad908ab7c
child 297800 7aa9b5719a80742a9bc7c8ca0aa93fe31c2becb0
push id19274
push userryanvm@gmail.com
push dateWed, 18 May 2016 16:14:35 +0000
treeherderfx-team@4cfa7a2cefa7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1269513
milestone49.0a1
Bug 1269513 - Add a template to execute a depends function only when a given value is present. r=glandium MozReview-Commit-ID: H99fVOqlh8d
build/moz.configure/util.configure
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -121,8 +121,24 @@ def delayed_getattr(func, key):
 def depends_if(*args):
     def decorator(func):
         @depends(*args)
         def wrapper(*args):
             if any(arg for arg in args):
                 return func(*args)
         return wrapper
     return decorator
+
+# Like @depends_if, but a distinguished value passed as a keyword argument
+# "when" is truth tested instead of every argument. This value is not passed
+# to the function if it is called.
+@template
+def depends_when(*args, **kwargs):
+    if not len(kwargs) == 1 and kwargs.get('when'):
+        die('depends_when requires a single keyword argument, "when"')
+    when = kwargs['when']
+    def decorator(fn):
+        @depends(when, *args)
+        def wrapper(val, *args):
+            if val:
+                return fn(*args)
+        return wrapper
+    return decorator