Skip to content

Commit a56ac00

Browse files
notoriagaCopilot
andauthored
have cc toolchain wrappers use posix shell (#180)
rules_rust uses the cc toolchain for linking, and I've been running into issues building with rules_rust + our custom toolchain (specifically llvm 20 on mac). Disabling the custom toolchain plus updating cc rules to bazelbuild/rules_cc#466 fixed my issue. I don't know if this needs to/should be applied to all wrappers, but I figured it couldn't hurt? The changes in each file are - Changed shebangs: #!/usr/bin/env bash and #!/bin/bash → #!/bin/sh - Replaced bash tests: [[ ]] → [ ] - Replaced BASH_SOURCE: ${BASH_SOURCE[0]} → $0 - Fixed path checks: [[ "$0" == "/"* ]] → case "$0" in /*) true;; *) false;; esac - Argument passing: "${@}" → "$@" --------- Co-authored-by: Copilot <[email protected]>
1 parent 56c9f08 commit a56ac00

File tree

29 files changed

+287
-296
lines changed

29 files changed

+287
-296
lines changed

cc/toolchains/gcc_arm_embedded/wrappers/wrapper

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# Copyright (C) 2022 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
@@ -29,25 +29,25 @@
2929
set -e
3030

3131
# Use --action_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
32-
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
32+
if [ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]; then
3333
set -x
3434
fi
3535

36-
tool_name=$(basename "${BASH_SOURCE[0]}")
36+
tool_name=$(basename "$0")
3737
# In case the tool label is changed, a change in here is very likely needed
3838
# This establishes backwards compatibility with the old WORKSPACE file
3939
toolchain_bindir=external/x86_64_linux_gcc_arm_embedded_toolchain/bin
4040
toolchain_bindir_as_bzlmod="external/rules_swiftnav++swift_cc_toolchain_extension+x86_64_linux_gcc_arm_embedded_toolchain/bin"
4141

42-
if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
42+
if [ -f "${toolchain_bindir}/${tool_name}" ]; then
4343
# We're running under _execroot_, call the real tool.
4444
# use-case: WORKSPACE
45-
exec "${toolchain_bindir}"/"${tool_name}" "$@"
46-
elif [[ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]]; then
45+
exec "${toolchain_bindir}/${tool_name}" "$@"
46+
elif [ -f "${toolchain_bindir_as_bzlmod}/${tool_name}" ]; then
4747
# We're running under _execroot_, call the real tool.
4848
# Use-case: bazelmod
49-
exec "${toolchain_bindir_as_bzlmod}"/"${tool_name}" "$@"
50-
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
49+
exec "${toolchain_bindir_as_bzlmod}/${tool_name}" "$@"
50+
elif case "$0" in /*) true;; *) false;; esac; then
5151
# This branch exists because some users of the toolchain,
5252
# namely rules_foreign_cc, will change CWD and call $CC (this script)
5353
# with its absolute path.
@@ -57,20 +57,18 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
5757
#
5858
# If the wrapper is relocated then this line needs to be adjusted.
5959

60-
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
60+
execroot_path="${0%/*/*/*/*/*/*/*/*}"
6161

6262
# Legacy path for non-bazelmod
6363
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
64-
if [[ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]];
65-
then
66-
exec "${tool}" "${@}"
64+
if [ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]; then
65+
exec "${tool}" "$@"
6766
fi
6867

6968
# After bazelmod migration, the directory structure is different
7069
tool_as_bzlmod="${execroot_path}/${toolchain_bindir_as_bzlmod}/${tool_name}"
71-
if [[ -f "${tool_as_bzlmod}" ]];
72-
then
73-
exec "${tool_as_bzlmod}" "${@}"
70+
if [ -f "${tool_as_bzlmod}" ]; then
71+
exec "${tool_as_bzlmod}" "$@"
7472
fi
7573
else
7674
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."

cc/toolchains/gcc_arm_gnu_8_3/wrappers/wrapper

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# Copyright (C) 2022 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
@@ -29,25 +29,25 @@
2929
set -e
3030

3131
# Use --action_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
32-
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
32+
if [ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]; then
3333
set -x
3434
fi
3535

