Bug 1257823 - Split ConfigureSandbox._db
Currently, ConfigureSandbox._db stores two different kind of
information. This split those in two different instance variables
instead, making things clearer.
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -118,20 +118,20 @@ class ConfigureSandbox(dict):
self._paths = []
self._templates = set()
self._depends = {}
self._seen = set()
self._options = OrderedDict()
# Store the raw values returned by @depends functions
self._results = {}
- # Store several kind of information:
- # - value for each Option, as per returned by Option.get_value
- # - raw option (as per command line or environment) for each value
- self._db = {}
+ # Store values for each Option, as per returned by Option.get_value
+ self._option_values = {}
+ # Store raw option (as per command line or environment) for each Option
+ self._raw_options = {}
# Store options added with `imply_option`, and the reason they were
# added (which can either have been given to `imply_option`, or
# infered.
self._implied_options = {}
# Store all results from _prepare_function
self._prepared_functions = set()
@@ -141,17 +141,17 @@ class ConfigureSandbox(dict):
self._config, self._stdout, self._stderr = config, stdout, stderr
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._db[self._help_option]:
+ if self._option_values[self._help_option]:
self._help = HelpFormatter(argv[0])
self._help.add(self._help_option)
def exec_file(self, path):
'''Execute one file within the sandbox. Users of this class probably
want to use `run` instead.'''
if self._paths:
@@ -264,19 +264,19 @@ class ConfigureSandbox(dict):
func, reason = self._implied_options[e.arg]
raise InvalidOptionError(
"'%s' implied by '%s' conflicts with '%s' from the %s"
% (e.arg, reason, e.old_arg, e.old_origin))
if self._help:
self._help.add(option)
- self._db[option] = value
- self._db[value] = (option_string.split('=', 1)[0]
- if option_string else option_string)
+ self._option_values[option] = value
+ self._raw_options[option] = (option_string.split('=', 1)[0]
+ if option_string else option_string)
return option
def depends_impl(self, *args):
'''Implementation of @depends()
This function is a decorator. It returns a function that subsequently
takes a function and returns a dummy function. The dummy function
identifies the actual function for the sandbox, while preventing
further function calls from within the sandbox.
@@ -310,18 +310,18 @@ class ConfigureSandbox(dict):
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]
if arg == self._help_option:
with_help = True
self._seen.add(arg)
- assert arg in self._db or self._help
- resolved_arg = self._db.get(arg)
+ assert arg in self._option_values or self._help
+ resolved_arg = self._option_values.get(arg)
elif isinstance(arg, DummyFunction):
assert arg in self._depends
arg = self._depends[arg]
resolved_arg = self._results.get(arg)
else:
raise TypeError(
"Cannot use object of type '%s' as argument to @depends"
% type(arg))
@@ -360,17 +360,20 @@ class ConfigureSandbox(dict):
if not reason:
deps = []
for name, value in zip(args, resolved_args):
if not isinstance(value, OptionValue):
raise ConfigureError(
"Cannot infer what implied '%s'" % option)
if name == '--help':
continue
- deps.append(value.format(self._db.get(value) or name))
+ prefix, opt, values = Option.split_option(name)
+ deps.append(value.format(
+ self._raw_options.get(self._options[opt])
+ or name))
if len(deps) != 1:
raise ConfigureError(
"Cannot infer what implied '%s'" % option)
reason = deps[0]
self._implied_options[option] = func, reason
if not self._help: