Bug 1686646 - Use more targeted search paths for each tool. r=firefox-build-system-reviewers,dmajor

Instead of adding all possible tool paths from ~/.mozbuild, we only
add the relevant paths for each of the tools we search for.

Differential Revision: https://phabricator.services.mozilla.com/D101718
This commit is contained in:
Mike Hommey 2021-01-15 04:26:05 +00:00
Родитель de6099304e
Коммит 8362a57bed
6 изменённых файлов: 70 добавлений и 74 удалений

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

@ -47,16 +47,21 @@ def check_cbindgen_version(cbindgen, fatal=False):
)
@depends_if("CBINDGEN", toolchain_search_path, when=cbindgen_is_needed)
@depends_if(
"CBINDGEN",
bootstrap_search_path("cbindgen"),
rust_search_path,
when=cbindgen_is_needed,
)
@checking("for cbindgen")
@imports(_from="textwrap", _import="dedent")
def cbindgen(cbindgen_override, toolchain_search_path):
def cbindgen(cbindgen_override, bootstrap_search_path, rust_search_path):
if cbindgen_override:
check_cbindgen_version(cbindgen_override[0], fatal=True)
return cbindgen_override[0]
candidates = []
for path in toolchain_search_path:
for path in bootstrap_search_path + rust_search_path:
candidate = find_program("cbindgen", [path])
if not candidate:
continue
@ -107,13 +112,13 @@ option(
"--with-clang-path",
c_compiler,
cxx_compiler,
toolchain_search_path,
clang_search_path,
target,
macos_sdk,
)
@checking("for clang for bindgen", lambda x: x.path if x else "not found")
def bindgen_clang_compiler(
clang_path, c_compiler, cxx_compiler, toolchain_search_path, target, macos_sdk
clang_path, c_compiler, cxx_compiler, clang_search_path, target, macos_sdk
):
# When the target compiler is clang, use that, including flags.
if cxx_compiler.type == "clang":
@ -143,7 +148,7 @@ def bindgen_clang_compiler(
clang_path = [os.path.join(os.path.dirname(cxx_compiler.compiler), "clang")]
clang_path = find_program(
clang_path[0] if clang_path else "clang++", toolchain_search_path
clang_path[0] if clang_path else "clang++", clang_search_path
)
if not clang_path:
return

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

@ -7,7 +7,7 @@
# PGO
# ==============================================================
llvm_profdata = check_prog(
"LLVM_PROFDATA", ["llvm-profdata"], allow_missing=True, paths=toolchain_search_path
"LLVM_PROFDATA", ["llvm-profdata"], allow_missing=True, paths=clang_search_path
)
option(

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

@ -636,13 +636,6 @@ def vc_compiler_path(target, paths):
return paths.get(vc_target)
@dependable
@imports("os")
@imports(_from="os", _import="environ")
def original_path():
return environ["PATH"].split(os.pathsep)
@depends(vc_compiler_path, original_path)
@imports("os")
@imports(_from="os", _import="environ")
@ -661,50 +654,7 @@ def vc_toolchain_search_path(vc_compiler_path, original_path):
return result
@depends(
original_path,
developer_options,
mozbuild_state_path,
)
@imports("os")
@imports(_from="os", _import="environ")
def toolchain_search_path(
original_path,
developer_options,
mozbuild_state_path,
):
result = list(original_path)
# Add in the location to which `mach bootstrap` or
# `mach artifact toolchain` installs clang, cbindgen, etc.
bootstrapped = [
os.path.join(mozbuild_state_path, *rest)
for rest in (
["clang", "bin"],
["cbindgen"],
["dump_syms"],
["nasm"],
["lucetc"],
["sccache"],
)
]
if developer_options:
log.debug(
"Prioritizing mozbuild state dir in toolchain path because "
"you are not building in release mode."
)
search_path = bootstrapped + result
else:
log.debug(
"Prioritizing system over mozbuild state dir in "
"toolchain path because you are building in "
"release mode."
)
search_path = result + bootstrapped
log.debug("Search path for toolchain: {}".format(search_path))
return search_path
clang_search_path = bootstrap_search_path("clang", "bin")
@depends(original_path)
@ -712,7 +662,6 @@ def toolchain_search_path(
@imports(_from="os", _import="environ")
def rust_search_path(original_path):
result = list(original_path)
# Also add the rustup install directory for cargo/rustc.
cargo_home = environ.get("CARGO_HOME", "")
if cargo_home:
@ -763,7 +712,11 @@ def ccache(value):
ccache = check_prog(
"CCACHE", progs=(), input=ccache, paths=toolchain_search_path, allow_missing=True
"CCACHE",
progs=(),
input=ccache,
paths=bootstrap_search_path("sccache"),
allow_missing=True,
)
option(env="CCACHE_PREFIX", nargs=1, help="Compiler prefix to use when using ccache")
@ -1072,7 +1025,7 @@ def compiler(
what=what,
progs=default_compilers,
input=provided_compiler.program,
paths=toolchain_search_path,
paths=clang_search_path,
)
@depends(compiler, provided_compiler, compiler_wrapper, host_or_target, macos_sdk)
@ -1970,7 +1923,9 @@ set_config("MOZ_FRAMEPTR_FLAGS", frame_pointer_flags)
# nasm detection
# ==============================================================
nasm = check_prog("NASM", ["nasm"], allow_missing=True, paths=toolchain_search_path)
nasm = check_prog(
"NASM", ["nasm"], allow_missing=True, paths=bootstrap_search_path("nasm")
)
@depends_if(nasm)
@ -2589,7 +2544,7 @@ llvm_config = check_prog(
llvm_config,
what="llvm-config",
when="--enable-clang-plugin",
paths=toolchain_search_path,
paths=clang_search_path,
)
add_old_configure_assignment("LLVM_CONFIG", llvm_config)
@ -2826,7 +2781,7 @@ def rc_names(c_compiler, toolchain_prefix):
return ("llvm-rc",)
check_prog("RC", rc_names, paths=toolchain_search_path, when=target_is_windows)
check_prog("RC", rc_names, paths=clang_search_path, when=target_is_windows)
@depends(toolchain_prefix, c_compiler)
@ -2855,7 +2810,7 @@ def ar_config(toolchain_prefix, c_compiler):
)
ar = check_prog("AR", ar_config.names, paths=toolchain_search_path)
ar = check_prog("AR", ar_config.names, paths=clang_search_path)
add_old_configure_assignment("AR", ar)
@ -2879,7 +2834,7 @@ def nm_names(toolchain_prefix, c_compiler):
return names
check_prog("NM", nm_names, paths=toolchain_search_path, when=target_is_linux)
check_prog("NM", nm_names, paths=clang_search_path, when=target_is_linux)
option("--enable-cpp-rtti", help="Enable C++ RTTI")

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

@ -519,7 +519,7 @@ link = check_prog(
("lld-link",),
input="LINKER",
when=target_is_windows,
paths=toolchain_search_path,
paths=clang_search_path,
)
option(env="HOST_LINKER", nargs=1, when=host_is_windows, help="Path to the host linker")
@ -529,7 +529,7 @@ host_link = check_prog(
("lld-link",),
input="HOST_LINKER",
when=host_is_windows,
paths=toolchain_search_path,
paths=clang_search_path,
)
add_old_configure_assignment("LINKER", link)

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

@ -194,6 +194,42 @@ add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
set_config("DEVELOPER_OPTIONS", developer_options)
@depends(developer_options)
def bootstrap_search_path_order(developer_options):
if developer_options:
log.debug(
"Prioritizing mozbuild state dir in toolchain paths because "
"you are not building in release mode."
)
return "prepend"
log.debug(
"Prioritizing system over mozbuild state dir in "
"toolchain paths because you are building in "
"release mode."
)
return "append"
@dependable
@imports("os")
@imports(_from="os", _import="environ")
def original_path():
return environ["PATH"].split(os.pathsep)
@template
def bootstrap_search_path(*path_parts):
@depends(bootstrap_search_path_order, original_path, mozbuild_state_path)
def bootstrap_search_path(order, original_path, mozbuild_state_path):
path = [os.path.join(mozbuild_state_path, *path_parts)]
if order == "prepend":
return path + original_path
return original_path + path
return bootstrap_search_path
wine = check_prog(
"WINE",
["wine64", "wine"],
@ -769,7 +805,7 @@ llvm_objdump = check_prog(
llvm_objdump,
what="llvm-objdump",
when="--enable-compile-environment",
paths=toolchain_search_path,
paths=clang_search_path,
)
add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)

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

@ -1520,7 +1520,7 @@ llvm_dlltool = check_prog(
("llvm-dlltool",),
what="llvm-dlltool",
when=check_for_llvm_dlltool,
paths=toolchain_search_path,
paths=clang_search_path,
)
@ -2067,7 +2067,7 @@ set_config("MOZ_USING_WASM_SANDBOXING", requires_wasm_sandboxing)
set_define("MOZ_USING_WASM_SANDBOXING", requires_wasm_sandboxing)
with only_when(requires_wasm_sandboxing & compile_environment):
lucetc = check_prog("LUCETC", ["lucetc"], paths=toolchain_search_path)
lucetc = check_prog("LUCETC", ["lucetc"], paths=bootstrap_search_path("lucetc"))
option(
"--with-wasi-sysroot",
@ -2126,7 +2126,7 @@ with only_when(requires_wasm_sandboxing & compile_environment):
"_WASM_CC",
["clang"],
input=provided_wasm_cc.program,
paths=toolchain_search_path,
paths=clang_search_path,
allow_missing=True,
what="the C->WASM compiler",
)
@ -2145,7 +2145,7 @@ with only_when(requires_wasm_sandboxing & compile_environment):
"_WASM_CXX",
["clang++"],
input=provided_wasm_cxx.program,
paths=toolchain_search_path,
paths=clang_search_path,
allow_missing=True,
what="the C++->WASM compiler",
)
@ -2317,7 +2317,7 @@ check_prog(
"DUMP_SYMS",
["dump_syms"],
allow_missing=True,
paths=toolchain_search_path,
paths=bootstrap_search_path("dump_syms"),
when=compile_environment,
)