36-
tool_name=$(basename "${BASH_SOURCE[0]}")
36+
tool_name=$(basename "$0")
3737
# In case the tool label is changed, a change in here is very likely needed
3838
# This establishes backwards compatibility with the old WORKSPACE file
3939
toolchain_bindir=external/gcc_arm_gnu_8_3_toolchain/bin
4040
toolchain_bindir_as_bzlmod="external/rules_swiftnav++swift_cc_toolchain_extension+gcc_arm_gnu_8_3_toolchain/bin"
4141

42-
if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
42+
if [ -f "${toolchain_bindir}/${tool_name}" ]; then
4343
# We're running under _execroot_, call the real tool.
4444
# use-case: WORKSPACE
4545
exec "${toolchain_bindir}"/"${tool_name}" "$@"
46-
elif [[ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]]; then
46+
elif [ -f "${toolchain_bindir_as_bzlmod}/${tool_name}" ]; then
4747
# We're running under _execroot_, call the real tool.
4848
# Use-case: bazelmod
4949
exec "${toolchain_bindir_as_bzlmod}"/"${tool_name}" "$@"
50-
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
50+
elif case "$0" in /*) true;; *) false;; esac; then
5151
# This branch exists because some users of the toolchain,
5252
# namely rules_foreign_cc, will change CWD and call $CC (this script)
5353
# with its absolute path.
@@ -57,20 +57,18 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
5757
#
5858
# If the wrapper is relocated then this line needs to be adjusted.
5959

60-
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
60+
execroot_path="${0%/*/*/*/*/*/*/*/*}"
6161

6262
# Legacy path for non-bazelmod
6363
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
64-
if [[ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]];
65-
then
66-
exec "${tool}" "${@}"
64+
if [ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]; then
65+
exec "${tool}" "$@"
6766
fi
6867

6968
# After bazelmod migration, the directory structure is different
7069
tool_as_bzlmod="${execroot_path}/${toolchain_bindir_as_bzlmod}/${tool_name}"
71-
if [[ -f "${tool_as_bzlmod}" ]];
72-
then
73-
exec "${tool_as_bzlmod}" "${@}"
70+
if [ -f "${tool_as_bzlmod}" ]; then
71+
exec "${tool_as_bzlmod}" "$@"
7472
fi
7573
else
7674
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."

cc/toolchains/llvm/aarch64-darwin/wrappers/wrapper

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# Copyright (C) 2022 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
@@ -29,25 +29,25 @@
2929
set -e
3030

3131
# Use --action_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
32-
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
32+
if [ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]; then
3333
set -x
3434
fi
3535

36-
tool_name=$(basename "${BASH_SOURCE[0]}")
36+
tool_name=$(basename "$0")
3737
# In case the tool label is changed, a change in here is very likely needed
3838
# This establishes backwards compatibility with the old WORKSPACE file
3939
toolchain_bindir=external/aarch64-darwin-llvm/bin
4040
toolchain_bindir_as_bzlmod="external/rules_swiftnav++swift_cc_toolchain_extension+aarch64-darwin-llvm/bin"
4141

42-
if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
42+
if [ -f "${toolchain_bindir}"/"${tool_name}" ]; then
4343
# We're running under _execroot_, call the real tool.
4444
# use-case: WORKSPACE
4545
exec "${toolchain_bindir}"/"${tool_name}" "$@"
46-
elif [[ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]]; then
46+
elif [ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]; then
4747
# We're running under _execroot_, call the real tool.
4848
# Use-case: bazelmod
4949
exec "${toolchain_bindir_as_bzlmod}"/"${tool_name}" "$@"
50-
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
50+
elif case "$0" in /*) true;; *) false;; esac; then
5151
# This branch exists because some users of the toolchain,
5252
# namely rules_foreign_cc, will change CWD and call $CC (this script)
5353
# with its absolute path.
@@ -57,20 +57,20 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
5757
#
5858
# If the wrapper is relocated then this line needs to be adjusted.
5959

60-
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
60+
execroot_path="${0%/*/*/*/*/*/*/*/*}"
6161

6262
# Legacy path for non-bazelmod
6363
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
64-
if [[ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]];
64+
if [ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ];
6565
then
66-
exec "${tool}" "${@}"
66+
exec "${tool}" "$@"
6767
fi
6868

