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.
--- 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().