Bug 1269513 - Add a template to execute a depends function only when a given value is present. r=glandium
MozReview-Commit-ID: H99fVOqlh8d
--- 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