6969
# After bazelmod migration, the directory structure is different
7070
tool_as_bzlmod="${execroot_path}/${toolchain_bindir_as_bzlmod}/${tool_name}"
71-
if [[ -f "${tool_as_bzlmod}" ]];
71+
if [ -f "${tool_as_bzlmod}" ];
7272
then
73-
exec "${tool_as_bzlmod}" "${@}"
73+
exec "${tool_as_bzlmod}" "$@"
7474
fi
7575
else
7676
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."

cc/toolchains/llvm/aarch64-linux/wrappers/wrapper

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# Copyright (C) 2022 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
@@ -29,23 +29,23 @@
2929
set -e
3030

3131
# Use --action_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
32-
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
32+
if [ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]; then
3333
set -x
3434
fi
3535

36-
tool_name=$(basename "${BASH_SOURCE[0]}")
36+
tool_name=$(basename "$0")
3737
toolchain_bindir=external/aarch64-linux-llvm/bin
3838
toolchain_bindir_as_bzlmod="external/rules_swiftnav++swift_cc_toolchain_extension+aarch64-linux-llvm/bin"
3939

40-
if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
40+
if [ -f "${toolchain_bindir}"/"${tool_name}" ]; then
4141
# We're running under _execroot_, call the real tool.
4242
# use-case: WORKSPACE
4343
exec "${toolchain_bindir}"/"${tool_name}" "$@"
44-
elif [[ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]]; then
44+
elif [ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]; then
4545
# We're running under _execroot_, call the real tool.
4646
# Use-case: bazelmod
4747
exec "${toolchain_bindir_as_bzlmod}"/"${tool_name}" "$@"
48-
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
48+
elif case "$0" in /*) true;; *) false;; esac; then
4949
# This branch exists because some users of the toolchain,
5050
# namely rules_foreign_cc, will change CWD and call $CC (this script)
5151
# with its absolute path.
@@ -55,20 +55,20 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
5555
#
5656
# If the wrapper is relocated then this line needs to be adjusted.
5757

58-
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
58+
execroot_path="${0%/*/*/*/*/*/*/*/*}"
5959

6060
# Legacy path for non-bazelmod
6161
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
62-
if [[ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]];
62+
if [ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ];
6363
then
64-
exec "${tool}" "${@}"
64+
exec "${tool}" "$@"
6565
fi
6666

6767
# After bazelmod migration, the directory structure is different
6868
tool_as_bzlmod="${execroot_path}/${toolchain_bindir_as_bzlmod}/${tool_name}"
69-
if [[ -f "${tool_as_bzlmod}" ]];
69+
if [ -f "${tool_as_bzlmod}" ];
7070
then
71-
exec "${tool_as_bzlmod}" "${@}"
71+
exec "${tool_as_bzlmod}" "$@"
7272
fi
7373
else
7474
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."

cc/toolchains/llvm/x86_64-aarch64-linux/wrappers/wrapper

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# Copyright (C) 2022 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
@@ -29,23 +29,23 @@
2929
set -e
3030

3131
# Use --action_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
32-
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
32+
if [ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]; then
3333
set -x
3434
fi
3535

36-
tool_name=$(basename "${BASH_SOURCE[0]}")
36+
tool_name=$(basename "$0")
3737
toolchain_bindir=external/x86_64-linux-llvm/bin
3838
toolchain_bindir_as_bzlmod="external/rules_swiftnav++swift_cc_toolchain_extension+x86_64-linux-llvm/bin"
3939

40-
if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
40+
if [ -f "${toolchain_bindir}"/"${tool_name}" ]; then
4141
# We're running under _execroot_, call the real tool.
4242
# use-case: WORKSPACE
4343
exec "${toolchain_bindir}"/"${tool_name}" "$@"
44-
elif [[ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]]; then
44+
elif [ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]; then
4545
# We're running under _execroot_, call the real tool.
4646
# Use-case: bazelmod
4747
exec "${toolchain_bindir_as_bzlmod}"/"${tool_name}" "$@"
48-
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
48+
elif case "$0" in /*) true;; *) false;; esac; then
4949
# This branch exists because some users of the toolchain,
5050
# namely rules_foreign_cc, will change CWD and call $CC (this script)
5151
# with its absolute path.
@@ -55,20 +55,20 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
5555
#
5656
# If the wrapper is relocated then this line needs to be adjusted.
5757

58-
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
58+
execroot_path="${0%/*/*/*/*/*/*/*/*}"
5959

