From 2b181156c893843266c2825098360db2364dbd23 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 5 Mar 2021 10:21:12 +0000 Subject: [PATCH] tools/build/make.py: Avoid calling brew --prefix on macOS unnecessarily If all the require variables (XCC/XCXX/XCPP/XLD) are already set in the environment, we don't have to infer a default value for the cross toolchain path. This avoids an additional `brew --prefix` call when building with cheribuild (since it already sets all these variables). --- tools/build/make.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/build/make.py b/tools/build/make.py index c34147f6ac21..0cf831a3c966 100755 --- a/tools/build/make.py +++ b/tools/build/make.py @@ -119,6 +119,15 @@ def check_required_make_env_var(varname, binary_name, bindir): if parsed_args.debug: run([guess, "--version"]) +def check_xtool_make_env_var(varname, binary_name): + # Avoid calling brew --prefix on macOS if all variables are already set: + if os.getenv(varname): + return + global parsed_args + if parsed_args.cross_bindir is None: + parsed_args.cross_bindir = default_cross_toolchain() + return check_required_make_env_var(varname, binary_name, + parsed_args.cross_bindir) def default_cross_toolchain(): # default to homebrew-installed clang on MacOS if available @@ -170,8 +179,6 @@ def default_cross_toolchain(): except ImportError: pass parsed_args, bmake_args = parser.parse_known_args() - if parsed_args.cross_bindir is None: - parsed_args.cross_bindir = default_cross_toolchain() MAKEOBJDIRPREFIX = os.getenv("MAKEOBJDIRPREFIX") if not MAKEOBJDIRPREFIX: @@ -209,16 +216,11 @@ def default_cross_toolchain(): # On non-FreeBSD we need to explicitly pass XCC/XLD/X_COMPILER_TYPE use_cross_gcc = parsed_args.cross_compiler_type == "gcc" - check_required_make_env_var("XCC", "gcc" if use_cross_gcc else "clang", - parsed_args.cross_bindir) - check_required_make_env_var("XCXX", - "g++" if use_cross_gcc else "clang++", - parsed_args.cross_bindir) - check_required_make_env_var("XCPP", - "cpp" if use_cross_gcc else "clang-cpp", - parsed_args.cross_bindir) - check_required_make_env_var("XLD", "ld" if use_cross_gcc else "ld.lld", - parsed_args.cross_bindir) + check_xtool_make_env_var("XCC", "gcc" if use_cross_gcc else "clang") + check_xtool_make_env_var("XCXX", "g++" if use_cross_gcc else "clang++") + check_xtool_make_env_var("XCPP", + "cpp" if use_cross_gcc else "clang-cpp") + check_xtool_make_env_var("XLD", "ld" if use_cross_gcc else "ld.lld") # We also need to set STRIPBIN if there is no working strip binary # in $PATH. @@ -232,7 +234,7 @@ def default_cross_toolchain(): else: strip_binary = "strip" check_required_make_env_var("STRIPBIN", strip_binary, - parsed_args.cross_bindir) + parsed_args.host_bindir) if os.getenv("STRIPBIN") or "STRIPBIN" in new_env_vars: # If we are setting STRIPBIN, we have to set XSTRIPBIN to the # default if it is not set otherwise already.