Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Mar 2021 12:00:29 GMT
From:      Alex Richardson <arichardson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2b181156c893 - main - tools/build/make.py: Avoid calling brew --prefix on macOS unnecessarily
Message-ID:  <202103221200.12MC0TqN055165@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=2b181156c893843266c2825098360db2364dbd23

commit 2b181156c893843266c2825098360db2364dbd23
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-03-05 10:21:12 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-03-22 11:55:07 +0000

    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 @@ if __name__ == "__main__":
     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 @@ if __name__ == "__main__":
 
         # 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 @@ if __name__ == "__main__":
             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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103221200.12MC0TqN055165>