Commit 24245fe1 authored by Ben Pastene's avatar Ben Pastene Committed by Commit Bot

chromeos: Refactor toolchain path relativizing into shareable template.

Reduces some copy-pasted code.

Bug: 937821
Change-Id: Ic306e0235de76b43145a58214a95f497e5b2330c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2013906Reviewed-by: default avatarGeorge Burgess <gbiv@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734116}
parent cab6434f
......@@ -7,22 +7,38 @@ import("//build/config/sysroot.gni")
import("//build/toolchain/cros_toolchain.gni")
import("//build/toolchain/gcc_toolchain.gni")
# This is mostly identical to gcc_toolchain, but handles relativizing toolchain
# paths. This is needed for CrOS since these paths often change based on the
# environment. For example, cxx is a relative path picked up on $PATH in the
# chroot. But in Simple Chrome, cxx is a system-absolute path.
template("cros_toolchain") {
gcc_toolchain(target_name) {
forward_variables_from(invoker, "*")
# Relativize path if compiler is specified such that not to lookup from $PATH
# and cc/cxx does not contain additional flags.
if (cc != get_path_info(cc, "file") && string_replace(cc, " ", "") == cc) {
cc = rebase_path(cc, root_build_dir)
}
if (cxx != get_path_info(cxx, "file") &&
string_replace(cxx, " ", "") == cxx) {
cxx = rebase_path(cxx, root_build_dir)
}
if (ar != get_path_info(ar, "file") && string_replace(ar, " ", "") == ar) {
ar = rebase_path(ar, root_build_dir)
}
if (ld != get_path_info(ld, "file") && string_replace(ld, " ", "") == ld) {
ld = rebase_path(ld, root_build_dir)
}
}
}
# This is the normal toolchain for most targets.
gcc_toolchain("target") {
cros_toolchain("target") {
ar = cros_target_ar
cc = cros_target_cc
cxx = cros_target_cxx
# Relativize path if compiler is specified such that not to lookup from $PATH
# and cc/cxx does not contain additional flags.
if (cc != get_path_info(cc, "file") && string_replace(cc, " ", "") == cc) {
cc = rebase_path(cc, root_build_dir)
}
if (cxx != get_path_info(cxx, "file") &&
string_replace(cxx, " ", "") == cxx) {
cxx = rebase_path(cxx, root_build_dir)
}
ld = cxx
if (cros_target_ld != "") {
ld = cros_target_ld
......@@ -54,20 +70,11 @@ gcc_toolchain("target") {
# //native_client/src/trusted/service_runtime/linux. It is identical
# to ":target" except that it forces use_debug_fission, use_gold, and
# use_sysroot off, and allows the user to set different sets of extra flags.
gcc_toolchain("nacl_bootstrap") {
cros_toolchain("nacl_bootstrap") {
ar = cros_target_ar
cc = cros_target_cc
cxx = cros_target_cxx
# Relativize path if compiler is specified such that not to lookup from $PATH
# and cc/cxx does not contain additional flags.
if (cc != get_path_info(cc, "file") && string_replace(cc, " ", "") == cc) {
cc = rebase_path(cc, root_build_dir)
}
if (cxx != get_path_info(cxx, "file") &&
string_replace(cxx, " ", "") == cxx) {
cxx = rebase_path(cxx, root_build_dir)
}
ld = cxx
if (cros_target_ld != "") {
ld = cros_target_ld
......@@ -95,24 +102,12 @@ gcc_toolchain("nacl_bootstrap") {
}
}
gcc_toolchain("host") {
cros_toolchain("host") {
# These are args for the template.
ar = cros_host_ar
cc = cros_host_cc
cxx = cros_host_cxx
# Relativize path if compiler is specified such that not to lookup from $PATH
# and cc/cxx does not contain additional flags.
if (cc != get_path_info(cc, "file") && string_replace(cc, " ", "") == cc) {
cc = rebase_path(cc, root_build_dir)
}
if (cxx != get_path_info(cxx, "file") &&
string_replace(cxx, " ", "") == cxx) {
cxx = rebase_path(cxx, root_build_dir)
}
if (ar != get_path_info(ar, "file") && string_replace(ar, " ", "") == ar) {
ar = rebase_path(ar, root_build_dir)
}
ld = cxx
if (cros_host_ld != "") {
ld = cros_host_ld
......@@ -138,24 +133,12 @@ gcc_toolchain("host") {
}
}
gcc_toolchain("v8_snapshot") {
cros_toolchain("v8_snapshot") {
# These are args for the template.
ar = cros_v8_snapshot_ar
cc = cros_v8_snapshot_cc
cxx = cros_v8_snapshot_cxx
# Relativize path if compiler is specified such that not to lookup from $PATH
# and cc/cxx does not contain additional flags.
if (cc != get_path_info(cc, "file") && string_replace(cc, " ", "") == cc) {
cc = rebase_path(cc, root_build_dir)
}
if (cxx != get_path_info(cxx, "file") &&
string_replace(cxx, " ", "") == cxx) {
cxx = rebase_path(cxx, root_build_dir)
}
if (ar != get_path_info(ar, "file") && string_replace(ar, " ", "") == ar) {
ar = rebase_path(ar, root_build_dir)
}
ld = cxx
if (cros_v8_snapshot_ld != "") {
ld = cros_v8_snapshot_ld
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment