Bug 1384396 - Add a @depends_all utility function; r=nalexander
authorGregory Szorc <gps@mozilla.com>
Tue, 25 Jul 2017 22:00:38 -0700
changeset 422602 abd5c5d03d1cc14b92d1cf2e9a8bce3b3b5dd2f0
parent 422601 a9029a587fec3ad8f2d2ea7586b4d54a7c3265e5
child 422603 3db186a5de7dbcf9d762b1dbcc54e9a5f8d7e057
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1384396
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1384396 - Add a @depends_all utility function; r=nalexander Often you only want to evaluate a function if all its dependencies are true. Expressing this in a "when" can be difficult. So let's add a convenience decorator for it. The existing code for @depends_if() was refactored to take an evaluation function as its first argument. This prevents some duplicate code and turns @depends_if() and @depends_all() into one-liners. MozReview-Commit-ID: Jbugvf0lioM
build/moz.configure/util.configure
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -399,33 +399,49 @@ def dependable(obj):
         return depends(when=True)(obj)
     return depends(when=True)(lambda: obj)
 
 
 always = dependable(True)
 never = dependable(False)
 
 
-# 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)
+# Create a decorator that will only execute the body of a function
+# if the passed function returns True when passed all positional
+# arguments.
 @template
-def depends_if(*args, **kwargs):
+def depends_tmpl(eval_args_fn, *args, **kwargs):
     if kwargs:
         assert len(kwargs) == 1
         when = kwargs['when']
     else:
         when = None
     def decorator(func):
         @depends(*args, when=when)
         def wrapper(*args):
-            if any(arg for arg in args):
+            if eval_args_fn(args):
                 return func(*args)
         return wrapper
     return decorator
 
+
+# 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, **kwargs):
+    return depends_tmpl(any, *args, **kwargs)
+
+
+# Like @depends, but the decorated function is only called if all of the
+# arguments it would be called with have a positive value.
+@template
+def depends_all(*args, **kwargs):
+    return depends_tmpl(all, *args, **kwargs)
+
+
 # Hacks related to old-configure
 # ==============================
 
 @dependable
 def old_configure_assignments():
     return []
 
 @dependable