Bug 1374727 - Apply check_prog's `when` to more of what it "expands" to. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 21 Jun 2017 07:19:33 +0900
changeset 597748 b45715e494b45406e94eeefcdab45211d3130883
parent 597455 464b2a3c25aa1065760d9ecbb0870bca4a66c62e
child 634307 532d98095fda407fab5f7e09232b1c53165cdc6b
push id65015
push userbmo:mh+mozilla@glandium.org
push dateTue, 20 Jun 2017 22:30:22 +0000
reviewerschmanchester
bugs1374727
milestone56.0a1
Bug 1374727 - Apply check_prog's `when` to more of what it "expands" to. r?chmanchester check_prog, when used with a `when` argument, doesn't work the same way as putting it under a `with only_when()` block, while it should. The difference comes from the fact that `with only_when()` applies the `when` to every option and depends used in the block (which check_prog calls a bunch of). So, we "manually" apply the `when` to all option and depends in check_prog. An alternative solution would be to put the whole function under a `with only_when()` block, but that would mean reindenting the whole function. Either way, as a consequence, this requires the `when` to have a dependency on --help for "non-trivial" functions, which fortunately, there's only one of.
build/moz.configure/checks.configure
toolkit/moz.configure
--- a/build/moz.configure/checks.configure
+++ b/build/moz.configure/checks.configure
@@ -92,28 +92,28 @@ def checking(what, callback=None):
 # 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, when=None):
     if input is not None:
         # Wrap input with type checking and normalization.
-        @depends(input)
+        @depends(input, when=when)
         def input(value):
             if not value:
                 return
             if isinstance(value, str):
                 return (value,)
             if isinstance(value, (tuple, list)) and len(value) == 1:
                 return value
             configure_error('input must resolve to a tuple or a list with a '
                             'single element, or a string')
     else:
-        option(env=var, nargs=1,
+        option(env=var, nargs=1, when=when,
                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)
 
@@ -130,15 +130,15 @@ def check_prog(var, progs, what=None, in
             log.debug('%s: Trying %s', var.lower(), quote(prog))
             result = find_program(prog, paths)
             if result:
                 return result
 
         if not allow_missing or value:
             raise FatalCheckError('Cannot find %s' % what)
 
-    @depends_if(check, progs)
+    @depends_if(check, progs, when=when)
     def normalized_for_config(value, progs):
         return ':' if value is None else value
 
     set_config(var, normalized_for_config)
 
     return check
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -618,18 +618,18 @@ simple_keyfile('Adjust SDK')
 
 id_and_secret_keyfile('Leanplum SDK')
 
 # Servo integration
 # ==============================================================
 option('--enable-stylo', nargs='?', choices=('build',),
        help='Include Stylo in the build and/or enable it at runtime')
 
-@depends('--enable-stylo')
-def stylo_config(value):
+@depends('--enable-stylo', '--help')
+def stylo_config(value, _):
     build_stylo = None
     enable_stylo = None
 
     # The default is to not build Stylo at all.
     if value.origin == 'default':
         pass
     elif value == 'build':
         build_stylo = True