Bug 1752004 - Remove usage of six in python configure. r=firefox-build-system-reviewers,mhentges

Differential Revision: https://phabricator.services.mozilla.com/D136946
This commit is contained in:
Mike Hommey 2022-01-25 21:38:47 +00:00
Родитель 3b3794ffe3
Коммит 77ef469247
6 изменённых файлов: 15 добавлений и 34 удалений

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

@ -160,11 +160,8 @@ add_old_configure_assignment("PYTHON3", virtualenv_python3.path)
def early_options():
@depends("--help")
@imports("__sandbox__")
@imports(_from="six", _import="itervalues")
def early_options(_):
return set(
option.env for option in itervalues(__sandbox__._options) if option.env
)
return set(option.env for option in __sandbox__._options.values() if option.env)
return early_options
@ -176,7 +173,6 @@ early_options = early_options()
# This gives access to the sandbox. Don't copy this blindly.
@imports("__sandbox__")
@imports("os")
@imports("six")
def mozconfig_options(mozconfig, early_options, automation, help):
if mozconfig["path"]:
if "MOZ_AUTOMATION_MOZCONFIG" in mozconfig["env"]["added"]:
@ -207,15 +203,15 @@ def mozconfig_options(mozconfig, early_options, automation, help):
if key not in early_options:
helper.add(arg, origin="mozconfig", args=helper._args)
for key, value in six.iteritems(mozconfig["env"]["added"]):
for key, value in mozconfig["env"]["added"].items():
add(key, value)
os.environ[key] = value
for key, (_, value) in six.iteritems(mozconfig["env"]["modified"]):
for key, (_, value) in mozconfig["env"]["modified"].items():
add(key, value)
os.environ[key] = value
for key, value in six.iteritems(mozconfig["vars"]["added"]):
for key, value in mozconfig["vars"]["added"].items():
add(key, value)
for key, (_, value) in six.iteritems(mozconfig["vars"]["modified"]):
for key, (_, value) in mozconfig["vars"]["modified"].items():
add(key, value)

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

@ -147,9 +147,7 @@ def old_configure_for(old_configure_path, extra_env=None):
@imports(_from="mozbuild.shellutil", _import="split")
@imports(_from="tempfile", _import="NamedTemporaryFile")
@imports(_from="subprocess", _import="CalledProcessError")
@imports(_from="six", _import="exec_")
@imports(_from="six", _import="iteritems")
@imports(_from="six", _import="string_types")
@imports(_from="__builtin__", _import="exec")
def old_configure(
prepare_configure,
prepare_configure_options,
@ -306,7 +304,7 @@ def old_configure_for(old_configure_path, extra_env=None):
}
with open("config.data", "r") as fh:
code = compile(fh.read(), "config.data", "exec")
exec_(code, raw_config)
exec(code, raw_config)
# Ensure all the flags known to old-configure appear in the
# @old_configure_options above.
@ -326,7 +324,7 @@ def old_configure_for(old_configure_path, extra_env=None):
return namespace(
**{
c: [
(k[1:-1], v[1:-1] if isinstance(v, string_types) else v)
(k[1:-1], v[1:-1] if isinstance(v, str) else v)
for k, v in raw_config[c]
]
for c in ("substs", "defines")

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

@ -405,7 +405,6 @@ def detect_rustc_target(
@imports("os")
@imports(_from="six", _import="ensure_binary")
@imports(_from="tempfile", _import="mkstemp")
@imports(_from="textwrap", _import="dedent")
@imports(_from="mozbuild.configure.util", _import="LineIO")
@ -417,12 +416,12 @@ def assert_rust_compile(host_or_target, rustc_target, rustc):
out_fd, out_path = mkstemp(prefix="conftest", suffix=".rlib")
os.close(out_fd)
try:
source = 'pub extern fn hello() { println!("Hello world"); }'
source = b'pub extern fn hello() { println!("Hello world"); }'
log.debug("Creating `%s` with content:", in_path)
with LineIO(lambda l: log.debug("| %s", l)) as out:
out.write(source)
os.write(in_fd, ensure_binary(source))
os.write(in_fd, source)
os.close(in_fd)
cmd = [

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

@ -225,7 +225,6 @@ def try_preprocess(compiler, language, source, onerror=None):
@imports(_from="mozbuild.configure.constants", _import="CPU_preprocessor_checks")
@imports(_from="mozbuild.configure.constants", _import="kernel_preprocessor_checks")
@imports(_from="mozbuild.configure.constants", _import="OS_preprocessor_checks")
@imports(_from="six", _import="iteritems")
@imports(_from="textwrap", _import="dedent")
@imports(_from="__builtin__", _import="Exception")
def get_compiler_info(compiler, language):
@ -274,7 +273,7 @@ def get_compiler_info(compiler, language):
("KERNEL", kernel_preprocessor_checks),
("OS", OS_preprocessor_checks),
):
for n, (value, condition) in enumerate(iteritems(preprocessor_checks)):
for n, (value, condition) in enumerate(preprocessor_checks.items()):
check += dedent(
"""\
#%(if)s %(condition)s

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

@ -23,7 +23,6 @@ def configure_error(message):
# A wrapper to obtain a process' output and return code.
# Returns a tuple (retcode, stdout, stderr).
@imports("os")
@imports("six")
@imports("subprocess")
@imports(_from="mozbuild.shellutil", _import="quote")
@imports(_from="mozbuild.util", _import="system_encoding")
@ -37,19 +36,11 @@ def get_cmd_output(*args, **kwargs):
# stdout/stderr. Elsewhere, it simply prevents it from inheriting extra
# file descriptors, which is what we want.
close_fds=os.name != "nt",
encoding=system_encoding,
errors="replace",
**kwargs
)
stdout, stderr = proc.communicate()
# Normally we would set the `encoding` and `errors` arguments in the
# constructor to subprocess.Popen, but those arguments were added in 3.6
# and we need to support back to 3.5, so instead we need to do this
# nonsense.
stdout = six.ensure_text(
stdout, encoding=system_encoding, errors="replace"
).replace("\r\n", "\n")
stderr = six.ensure_text(
stderr, encoding=system_encoding, errors="replace"
).replace("\r\n", "\n")
return proc.wait(), stdout, stderr
@ -209,7 +200,6 @@ def find_program(file, paths=None):
@imports("os")
@imports(_from="mozbuild.configure.util", _import="LineIO")
@imports(_from="six", _import="ensure_binary")
@imports(_from="tempfile", _import="mkstemp")
def try_invoke_compiler(compiler, language, source, flags=None, onerror=None):
flags = flags or []
@ -230,7 +220,7 @@ def try_invoke_compiler(compiler, language, source, flags=None, onerror=None):
with LineIO(lambda l: log.debug("| %s", l)) as out:
out.write(source)
os.write(fd, ensure_binary(source))
os.write(fd, source)
os.close(fd)
cmd = compiler + [path] + list(flags)
kwargs = {"onerror": onerror}

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

@ -10,12 +10,11 @@
@imports(_from="mozbuild.shellutil", _import="quote")
@imports(_from="mozbuild.util", _import="ensure_unicode")
@imports(_from="mozbuild.util", _import="system_encoding")
@imports(_from="six", _import="itervalues")
@imports("__sandbox__")
def all_configure_options():
result = []
previous = None
for option in itervalues(__sandbox__._options):
for option in __sandbox__._options.values():
# __sandbox__._options contains items for both option.name and
# option.env. But it's also an OrderedDict, meaning both are
# consecutive.