Skip to content

Commit 6c171ff

Browse files
oharboeclaude
andcommitted
bazel: fix bzl lint tests and surface suppressed external-path warnings
lint_bzl_test and fmt_bzl_test used `readlink -f MODULE.bazel` to locate the workspace, but MODULE.bazel was not in their `data` deps so it was missing from the runfiles. `readlink -f` silently returns a path for a non-existent file, so WORKSPACE resolved to the runfiles directory (not a git repo) and the scripts failed with "fatal: not a git repository". Add MODULE.bazel to the `data` of lint_bzl_test, fmt_bzl_test, and fix_lint so the runfiles symlink is present. Switch the scripts to the same `cd ... && pwd` pattern used by the tcl lint scripts, and fail loudly with a clear message if the marker is ever missing again. With the tests now actually running, buildifier flagged two legitimate uses of the literal "external/<repo>" path in bison.bzl and flex.bzl; these strings deliberately rewrite runfiles paths back to the non- runfiles execroot layout so Bison/Flex can locate their data files when invoked as toolchain tools. Annotate with `# buildifier: disable=external-path`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 62d109c commit 6c171ff

5 files changed

Lines changed: 18 additions & 7 deletions

File tree

BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ sh_test(
512512
srcs = ["//bazel:bzl_lint_test.sh"],
513513
args = ["$(rootpath @buildifier_prebuilt//:buildifier)"],
514514
data = [
515+
"MODULE.bazel",
515516
"@buildifier_prebuilt//:buildifier",
516517
],
517518
tags = ["local"],
@@ -525,6 +526,7 @@ sh_test(
525526
srcs = ["//bazel:bzl_fmt_test.sh"],
526527
args = ["$(rootpath @buildifier_prebuilt//:buildifier)"],
527528
data = [
529+
"MODULE.bazel",
528530
"@buildifier_prebuilt//:buildifier",
529531
],
530532
tags = ["local"],
@@ -571,6 +573,7 @@ sh_binary(
571573
"$(rootpath @buildifier_prebuilt//:buildifier)",
572574
],
573575
data = [
576+
"MODULE.bazel",
574577
"tclint.toml",
575578
"//bazel:bzl_lint_test.sh",
576579
"//bazel:bzl_tidy.sh",

bazel/bison.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def correct_bison_env_for_action(env, bison):
2929

3030
bison_env["BISON_PKGDATADIR"] = bison_env["BISON_PKGDATADIR"].replace(
3131
bison_runfiles_dir,
32-
"external/{}".format(bison.owner.workspace_name),
32+
"external/{}".format(bison.owner.workspace_name), # buildifier: disable=external-path
3333
)
3434
bison_env["M4"] = bison_env["M4"].replace(
3535
bison_runfiles_dir,
36-
"{}/external/{}".format(bison.root.path, bison.owner.workspace_name),
36+
"{}/external/{}".format(bison.root.path, bison.owner.workspace_name), # buildifier: disable=external-path
3737
)
3838

3939
return bison_env

bazel/bzl_fmt_test.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#
55
# Check that all Bazel files are properly formatted (no lint warnings).
66
set -euo pipefail
7-
TOOL="$(readlink -f "$1")"
8-
WORKSPACE="$(dirname "$(readlink -f MODULE.bazel)")"
7+
TOOL="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
8+
# 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)"
913
cd "$WORKSPACE"
1014
# `git ls-files` skips submodule contents (src/sta, third-party/abc).
1115
# Explicit -mode=check -lint=off separates format errors from lint warnings,

bazel/bzl_lint_test.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#
55
# Lint all Bazel files using buildifier (check-only, with lint warnings).
66
set -euo pipefail
7-
TOOL="$(readlink -f "$1")"
8-
WORKSPACE="$(dirname "$(readlink -f MODULE.bazel)")"
7+
TOOL="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
8+
# 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)"
913
cd "$WORKSPACE"
1014
# `git ls-files` skips submodule contents (src/sta, third-party/abc), so
1115
# we never try to reformat files owned by another repo.

bazel/flex.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _correct_flex_env_for_action(env, flex):
2626
flex.owner.workspace_name,
2727
)
2828

29-
actual = "{}/external/{}".format(flex.root.path, flex.owner.workspace_name)
29+
actual = "{}/external/{}".format(flex.root.path, flex.owner.workspace_name) # buildifier: disable=external-path
3030

3131
for key, value in flex_env.items():
3232
flex_env[key] = value.replace(flex_runfiles_dir, actual)

0 commit comments

Comments
 (0)