6060
# Legacy path for non-bazelmod
6161
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
62-
if [[ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]];
62+
if [ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ];
6363
then
64-
exec "${tool}" "${@}"
64+
exec "${tool}" "$@"
6565
fi
6666

6767
# After bazelmod migration, the directory structure is different
6868
tool_as_bzlmod="${execroot_path}/${toolchain_bindir_as_bzlmod}/${tool_name}"
69-
if [[ -f "${tool_as_bzlmod}" ]];
69+
if [ -f "${tool_as_bzlmod}" ];
7070
then
71-
exec "${tool_as_bzlmod}" "${@}"
71+
exec "${tool_as_bzlmod}" "$@"
7272
fi
7373
else
7474
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."

cc/toolchains/llvm/x86_64-darwin/wrappers/wrapper

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

33
# Copyright (C) 2022 Swift Navigation Inc.
44
# Contact: Swift Navigation <[email protected]>
@@ -29,22 +29,23 @@
2929
set -e
3030

3131
# Use --action_env=SWIFTNAV_VERBOSE_TOOLCHAIN to enable
32-
if [[ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]]; then
32+
if [ -n "$SWIFTNAV_VERBOSE_TOOLCHAIN" ]; then
3333
set -x
3434
fi
3535

36-
tool_name=$(basename "${BASH_SOURCE[0]}")
36+
tool_name=$(basename "$0")
3737
toolchain_bindir=external/x86_64-darwin-llvm/bin
38+
toolchain_bindir_as_bzlmod="external/rules_swiftnav++swift_cc_toolchain_extension+x86_64-darwin-llvm/bin"
3839

39-
if [[ -f "${toolchain_bindir}"/"${tool_name}" ]]; then
40+
if [ -f "${toolchain_bindir}"/"${tool_name}" ]; then
4041
# We're running under _execroot_, call the real tool.
4142
# use-case: WORKSPACE
4243
exec "${toolchain_bindir}"/"${tool_name}" "$@"
43-
elif [[ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]]; then
44+
elif [ -f "${toolchain_bindir_as_bzlmod}"/"${tool_name}" ]; then
4445
# We're running under _execroot_, call the real tool.
4546
# Use-case: bazelmod
4647
exec "${toolchain_bindir_as_bzlmod}"/"${tool_name}" "$@"
47-
elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
48+
elif case "$0" in /*) true;; *) false;; esac; then
4849
# This branch exists because some users of the toolchain,
4950
# namely rules_foreign_cc, will change CWD and call $CC (this script)
5051
# with its absolute path.
@@ -54,20 +55,20 @@ elif [[ "${BASH_SOURCE[0]}" == "/"* ]]; then
5455
#
5556
# If the wrapper is relocated then this line needs to be adjusted.
5657

57-
execroot_path="${BASH_SOURCE[0]%/*/*/*/*/*/*/*/*}"
58+
execroot_path="${0%/*/*/*/*/*/*/*/*}"
5859

5960
# Legacy path for non-bazelmod
6061
tool="${execroot_path}/${toolchain_bindir}/${tool_name}"
61-
if [[ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ]];
62+
if [ -f "${execroot_path}/${toolchain_bindir}/${tool_name}" ];
6263
then
63-
exec "${tool}" "${@}"
64+
exec "${tool}" "$@"
6465
fi
6566

6667
# After bazelmod migration, the directory structure is different
6768
tool_as_bzlmod="${execroot_path}/${toolchain_bindir_as_bzlmod}/${tool_name}"
68-
if [[ -f "${tool_as_bzlmod}" ]];
69+
if [ -f "${tool_as_bzlmod}" ];
6970
then
70-
exec "${tool_as_bzlmod}" "${@}"
71+
exec "${tool_as_bzlmod}" "$@"
7172
fi
7273
else
7374
>&2 echo "ERROR: could not find ${tool_name}; PWD=\"$(pwd)\"; PATH=\"${PATH}\"."

0 commit comments

Comments
 (0)