Bug 1316956 - Add a when argument to check_prog. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Sat, 13 May 2017 07:12:56 +0900
changeset 577176 5a4313452aa74348fa1c654fedf40343d396b629
parent 576885 bacbf98fc81812fa190b80d03e92d1d85b0422be
child 628451 b2736ed078e097e6c53439b6b67c9b2ac797db1d
push id58638
push userbmo:mh+mozilla@glandium.org
push dateSat, 13 May 2017 00:27:37 +0000
reviewerschmanchester
bugs1316956
milestone55.0a1
Bug 1316956 - Add a when argument to check_prog. r?chmanchester
build/moz.configure/checks.configure
build/moz.configure/util.configure
--- a/build/moz.configure/checks.configure
+++ b/build/moz.configure/checks.configure
@@ -89,17 +89,17 @@ def checking(what, callback=None):
 # The simplest form is:
 #   check_prog('PROG', ('a', 'b'))
 # This will look for 'a' or 'b' in $PATH, and set_config PROG to the one
 # it can find. If PROG is already set from the environment or command line,
 # use that value instead.
 @template
 @imports(_from='mozbuild.shellutil', _import='quote')
 def check_prog(var, progs, what=None, input=None, allow_missing=False,
-               paths=None):
+               paths=None, when=None):
     if input is not None:
         # Wrap input with type checking and normalization.
         @depends(input)
         def input(value):
             if not value:
                 return
             if isinstance(value, str):
                 return (value,)
@@ -112,17 +112,17 @@ def check_prog(var, progs, what=None, in
                help='Path to %s' % (what or 'the %s program' % var.lower()))
         input = var
     what = what or var.lower()
 
     # Trick to make a @depends function out of an immediate value.
     progs = dependable(progs)
     paths = dependable(paths)
 
-    @depends_if(input, progs, paths)
+    @depends_if(input, progs, paths, when=when)
     @checking('for %s' % what, lambda x: quote(x) if x else 'not found')
     def check(value, progs, paths):
         if progs is None:
             progs = ()
 
         if not isinstance(progs, (tuple, list)):
             configure_error('progs must resolve to a list or tuple!')
 
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -385,19 +385,24 @@ def delayed_getattr(func, key):
         return getattr(value, key, None)
 
     return 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 depends_if(*args, **kwargs):
+    if kwargs:
+        assert len(kwargs) == 1
+        when = kwargs['when']
+    else:
+        when = None
     def decorator(func):
-        @depends(*args)
+        @depends(*args, when=when)
         def wrapper(*args):
             if any(arg for arg in args):
                 return func(*args)
         return wrapper
     return decorator
 
 # Hacks related to old-configure
 # ==============================