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