Replacing hardcoded use of 'local' for env variables in cc autoconfig
--
Change-Id: Ic1632229e67bf82b69983f9614258c5fd54c12d8
Reviewed-on: https://cr.bazel.build/9390
PiperOrigin-RevId: 151422502
MOS_MIGRATED_REVID=151422502
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index becd458..1a46712 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -324,7 +324,22 @@
shift
local client_env=()
# Propagate important environment variables to bootstrapped Bazel.
- for varname in PATH CC BAZEL_SH BAZEL_VC BAZEL_VS BAZEL_PYTHON CPLUS_INCLUDEPATH; do
+ local env_vars="ABI_LIBC_VERSION"
+ env_vars="$env_vars ABI_VERSION"
+ env_vars="$env_vars BAZEL_COMPILER "
+ env_vars="$env_vars BAZEL_HOST_SYSTEM"
+ env_vars="$env_vars BAZEL_PYTHON"
+ env_vars="$env_vars BAZEL_SH"
+ env_vars="$env_vars BAZEL_TARGET_CPU"
+ env_vars="$env_vars BAZEL_TARGET_LIBC"
+ env_vars="$env_vars BAZEL_TARGET_SYSTEM"
+ env_vars="$env_vars BAZEL_VC"
+ env_vars="$env_vars BAZEL_VS"
+ env_vars="$env_vars CC"
+ env_vars="$env_vars CC_TOOLCHAIN_NAME"
+ env_vars="$env_vars CPLUS_INCLUDE_PATH"
+ env_vars="$env_vars PATH"
+ for varname in $env_vars; do
eval value=\$$varname
if [ "${value}" ]; then
client_env=("${client_env[@]}" --client_env="${varname}=${value}")
diff --git a/tools/cpp/BUILD.tpl b/tools/cpp/BUILD.tpl
index 11061da..5ea5368 100644
--- a/tools/cpp/BUILD.tpl
+++ b/tools/cpp/BUILD.tpl
@@ -24,7 +24,7 @@
cc_toolchain_suite(
name = "toolchain",
toolchains = {
- "%{name}|compiler": ":cc-compiler-%{name}",
+ "%{name}|%{compiler}": ":cc-compiler-%{name}",
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
"ios_x86_64|compiler": ":cc-compiler-ios_x86_64",
},
@@ -34,7 +34,7 @@
name = "cc-compiler-%{name}",
all_files = "%{cc_compiler_deps}",
compiler_files = "%{cc_compiler_deps}",
- cpu = "local",
+ cpu = "%{name}",
dwp_files = ":empty",
dynamic_runtime_libs = [":empty"],
linker_files = "%{cc_compiler_deps}",
diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl
index 906c1f5..580c7a0 100644
--- a/tools/cpp/CROSSTOOL.tpl
+++ b/tools/cpp/CROSSTOOL.tpl
@@ -24,7 +24,7 @@
default_toolchain {
cpu: "s390x"
- toolchain_identifier: "local"
+ toolchain_identifier: "%{toolchain_name}"
}
default_toolchain {
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index eddf060..8abed7e 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -212,11 +212,11 @@
"""Return the content for the CROSSTOOL file, in a dictionary."""
supports_gold_linker = _is_gold_supported(repository_ctx, cc)
return {
- "abi_version": "local",
- "abi_libc_version": "local",
+ "abi_version": _get_env_var(repository_ctx, "ABI_VERSION", "local"),
+ "abi_libc_version": _get_env_var(repository_ctx, "ABI_LIBC_VERSION", "local"),
"builtin_sysroot": "",
- "compiler": "compiler",
- "host_system_name": "local",
+ "compiler": _get_env_var(repository_ctx, "BAZEL_COMPILER", "compiler"),
+ "host_system_name": _get_env_var(repository_ctx, "BAZEL_HOST_SYSTEM", "local"),
"needsPic": True,
"supports_gold_linker": supports_gold_linker,
"supports_incremental_linker": False,
@@ -224,9 +224,9 @@
"supports_interface_shared_objects": False,
"supports_normalizing_ar": False,
"supports_start_end_lib": supports_gold_linker,
- "target_libc": "macosx" if darwin else "local",
- "target_cpu": cpu_value,
- "target_system_name": "local",
+ "target_libc": "macosx" if darwin else _get_env_var(repository_ctx, "BAZEL_TARGET_LIBC", "local"),
+ "target_cpu": _get_env_var(repository_ctx, "BAZEL_TARGET_CPU", cpu_value),
+ "target_system_name": _get_env_var(repository_ctx, "BAZEL_TARGET_SYSTEM", "local"),
"cxx_flag": [
"-std=c++0x",
] + _cplus_include_paths(repository_ctx),
@@ -732,6 +732,7 @@
"%{name}": cpu_value,
"%{supports_param_files}": "0" if darwin else "1",
"%{cc_compiler_deps}": ":cc_wrapper" if darwin else ":empty",
+ "%{compiler}": _get_env_var(repository_ctx, "BAZEL_COMPILER", "compiler"),
})
_tpl(repository_ctx,
"osx_cc_wrapper.sh" if darwin else "linux_cc_wrapper.sh",
@@ -739,8 +740,8 @@
"cc_wrapper.sh")
_tpl(repository_ctx, "CROSSTOOL", {
"%{cpu}": cpu_value,
- "%{default_toolchain_name}": "local",
- "%{toolchain_name}": "local",
+ "%{default_toolchain_name}": _get_env_var(repository_ctx, "CC_TOOLCHAIN_NAME", "local"),
+ "%{toolchain_name}": _get_env_var(repository_ctx, "CC_TOOLCHAIN_NAME", "local"),
"%{content}": _build_crosstool(crosstool_content) + "\n" +
_build_tool_path(tool_paths),
"%{opt_content}": _build_crosstool(opt_content, " "),
@@ -753,11 +754,19 @@
cc_autoconf = repository_rule(
implementation=_impl,
environ = [
- "CC",
+ "ABI_LIBC_VERSION",
+ "ABI_VERSION",
+ "BAZEL_COMPILER",
+ "BAZEL_HOST_SYSTEM",
+ "BAZEL_PYTHON",
+ "BAZEL_SH",
+ "BAZEL_TARGET_CPU",
+ "BAZEL_TARGET_LIBC",
+ "BAZEL_TARGET_SYSTEM",
"BAZEL_VC",
"BAZEL_VS",
- "BAZEL_SH",
- "BAZEL_PYTHON",
+ "CC",
+ "CC_TOOLCHAIN_NAME",
"CPLUS_INCLUDE_PATH"])