Skip to content

Commit 60b065b

Browse files
authored
Avoid ../ segments in paths in compiler wrapper (bazel-contrib#565)
`../` segments may throw off Bazel's undeclared includes detection and are replaced with `dirname`. Work towards bazel-contrib#547
1 parent f54b90b commit 60b065b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

toolchain/cc_wrapper.sh.tpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ toolchain_path_prefix="%{toolchain_path_prefix}"
7474
# Sometimes this path may be an absolute path in which case we dont do anything because
7575
# This is using the host toolchain to build.
7676
if [[ ${toolchain_path_prefix} != /* ]]; then
77-
toolchain_path_prefix="${script_dir}/../../${toolchain_path_prefix#external/}"
77+
# shellcheck disable=SC2312
78+
toolchain_path_prefix="$(dirname_shim "$(dirname_shim "${script_dir}")")/${toolchain_path_prefix#external/}"
7879
fi
7980

8081
if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then
@@ -101,7 +102,8 @@ function sanitize_option() {
101102
elif [[ ${opt} =~ ^-fsanitize-(ignore|black)list=[^/] ]] && [[ ${script_dir} == /* ]]; then
102103
# shellcheck disable=SC2206
103104
parts=(${opt/=/ }) # Split flag name and value into array.
104-
printf "%s" "${parts[0]}=${script_dir}/../../../${parts[1]}"
105+
# shellcheck disable=SC2312
106+
printf "%s" "${parts[0]}=$(dirname_shim "$(dirname_shim "$(dirname_shim "${script_dir}")")")/${parts[1]}"
105107
else
106108
printf "%s" "${opt}"
107109
fi

toolchain/osx_cc_wrapper.sh.tpl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ toolchain_path_prefix="%{toolchain_path_prefix}"
108108
# Sometimes this path may be an absolute path in which case we dont do anything because
109109
# This is using the host toolchain to build.
110110
if [[ ${toolchain_path_prefix} != /* ]]; then
111-
toolchain_path_prefix="${script_dir}/../../${toolchain_path_prefix#external/}"
111+
# shellcheck disable=SC2312
112+
toolchain_path_prefix="$(dirname_shim "$(dirname_shim "${script_dir}")")/${toolchain_path_prefix#external/}"
112113
toolchain_path_prefix_abs="$(cd "${toolchain_path_prefix}" && pwd -P)/"
113114
else
114115
toolchain_path_prefix_abs="${toolchain_path_prefix}"
@@ -128,7 +129,8 @@ function sanitize_option() {
128129
elif [[ ${opt} =~ ^-fsanitize-(ignore|black)list=[^/] ]] && [[ ${script_dir} == /* ]]; then
129130
# shellcheck disable=SC2206
130131
parts=(${opt/=/ }) # Split flag name and value into array.
131-
printf "%s" "${parts[0]}=${script_dir}/../../../${parts[1]}"
132+
# shellcheck disable=SC2312
133+
printf "%s" "${parts[0]}=$(dirname_shim "$(dirname_shim "$(dirname_shim "${script_dir}")")")/${parts[1]}"
132134
else
133135
printf "%s" "${opt}"
134136
fi

0 commit comments

Comments
 (0)