From 2da3afb77e17fa2a14c9f6d8d618232d99f9f57d Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Sun, 15 Aug 2021 09:38:53 -0500 Subject: [PATCH] llvm_toolchain: fixes for using/running the toolchain from other locations in the execroot As the message within explains, `rules_foreign_cc` will use a different PWD than the execroot root for cmake targets which breaks the wrapper script. This commit has the wrapper script search alongside itself for `clang` when it isn't in the usual places. --- toolchain/cc_wrapper.sh.tpl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index 7a8d40a7d..e3e7ea0d9 100755 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -56,8 +56,19 @@ done if [[ "${PATH}:" == *"%{toolchain_path_prefix}bin:"* ]]; then # GoCompile sets the PATH to the directory containing the linker, and changes CWD. clang "$@" -else +elif [[ -f %{toolchain_path_prefix}bin/clang ]]; then %{toolchain_path_prefix}bin/clang "$@" +else + # Some consumers of `CcToolchainConfigInfo`s will use a PWD that *isn't* + # the execroot (i.e. `cmake` from `rules_foreign_cc`). For cases like this, + # we'll try to find `clang` by assuming it's next to this script. + potential_clang_path="$(dirname "${0}")/clang" + if [[ -f ${potential_clang_path} ]]; then + "${potential_clang_path}" "${@}" + else + echo "ERROR: could not find clang; PWD is: $(pwd)." + exit 5 + fi fi function get_library_path() {