Remove --help dependencies from @dependable and delayed_getattr. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 27 Oct 2016 15:00:51 +0900
changeset 430141 eb80d8ed583490bb2586dd361f87da5607f6cc4d
parent 430140 1e464cd81202fdde0743fd8d8a6682060ea98839
child 535134 6550af4536396275e77f0a9beb58600c7e2835a7
push id33749
push userbmo:mh+mozilla@glandium.org
push dateThu, 27 Oct 2016 07:42:00 +0000
reviewerschmanchester
milestone52.0a1
Remove --help dependencies from @dependable and delayed_getattr. r?chmanchester This sadly requires to replace a few @dependendable to pass the lint check.
build/moz.configure/android-ndk.configure
build/moz.configure/init.configure
build/moz.configure/util.configure
moz.configure
--- a/build/moz.configure/android-ndk.configure
+++ b/build/moz.configure/android-ndk.configure
@@ -9,17 +9,17 @@ js_option('--with-android-ndk', nargs=1,
           help='location where the Android NDK can be found')
 
 js_option('--with-android-toolchain', nargs=1,
           help='location of the Android toolchain')
 
 js_option('--with-android-gnu-compiler-version', nargs=1,
           help='GNU compiler version to use')
 
-min_android_version = dependable('9')
+min_android_version = dependable(lambda: '9')
 
 js_option('--with-android-version',
           nargs=1,
           help='android platform version',
           default=min_android_version)
 
 @depends('--with-android-version', min_android_version)
 @imports(_from='__builtin__', _import='ValueError')
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -808,11 +808,11 @@ def js_option(*args, **kwargs):
     add_old_configure_arg(js_option)
 
 
 # Bug 1278542: This function is a workaround to resolve
 # |android_ndk_include|'s dependency on 'gonkdir.' The
 # actual implementation is located in b2g/moz.configure.
 # Remove this function as soon as 'android_ndk_include'
 # depends on 'target.'
-@dependable
-def gonkdir():
+@depends('--help')
+def gonkdir(_):
     return None
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -333,51 +333,43 @@ def namespace(**kwargs):
 # or, for convenience, a @depends function.
 @template
 @imports(_from='inspect', _import='isfunction')
 @imports(_from='mozbuild.configure', _import='SandboxDependsFunction')
 def dependable(obj):
     if isinstance(obj, SandboxDependsFunction):
         return obj
     if isfunction(obj):
-        return depends('--help')(lambda _: obj())
-    return depends('--help')(lambda _: obj)
+        return depends(when=True)(obj)
+    return depends(when=True)(lambda: obj)
 
 
 always = dependable(True)
 never = dependable(False)
 
 
 # Some @depends function return namespaces, and one could want to use one
 # specific attribute from such a namespace as a "value" given to functions
 # such as `set_config`. But those functions do not take immediate values.
 # The `delayed_getattr` function allows access to attributes from the result
 # of a @depends function in a non-immediate manner.
 #   @depends('--option')
 #   def option(value)
 #       return namespace(foo=value)
 #   set_config('FOO', delayed_getattr(option, 'foo')
 @template
-@imports('__sandbox__')
 def delayed_getattr(func, key):
-    deps = __sandbox__._depends.get(func, ())
-    if deps:
-        deps = deps.sandboxed_dependencies
-
-    def result(value, _=None):
+    @depends(func)
+    def result(value):
         # The @depends function we're being passed may have returned
         # None, or an object that simply doesn't have the wanted key.
         # In that case, just return None.
         return getattr(value, key, None)
 
-    # Automatically add a dependency on --help when the given @depends
-    # function itself depends on --help.
-    if __sandbox__._help_option in deps:
-        return depends(func, '--help')(result)
-    return depends(func)(result)
+    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 decorator(func):
         @depends(*args)
--- a/moz.configure
+++ b/moz.configure
@@ -114,19 +114,19 @@ include('build/moz.configure/memory.conf
         when='--enable-compile-environment')
 include('build/moz.configure/headers.configure',
         when='--enable-compile-environment')
 include('build/moz.configure/warnings.configure',
         when='--enable-compile-environment')
 
 include(include_project_configure)
 
-@dependable
+@depends('--help')
 @imports(_from='mozbuild.backend', _import='backends')
-def build_backends_choices():
+def build_backends_choices(_):
     return tuple(backends)
 
 
 @deprecated_option('--enable-build-backend', nargs='+',
                    choices=build_backends_choices)
 def build_backend(backends):
     if backends:
         return tuple('+%s' % b for b in backends)