Bug 1253203 - Use mozpath functions for sandboxed os.path in configure.py draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 04 Mar 2016 17:05:52 +0900
changeset 336854 b5ca43488b99bca70c200a658496d02f23931501
parent 336853 a986991a670200c38a9d7bf8b6c6797f8edc33ab
child 336855 e563b28c8fac6fc72b8e3915a2d36daba383d2a1
child 336857 9298a871652ffe50494db90e3c80da46bda5dfe3
child 336861 fcb4d0afaa447852d28a3165e5cbff5ed0c196b1
push id12192
push userbmo:mh+mozilla@glandium.org
push dateFri, 04 Mar 2016 08:13:32 +0000
bugs1253203
milestone47.0a1
Bug 1253203 - Use mozpath functions for sandboxed os.path in configure.py Generally speaking, the configuration needs forward-slashes in paths. We might as well make it hard(er) to set configuration items with backslash separators on Windows by exposing mozpath.* functions in place of os.path functions. The downside is that functions explicitly importing os will still get the real os.path functions.
python/mozbuild/mozbuild/configure/__init__.py
python/mozbuild/mozpack/path.py
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -90,27 +90,27 @@ class ConfigureSandbox(dict):
     BUILTINS = ReadOnlyDict({
         b: __builtins__[b]
         for b in ('None', 'False', 'True', 'int', 'bool', 'any', 'all', 'len',
                   'list', 'set', 'dict')
     }, __import__=forbidden_import)
 
     # Expose a limited set of functions from os.path
     OS = ReadOnlyNamespace(path=ReadOnlyNamespace(
-        abspath=os.path.abspath,
-        basename=os.path.basename,
-        dirname=os.path.dirname,
+        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=os.path.join,
-        normpath=os.path.normpath,
-        realpath=os.path.realpath,
-        relpath=os.path.relpath,
+        join=mozpath.join,
+        normpath=mozpath.normpath,
+        realpath=mozpath.realpath,
+        relpath=mozpath.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()
--- a/python/mozbuild/mozpack/path.py
+++ b/python/mozbuild/mozpack/path.py
@@ -25,16 +25,20 @@ def normsep(path):
     return path
 
 
 def relpath(path, start):
     rel = normsep(os.path.relpath(path, start))
     return '' if rel == '.' else rel
 
 
+def realpath(path):
+    return normsep(os.path.realpath(path))
+
+
 def abspath(path):
     return normsep(os.path.abspath(path))
 
 
 def join(*paths):
     return normsep(os.path.join(*paths))