Skip to content

Commit 83e3846

Browse files
oharboeclaude
andcommitted
bazel-hermetic: drop realpath from shebang check; macOS-safe LANG
Two macOS findings from the latest Gemini pass: - Shebang detection no longer shells out to realpath (nor readlink -f): read the candidate via redirection, `head -c 2 < "${BAZEL}"`. open() follows the symlink itself, so no path-resolution tool is needed — which also settles whether realpath/readlink -f is present on macOS (it need not be). Verified reading through a symlink yields the target file's first bytes. - LANG: macOS has no C.UTF-8 locale, so forcing it makes programs emit "cannot change locale" warnings. Pick en_US.UTF-8 on Darwin, C.UTF-8 elsewhere; both give UTF-8 byte handling. Re-verified with the stub-bazel argv harness (build / bug case / info). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent ad51f2a commit 83e3846

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

etc/bazel-hermetic

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ if [[ -z ${BAZEL} ]]; then
9191
fi
9292
# Wrapper detection: the bazelisk launcher by name, or any script shebang
9393
# (npm/shell wrappers). Native binaries (ELF on Linux, Mach-O on macOS)
94-
# are symlinked directly.
95-
if [[ ${BAZEL} == *bazelisk* || $(head -c 2 "$(realpath "${BAZEL}")") == '#!' ]]; then
94+
# are symlinked directly. Read via redirection: open() follows the
95+
# symlink for us, so no realpath/readlink -f is needed (neither is
96+
# reliably present on macOS).
97+
if [[ ${BAZEL} == *bazelisk* || $(head -c 2 < "${BAZEL}") == '#!' ]]; then
9698
version=$(BAZELISK_SKIP_WRAPPER=1 "${BAZEL}" --version | awk '{print $2}')
9799
os=$(uname -s | tr '[:upper:]' '[:lower:]')
98100
arch=$(uname -m | sed 's/aarch64/arm64/')
@@ -196,13 +198,21 @@ if [[ -z ${command} ]]; then
196198
bazel_argv=(${startup_flags[@]+"${startup_flags[@]}"})
197199
fi
198200

201+
# macOS has no C.UTF-8 locale, so forcing it there makes programs print
202+
# "cannot change locale" warnings; use en_US.UTF-8 on Darwin. Both give
203+
# UTF-8 byte handling.
204+
case "$(uname -s)" in
205+
Darwin) lang=en_US.UTF-8 ;;
206+
*) lang=C.UTF-8 ;;
207+
esac
208+
199209
# HOME:- and the array guards: same set -u / bash 3.2 safety as above.
200210
exec env -i \
201211
HOME="${HOME:-}" \
202212
USER="${USER:-$(id -un)}" \
203213
LOGNAME="${LOGNAME:-$(id -un)}" \
204214
TERM="${TERM:-dumb}" \
205-
LANG=C.UTF-8 \
215+
LANG="${lang}" \
206216
PATH="${TOOLBOX}" \
207217
${preserved_env[@]+"${preserved_env[@]}"} \
208218
"${TOOLBOX}/bazel" ${bazel_argv[@]+"${bazel_argv[@]}"}

0 commit comments

Comments
 (0)