Skip to content

Commit 96b08ff

Browse files
authored
cc_wrapper: Handle absolute BASH_SOURCE path (bazel-contrib#567)
Fixes bazel-contrib#547
1 parent 60b065b commit 96b08ff

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

toolchain/cc_wrapper.sh.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ dirname_shim() {
6868
echo "${path:-/}"
6969
}
7070

71-
script_dir=$(dirname_shim "${BASH_SOURCE[0]}")
71+
if [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
72+
bash_source_abs="$(realpath "${BASH_SOURCE[0]}")"
73+
pwd_abs="$(realpath ".")"
74+
bash_source_rel=${bash_source_abs#"${pwd_abs}/"}
75+
else
76+
bash_source_rel="${BASH_SOURCE[0]}"
77+
fi
78+
script_dir=$(dirname_shim "${bash_source_rel}")
7279
toolchain_path_prefix="%{toolchain_path_prefix}"
7380

7481
# Sometimes this path may be an absolute path in which case we dont do anything because

toolchain/osx_cc_wrapper.sh.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ dirname_shim() {
103103
echo "${path:-/}"
104104
}
105105

106-
script_dir=$(dirname_shim "${BASH_SOURCE[0]}")
106+
if [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
107+
bash_source_abs="$(realpath "${BASH_SOURCE[0]}")"
108+
pwd_abs="$(realpath ".")"
109+
bash_source_rel=${bash_source_abs#"${pwd_abs}/"}
110+
else
111+
bash_source_rel="${BASH_SOURCE[0]}"
112+
fi
113+
script_dir=$(dirname_shim "${bash_source_rel}")
107114
toolchain_path_prefix="%{toolchain_path_prefix}"
108115
# Sometimes this path may be an absolute path in which case we dont do anything because
109116
# This is using the host toolchain to build.

0 commit comments

Comments
 (0)