Skip to content

Commit 288a1ac

Browse files
oharboeclaude
andcommitted
bazel: use portable readlink in bzl lint/fmt tests
`readlink -f` is GNU-only; macOS's BSD readlink lacks -f. Bazel writes runfiles symlinks with absolute targets, so plain `readlink` suffices and works on both platforms. Also tighten the precondition to `-L` since the entry must be a symlink, not just any file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 6c171ff commit 288a1ac

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

bazel/bzl_fmt_test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
set -euo pipefail
77
TOOL="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
88
# MODULE.bazel must be in the sh_test `data` deps so it appears as a
9-
# runfiles symlink; readlink -f then resolves it to the real workspace.
10-
# Without the data dep, readlink -f silently returns a bogus path.
11-
[ -e MODULE.bazel ] || { echo "MODULE.bazel missing from runfiles" >&2; exit 1; }
12-
WORKSPACE="$(cd "$(dirname "$(readlink -f MODULE.bazel)")" && pwd)"
9+
# runfiles symlink pointing at the real workspace. `readlink` (no -f,
10+
# for macOS portability) resolves the absolute path Bazel wrote.
11+
[ -L MODULE.bazel ] || { echo "MODULE.bazel missing from runfiles" >&2; exit 1; }
12+
WORKSPACE="$(dirname "$(readlink MODULE.bazel)")"
1313
cd "$WORKSPACE"
1414
# `git ls-files` skips submodule contents (src/sta, third-party/abc).
1515
# Explicit -mode=check -lint=off separates format errors from lint warnings,

bazel/bzl_lint_test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
set -euo pipefail
77
TOOL="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
88
# MODULE.bazel must be in the sh_test `data` deps so it appears as a
9-
# runfiles symlink; readlink -f then resolves it to the real workspace.
10-
# Without the data dep, readlink -f silently returns a bogus path.
11-
[ -e MODULE.bazel ] || { echo "MODULE.bazel missing from runfiles" >&2; exit 1; }
12-
WORKSPACE="$(cd "$(dirname "$(readlink -f MODULE.bazel)")" && pwd)"
9+
# runfiles symlink pointing at the real workspace. `readlink` (no -f,
10+
# for macOS portability) resolves the absolute path Bazel wrote.
11+
[ -L MODULE.bazel ] || { echo "MODULE.bazel missing from runfiles" >&2; exit 1; }
12+
WORKSPACE="$(dirname "$(readlink MODULE.bazel)")"
1313
cd "$WORKSPACE"
1414
# `git ls-files` skips submodule contents (src/sta, third-party/abc), so
1515
# we never try to reformat files owned by another repo.

0 commit comments

Comments
 (0)