Bug 1256571 - Add a generic method to get the results of Options and DependsFunctions. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 08 Apr 2016 15:23:25 +0900
changeset 330981 22382dc2c9fabc77095c2bc1d2697e21d2e6dfef
parent 330980 9e2f69811b5251adee36d18b55cebe50c2977d2f
child 330982 f6dba01913b988c7797de8a3d81bec77b92f167a
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1256571
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1256571 - Add a generic method to get the results of Options and DependsFunctions. r=chmanchester instead of manually reading the member variable containing the results.
python/mozbuild/mozbuild/configure/__init__.py
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -159,19 +159,17 @@ class ConfigureSandbox(dict):
         }
         log_namespace['queue_debug'] = queue_debug
         self.log_impl = ReadOnlyNamespace(**log_namespace)
 
         self._help = None
         self._help_option = self.option_impl('--help',
                                              help='print this message')
         self._seen.add(self._help_option)
-        # self._option_impl('--help') will have set this if --help was on the
-        # command line.
-        if self._option_values[self._help_option]:
+        if self._value_for(self._help_option):
             self._help = HelpFormatter(argv[0])
             self._help.add(self._help_option)
         elif moz_logger:
             handler = logging.FileHandler('config.log', mode='w', delay=True)
             handler.setFormatter(formatter)
             logger.addHandler(handler)
 
     def exec_file(self, path):
@@ -251,25 +249,34 @@ class ConfigureSandbox(dict):
                            '@depends nor a @template' % key)
 
         return super(ConfigureSandbox, self).__setitem__(key, value)
 
     def _resolve(self, arg, need_help_dependency=True):
         if isinstance(arg, DependsFunction):
             assert arg in self._depends
             func, deps = self._depends[arg]
-            assert not inspect.isgeneratorfunction(func)
-            assert func in self._results
             if need_help_dependency and self._help_option not in deps:
                 raise ConfigureError("Missing @depends for `%s`: '--help'" %
                                      func.__name__)
-            result = self._results[func]
-            return result
+            return self._value_for(arg)
         return arg
 
+    def _value_for(self, obj):
+        if isinstance(obj, DependsFunction):
+            assert obj in self._depends
+            func, deps = self._depends[obj]
+            assert not inspect.isgeneratorfunction(func)
+            assert func in self._results
+            return self._results[func]
+        elif isinstance(obj, Option):
+            assert obj in self._option_values
+            return self._option_values.get(obj)
+        assert False
+
     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.
@@ -359,25 +366,17 @@ class ConfigureSandbox(dict):
                         _, deps = self._depends[arg]
                         if self._help_option not in deps:
                             raise ConfigureError(
                                 "`%s` depends on '--help' and `%s`. "
                                 "`%s` must depend on '--help'"
                                 % (func.__name__, arg.__name__, arg.__name__))
 
             if not self._help or with_help:
-                resolved_args = []
-                for arg in dependencies:
-                    if isinstance(arg, Option):
-                        assert arg in self._option_values
-                        resolved_args.append(self._option_values.get(arg))
-                    elif isinstance(arg, DependsFunction):
-                        arg, _ = self._depends[arg]
-                        resolved_args.append(self._results.get(arg))
-
+                resolved_args = [self._value_for(d) for d in dependencies]
                 self._results[func] = func(*resolved_args)
 
             return dummy
 
         return decorator
 
     def include_impl(self, what):
         '''Implementation of include().