Bug 1296530 - Move @depends dependency resolution to a separate function. r?chmanchester
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -398,16 +398,37 @@ class ConfigureSandbox(dict):
"'%s' implied by '%s' conflicts with '%s' from the %s"
% (e.arg, reason, e.old_arg, e.old_origin))
if option_string:
self._raw_options[option] = option_string
return value
+ def _dependency(self, arg, callee_name, arg_name=None):
+ if isinstance(arg, types.StringTypes):
+ prefix, name, values = Option.split_option(arg)
+ if values != ():
+ raise ConfigureError("Option must not contain an '='")
+ if name not in self._options:
+ raise ConfigureError("'%s' is not a known option. "
+ "Maybe it's declared too late?"
+ % arg)
+ arg = self._options[name]
+ self._seen.add(arg)
+ elif isinstance(arg, SandboxDependsFunction):
+ assert arg in self._depends
+ arg = self._depends[arg]
+ else:
+ raise TypeError(
+ "Cannot use object of type '%s' as %sargument to %s"
+ % (type(arg).__name__, '`%s` ' % arg_name if arg_name else '',
+ callee_name))
+ return arg
+
def option_impl(self, *args, **kwargs):
'''Implementation of option()
This function creates and returns an Option() object, passing it the
resolved arguments (uses the result of functions when functions are
passed). In most cases, the result of this function is not expected to
be used.
Command line argument/environment variable parsing for this Option is
handled here.
@@ -445,38 +466,17 @@ class ConfigureSandbox(dict):
The decorated function is altered to use a different global namespace
for its execution. This different global namespace exposes a limited
set of functions from os.path.
'''
if not args:
raise ConfigureError('@depends needs at least one argument')
- dependencies = []
- for arg in args:
- if isinstance(arg, types.StringTypes):
- prefix, name, values = Option.split_option(arg)
- if values != ():
- raise ConfigureError("Option must not contain an '='")
- if name not in self._options:
- raise ConfigureError("'%s' is not a known option. "
- "Maybe it's declared too late?"
- % arg)
- arg = self._options[name]
- self._seen.add(arg)
- dependencies.append(arg)
- elif isinstance(arg, SandboxDependsFunction):
- assert arg in self._depends
- arg = self._depends[arg]
- dependencies.append(arg)
- else:
- raise TypeError(
- "Cannot use object of type '%s' as argument to @depends"
- % type(arg).__name__)
- dependencies = tuple(dependencies)
+ dependencies = tuple(self._dependency(arg, '@depends') for arg in args)
def decorator(func):
if inspect.isgeneratorfunction(func):
raise ConfigureError(
'Cannot decorate generator functions with @depends')
func, glob = self._prepare_function(func)
depends = DependsFunction(self, func, dependencies)