--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -80,29 +80,21 @@ class ConfigureSandbox(dict):
# The default set of builtins.
BUILTINS = ReadOnlyDict({
b: __builtins__[b]
for b in ('None', 'False', 'True', 'int', 'bool', 'any', 'all', 'len',
'list', 'tuple', 'set', 'dict', 'isinstance')
}, __import__=forbidden_import)
# Expose a limited set of functions from os.path
- OS = ReadOnlyNamespace(path=ReadOnlyNamespace(
- abspath=mozpath.abspath,
- basename=mozpath.basename,
- dirname=mozpath.dirname,
- exists=os.path.exists,
- isabs=os.path.isabs,
- isdir=os.path.isdir,
- isfile=os.path.isfile,
- join=mozpath.join,
- normpath=mozpath.normpath,
- realpath=mozpath.realpath,
- relpath=mozpath.relpath,
- ))
+ OS = ReadOnlyNamespace(path=ReadOnlyNamespace(**{
+ k: getattr(mozpath, k, getattr(os.path, k))
+ for k in ('abspath', 'basename', 'dirname', 'exists', 'isabs', 'isdir',
+ 'isfile', 'join', 'normpath', 'realpath', 'relpath')
+ }))
def __init__(self, config, environ=os.environ, argv=sys.argv,
stdout=sys.stdout, stderr=sys.stderr):
dict.__setitem__(self, '__builtins__', self.BUILTINS)
self._paths = []
self._templates = set()
# Store the real function and its dependencies, behind each
@@ -256,17 +248,17 @@ class ConfigureSandbox(dict):
"'%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._option_values[option] = value
self._raw_options[option] = (option_string.split('=', 1)[0]
- if option_string else option_string)
+ 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.
@@ -292,18 +284,16 @@ class ConfigureSandbox(dict):
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]
- if arg == self._help_option:
- with_help = True
self._seen.add(arg)
dependencies.append(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
dependencies.append(arg)
arg, _ = self._depends[arg]
@@ -359,22 +349,18 @@ class ConfigureSandbox(dict):
immediately. They are altered so that their global namespace exposes
a limited set of functions from os.path, as well as `advanced`,
`depends` and `option`.
Templates allow to simplify repetitive constructs, or to implement
helper decorators and somesuch.
'''
template, glob = self._prepare_function(func)
glob.update(
- advanced=self.advanced_impl,
- depends=self.depends_impl,
- option=self.option_impl,
- set_config=self.set_config_impl,
- set_define=self.set_define_impl,
- imply_option=self.imply_option_impl,
+ (k[:-5], getattr(self, k))
+ for k in dir(self) if k.endswith('_impl') and k != 'template_impl'
)
self._templates.add(template)
return template
def advanced_impl(self, func):
'''Implementation of @advanced.
This function gives the decorated function access to the complete set
of builtins, allowing the import keyword as an expected side effect.