Bug 1296530 - Move @depends dependency resolution to a separate function. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 11 Oct 2016 08:42:17 +0900
changeset 425032 c6be6a83b7440ccffe020d57165b1c6b1483c037
parent 425031 b5cd447e7b0a129bc83f69d306ff4aa16e132991
child 425033 e8c8ddfb166ecf0f080be3896d7975e210a2cb27
push id32321
push userbmo:mh+mozilla@glandium.org
push dateFri, 14 Oct 2016 02:53:47 +0000
reviewerschmanchester
bugs1296530
milestone52.0a1
Bug 1296530 - Move @depends dependency resolution to a separate function. r?chmanchester
python/mozbuild/mozbuild/configure/__init__.py
--- 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)