From 0889de69c640669e2582da4735ca54c432806113 Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Tue, 25 Jul 2023 19:17:50 +0000 Subject: [PATCH] pw_toolchain: Make tools use relative paths Changes GN toolchains to use relative paths to tools by default rather than relying on the system PATH. Bug: b/290848929 Change-Id: I580e39c14c32080c0448f9daf4d4f97801f9829f Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/159130 Presubmit-Verified: CQ Bot Account Pigweed-Auto-Submit: Armando Montanez Commit-Queue: Auto-Submit Reviewed-by: Alexei Frolov --- pw_toolchain/arm_gcc/toolchains.gni | 31 ++++++++++++++++++++ pw_toolchain/clang_tools.gni | 44 +++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/pw_toolchain/arm_gcc/toolchains.gni b/pw_toolchain/arm_gcc/toolchains.gni index 1ed1b838ee..dca88c183a 100644 --- a/pw_toolchain/arm_gcc/toolchains.gni +++ b/pw_toolchain/arm_gcc/toolchains.gni @@ -16,10 +16,41 @@ import("//build_overrides/pigweed.gni") import("//build_overrides/pigweed_environment.gni") import("$dir_pw_toolchain/rbe.gni") +_default_compiler_prefix = "" +if (defined(pw_env_setup_CIPD_ARM)) { + _default_compiler_prefix = pw_env_setup_CIPD_ARM + "/bin/" +} + +declare_args() { + # This flag allows you to specify the root directory of the ARM GCC tools to + # to use when compiling with an arm-none-eabi toolchain. This is useful for + # debugging toolchain-related issues, or for building with an + # externally-provided toolchain. + # + # If the prefix begins with "//", it will be rebased to be relative to the + # root build directory. + pw_toolchain_ARM_NONE_EABI_PREFIX = _default_compiler_prefix +} + # Specifies the tools used by ARM GCC toolchains. arm_gcc_toolchain_tools = { _rbe_debug_flag = "" _local_tool_name_root = "arm-none-eabi-" + + _toolchain_prefix = pw_toolchain_ARM_NONE_EABI_PREFIX + if (_toolchain_prefix != "") { + # If the prefix is a GN-absolute path, rebase it so it's relative to the + # root of the build directory. + _split_prefix = string_split(_toolchain_prefix, "//") + if (_split_prefix[0] == "") { + _toolchain_prefix = rebase_path(_toolchain_prefix, root_build_dir) + } + _local_tool_name_root = _toolchain_prefix + _local_tool_name_root + } + if (host_os == "win") { + _local_tool_name_root = string_replace(_local_tool_name_root, "/", "\\") + } + if (pw_toolchain_USE_RBE) { if (pw_toolchain_RBE_DEBUG) { _rbe_debug_flag = " -v " diff --git a/pw_toolchain/clang_tools.gni b/pw_toolchain/clang_tools.gni index 21eb754bd5..4912b90de0 100644 --- a/pw_toolchain/clang_tools.gni +++ b/pw_toolchain/clang_tools.gni @@ -20,10 +20,16 @@ declare_args() { # and llvm-ar binaries to use when compiling with a clang-based toolchain. # This is useful for debugging toolchain-related issues by building with an # externally-provided toolchain. - pw_toolchain_CLANG_PREFIX = "" + # + # If the prefix begins with "//", it will be rebased to be relative to the + # root build directory. + pw_toolchain_CLANG_PREFIX = pw_env_setup_CIPD_PIGWEED + "/bin/" # This flag allows you to specify the root directory of the rustc binary. - pw_toolchain_RUST_PREFIX = "" + # + # If the prefix begins with "//", it will be rebased to be relative to the + # root build directory. + pw_toolchain_RUST_PREFIX = pw_env_setup_CIPD_PIGWEED + "/bin/" } pw_toolchain_clang_tools = { @@ -33,15 +39,35 @@ pw_toolchain_clang_tools = { ld = cxx rustc = "rustc" - if (pw_toolchain_CLANG_PREFIX != "") { - ar = pw_toolchain_CLANG_PREFIX + ar - cc = pw_toolchain_CLANG_PREFIX + cc - cxx = pw_toolchain_CLANG_PREFIX + cxx - ld = pw_toolchain_CLANG_PREFIX + ld + _toolchain_prefix = pw_toolchain_CLANG_PREFIX + if (_toolchain_prefix != "") { + # If the prefix is a GN-absolute path, rebase it so it's relative to the + # root of the build directory. + _split_prefix = string_split(_toolchain_prefix, "//") + if (_split_prefix[0] == "") { + _toolchain_prefix = rebase_path(_toolchain_prefix, root_build_dir) + } + ar = _toolchain_prefix + ar + cc = _toolchain_prefix + cc + cxx = _toolchain_prefix + cxx + ld = _toolchain_prefix + ld + } + if (host_os == "win") { + _toolchain_prefix = string_replace(_toolchain_prefix, "/", "\\") } - if (pw_toolchain_RUST_PREFIX != "") { - rustc = pw_toolchain_RUST_PREFIX + rustc + _rust_prefix = pw_toolchain_RUST_PREFIX + if (host_os == "win") { + _rust_prefix = string_replace(_rust_prefix, "/", "\\") + } + if (_rust_prefix != "") { + # If the prefix is a GN-absolute path, rebase it so it's relative to the + # root of the build directory. + _split_rust_prefix = string_split(_rust_prefix, "//") + if (_split_rust_prefix[0] == "") { + _rust_prefix = rebase_path(_rust_prefix, root_build_dir) + } + rustc = _rust_prefix + rustc } if (pw_toolchain_USE_RBE) {