Skip to content

Commit

Permalink
pw_toolchain: Make tools use relative paths
Browse files Browse the repository at this point in the history
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-scoped@luci-project-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Armando Montanez <amontanez@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
  • Loading branch information
armandomontanez authored and CQ Bot Account committed Jul 25, 2023
1 parent f04f934 commit 0889de6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
31 changes: 31 additions & 0 deletions pw_toolchain/arm_gcc/toolchains.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
44 changes: 35 additions & 9 deletions pw_toolchain/clang_tools.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand Down

0 comments on commit 0889de6

Please sign in to comment.