Bug 1802405 - Prepend mozillabuild msys2 to path only for the build. r=glandium

This reverts bug 1801826 and instead prepends the msys2 path only for
the build, which is a bit more sensible.

This allows us to remove the existing warning from old_configure, since
that can't happen now.

Differential Revision: https://phabricator.services.mozilla.com/D163073
This commit is contained in:
Emilio Cobos Álvarez 2022-11-26 23:23:34 +00:00
Родитель 280201b26e
Коммит de7acc6e32
5 изменённых файлов: 53 добавлений и 37 удалений

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

@ -116,11 +116,9 @@ def _maybe_activate_mozillabuild_environment():
paths_to_add = [mozillabuild_msys_tools_path, mozillabuild / "bin"]
existing_paths = [Path(p) for p in os.environ.get("PATH", "").split(os.pathsep)]
# It's important that we prepend to the path rather than append,
# in case mach is getting called from another msys2 environment.
for new_path in paths_to_add:
if new_path not in existing_paths:
os.environ["PATH"] = f"{new_path}{os.pathsep}" + os.environ["PATH"]
os.environ["PATH"] += f"{os.pathsep}{new_path}"
def initialize(topsrcdir):

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

@ -794,6 +794,12 @@ def target_is_windows(target):
return True
@depends(host)
def host_is_windows(host):
if host.kernel == "WINNT":
return True
set_define("_WINDOWS", target_is_windows)
set_define("WIN32", target_is_windows)
set_define("XP_WIN", target_is_windows)
@ -823,6 +829,12 @@ def target_is_osx(target):
return True
@depends(host)
def host_is_osx(host):
if host.os == "OSX":
return True
set_define("XP_MACOSX", target_is_osx)
@ -1120,6 +1132,23 @@ def mozbuild_state_path(path, _):
return normalize_path(os.path.expanduser(os.path.join("~", ".mozbuild")))
@depends("MOZILLABUILD", shell, host_is_windows)
@imports(_from="pathlib", _import="Path")
def mozillabuild_bin_paths(mozillabuild, shell, host_is_windows):
paths = []
if not mozillabuild or not host_is_windows:
return paths
paths.append(os.path.dirname(shell))
paths.append(str(Path(mozillabuild[0]) / "bin"))
return paths
@depends(mozillabuild_bin_paths)
@imports("os")
def prefer_mozillabuild_path(mozillabuild_bin_paths):
return mozillabuild_bin_paths + os.environ["PATH"].split(os.pathsep)
# A template providing a shorthand for setting a variable. The created
# option will only be settable with imply_option.
# It is expected that a project-specific moz.configure will call imply_option

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

@ -11,6 +11,7 @@ m4 = check_prog(
"gm4",
"m4",
),
paths=prefer_mozillabuild_path,
)
@ -121,11 +122,11 @@ def old_configure_for(old_configure_path, extra_env=None):
@depends(
prepare_configure,
prepare_configure_options,
prefer_mozillabuild_path,
altered_path,
extra_env,
build_environment,
old_configure_path,
"MOZILLABUILD",
awk,
m4,
shell,
@ -147,17 +148,23 @@ def old_configure_for(old_configure_path, extra_env=None):
def old_configure(
prepare_configure,
prepare_configure_options,
prefer_mozillabuild_path,
altered_path,
extra_env,
build_env,
old_configure,
mozillabuild,
awk,
m4,
shell,
):
# Use prepare_configure to make lint happy
prepare_configure
if altered_path:
path = altered_path
else:
path = os.pathsep.join(prefer_mozillabuild_path)
refresh = True
if os.path.exists(old_configure):
mtime = os.path.getmtime(old_configure)
@ -183,6 +190,7 @@ def old_configure_for(old_configure_path, extra_env=None):
env["M4"] = m4
env["AWK"] = awk
env["AC_MACRODIR"] = os.path.join(build_env.topsrcdir, "build", "autoconf")
env["PATH"] = path
try:
script = subprocess.check_output(
@ -199,17 +207,6 @@ def old_configure_for(old_configure_path, extra_env=None):
env=env,
)
except CalledProcessError as exc:
# Autoconf on win32 may break due to a bad $PATH. Let the user know
# their $PATH is suspect.
if mozillabuild:
mozillabuild_path = normsep(mozillabuild[0])
sh_path = normsep(find_program("sh"))
if mozillabuild_path not in sh_path:
log.warning(
"The '{}msys/bin' directory is not first in $PATH. "
"This may cause autoconf to fail. ($PATH is currently "
"set to: {})".format(mozillabuild_path, os.environ["PATH"])
)
die("autoconf exited with return code {}".format(exc.returncode))
if not script:
@ -259,8 +256,7 @@ def old_configure_for(old_configure_path, extra_env=None):
log_size = os.path.getsize(config_log.baseFilename)
break
if altered_path:
env["PATH"] = altered_path
env["PATH"] = path
if extra_env:
env.update(extra_env)

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

@ -68,12 +68,6 @@ with only_when(target_is_osx):
return value[0]
@depends(host)
def host_is_osx(host):
if host.os == "OSX":
return True
with only_when(host_is_osx | target_is_osx):
# MacOS SDK
# =========
@ -531,12 +525,6 @@ def get_vc_paths(topsrcdir):
yield (Version(install["installationVersion"]), tools_path)
@depends(host)
def host_is_windows(host):
if host.kernel == "WINNT":
return True
option(
"--with-visual-studio-version",
nargs=1,
@ -662,13 +650,17 @@ def rust_search_path(rust_path, search_order, original_path):
# As a workaround until bug 1516228 and bug 1516253 are fixed, set the PATH
# variable for the build to contain the toolchain search path.
@depends(vc_toolchain_search_path)
#
# FIXME(bug 1802573): The two bugs above are fixed, do we still need that?
#
# Prepend the mozilla-build msys2 path, since otherwise we can get mismatched
# cygwin dll errors during configure if we get called from another msys2
# environment, see bug 1801826.
@depends(mozillabuild_bin_paths, vc_toolchain_search_path)
@imports("os")
@imports(_from="os", _import="environ")
def altered_path(vc_toolchain_search_path):
path = environ["PATH"].split(os.pathsep)
altered_path = list(vc_toolchain_search_path)
for p in path:
def altered_path(mozillabuild_bin_paths, vc_toolchain_search_path):
altered_path = mozillabuild_bin_paths + list(vc_toolchain_search_path)
for p in os.environ["PATH"].split(os.pathsep):
if p not in altered_path:
altered_path.append(p)
return os.pathsep.join(altered_path)

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

@ -189,6 +189,7 @@ set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
include("build/moz.configure/bootstrap.configure")
# The execution model of the configure sandbox doesn't allow for
# check_prog to use bootstrap_search_path directly because check_prog
# comes first, so we use a trick to allow it. Uses of check_prog
@ -516,7 +517,7 @@ add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
# Awk detection
# ==============================================================
awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
# Until the AWK variable is not necessary in old-configure