Bug 1293579 - Add a `dependable` function/decorator to avoid some of the depends('--help') weirdness in python configure. r?chmanchester
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -297,16 +297,34 @@ def deprecated_option(*args, **kwargs):
# from mozbuild.util import ReadOnlyNamespace as namespace
@imports(_from='mozbuild.util', _import='ReadOnlyNamespace')
def namespace(**kwargs):
return ReadOnlyNamespace(**kwargs)
+# Turn an object into an object that can be used as an argument to @depends.
+# The given object can be a literal value, a function that takes no argument,
+# or, for convenience, a @depends function.
+@template
+@imports(_from='inspect', _import='isfunction')
+@imports(_from='mozbuild.configure', _import='DependsFunction')
+def dependable(obj):
+ if isinstance(obj, DependsFunction):
+ return obj
+ if isfunction(obj):
+ return depends('--help')(lambda _: obj())
+ return depends('--help')(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)