Bug 1259683 - Miscellaneous small cleanups in the mozbuild.configure module. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 25 Mar 2016 11:46:57 +0900
changeset 290541 174b56d80f690f0d34c4ac19d2cc0a06a5a05266
parent 290540 3dcf36d71a610ea6f483f73750cf77702eefdd52
child 290542 e2fe62b540c6f41b67921e8479cb0f8adf83ce43
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Bug 1259683 - Miscellaneous small cleanups in the mozbuild.configure module. r=nalexander This is not related to the bug, but are drive-by cleanups.
--- 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._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
                 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]
@@ -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)
-            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[:-len('_impl')], getattr(self, k))
+            for k in dir(self) if k.endswith('_impl') and k != 'template_impl'
         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.