Bug 1748383 - In configure, make e.g. os.path.join mean the same thing whether importing os or not. r=firefox-build-system-reviewers,mhentges

Currently, using any of the functions defined in
`ConfigureSandbox.OS.path` in a `@depends` function will have a different
behavior if the function has an `@imports("os")` or not. In the former
case, we get plain `os.path.$function`, while in the latter we get the
function from `ConfigureSandbox.OS.path`, which handles path separators
differently, which makes a significant difference on Windows.

With this change, we now consistently use the versions from
`ConfigureSandbox.OS.path`.

Differential Revision: https://phabricator.services.mozilla.com/D135003
This commit is contained in:
Mike Hommey 2022-01-05 01:34:35 +00:00
Родитель 1fe66a3272
Коммит de0df1009a
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -1004,6 +1004,11 @@ class ConfigureSandbox(dict):
# Special case os and os.environ so that os.environ is our copy of
# the environment.
wrapped_os["environ"] = self._environ
# Also override some os.path functions with ours.
wrapped_path = {}
exec_("from os.path import *", {}, wrapped_path)
wrapped_path.update(self.OS.path.__dict__)
wrapped_os["path"] = ReadOnlyNamespace(**wrapped_path)
return ReadOnlyNamespace(**wrapped_os)
@memoized_property

Просмотреть файл

@ -278,6 +278,12 @@ class TestConfigure(unittest.TestCase):
self.assertIs(sandbox["foo"](), sys)
# os.path after an import is a mix of vanilla os.path and sandbox os.path.
os_path = {}
exec_("from os.path import *", {}, os_path)
os_path.update(sandbox.OS.path.__dict__)
os_path = ReadOnlyNamespace(**os_path)
exec_(
textwrap.dedent(
"""
@ -289,7 +295,7 @@ class TestConfigure(unittest.TestCase):
sandbox,
)
self.assertIs(sandbox["foo"](), os.path)
self.assertEquals(sandbox["foo"](), os_path)
exec_(
textwrap.dedent(
@ -302,7 +308,7 @@ class TestConfigure(unittest.TestCase):
sandbox,
)
self.assertIs(sandbox["foo"](), os.path)
self.assertEquals(sandbox["foo"](), os_path)
exec_(
textwrap.dedent(