14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
- # OS X relpath is not really working. This is a wrapper script around gcc
18
- # to simulate relpath behavior.
19
- #
20
- # This wrapper uses install_name_tool to replace all paths in the binary
21
- # (bazel-out/.../path/to/original/library.so) by the paths relative to
22
- # the binary. It parses the command line to behave as rpath is supposed
23
- # to work.
24
- #
25
- # See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
26
- # on how to set those paths for Mach-O binaries.
27
-
28
17
# shellcheck disable=SC1083
29
18
30
19
set -euo pipefail
@@ -42,27 +31,41 @@ trap cleanup EXIT
42
31
# See note in toolchain/internal/configure.bzl where we define
43
32
# `wrapper_bin_prefix` for why this wrapper is needed.
44
33
45
- if [[ -f %{toolchain_path_prefix}bin/clang ]]; then
46
- execroot_path=" "
47
- elif [[ ${BASH_SOURCE[0]} == " /" * ]]; then
48
- # Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc)
49
- # change CWD and call $CC (this script) with its absolute path.
50
- # For cases like this, we'll try to find `clang` through an absolute path.
51
- # This script is at _execroot_/external/_repo_name_/bin/cc_wrapper.sh
52
- execroot_path=" ${BASH_SOURCE[0]%/*/*/*/* } /"
53
- else
54
- echo >&2 " ERROR: could not find clang; PWD=\" ${PWD} \" ; PATH=\" ${PATH} \" ."
34
+ # this script is located at either
35
+ # - <execroot>/external/<repo_name>/bin/cc_wrapper.sh
36
+ # - <runfiles>/<repo_name>/bin/cc_wrapper.sh
37
+ # The clang is located at
38
+ # - <execroot>/external/<repo_name2>/bin/clang
39
+ # - <runfiles>/<repo_name2>/bin/clang
40
+ #
41
+ # In both cases, getting to clang can be done via
42
+ # Finding the current dir of this script,
43
+ # - <execroot>/external/<repo_name>/bin/
44
+ # - <runfiles>/<repo_name>/bin/
45
+ # going back 2 directories
46
+ # - <execroot>/external
47
+ # - <runfiles>
48
+ #
49
+ # Going into %{toolchain_path_prefix} without the `external/` prefix + bin/clang
50
+ #
51
+
52
+ script_dir=$( dirname ${BASH_SOURCE[0]} )
53
+ toolchain_path_prefix=" %{toolchain_path_prefix}"
54
+ toolchain_path_prefix=" $script_dir /../../${toolchain_path_prefix# external/ } "
55
+
56
+ if [[ ! -f ${toolchain_path_prefix} bin/clang ]]; then
57
+ echo >&2 " ERROR: could not find clang; PWD=\" ${PWD} \" ; PATH=\" ${PATH} \" ; toolchain_path_prefix=${toolchain_path_prefix} ."
55
58
exit 5
56
59
fi
57
60
58
61
function sanitize_option() {
59
62
local -r opt=$1
60
63
if [[ ${opt} == * /cc_wrapper.sh ]]; then
61
- printf " %s" " ${execroot_path} %{ toolchain_path_prefix}bin/clang"
62
- elif [[ ${opt} =~ ^-fsanitize-(ignore| black)list= [^/] ]]; then
64
+ printf " %s" " ${toolchain_path_prefix} bin/clang"
65
+ elif [[ ${opt} =~ ^-fsanitize-(ignore| black)list= [^/] ]] && [[ ${script_dir} == / * ]] ; then
63
66
# shellcheck disable=SC2206
64
67
parts=(${opt/ =/ } ) # Split flag name and value into array.
65
- printf " %s" " ${parts[0]} =${execroot_path} ${parts[1]} "
68
+ printf " %s" " ${parts[0]} =$script_dir /../../../ ${parts[1]} "
66
69
else
67
70
printf " %s" " ${opt} "
68
71
fi
0 commit comments