Skip to content

Commit c8bee28

Browse files
redsun82Copilot
andcommitted
Just: name buildifier's binary by its external label
The alias existed only to give that binary a label in this workspace, which is precisely what stopped it working from anywhere else: a repository with this one checked out inside it cannot resolve `//misc/bazel/buildifier`, so it had to override `_bazel_formatter` just to name the same binary again. `@buildifier_prebuilt//:buildifier` resolves from any workspace and picks up whichever version that workspace pins, which is the behaviour the override was reproducing by hand. Also removes the second copy of the whole-workspace-versus-paths explanation, which the alias carried alongside the one in format.just. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent dd441b8 commit c8bee28

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

misc/bazel/buildifier/BUILD.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,3 @@ buildifier(
88
],
99
lint_mode = "fix",
1010
)
11-
12-
# The binary behind the target above, which formats the paths it is given rather than
13-
# always the whole workspace. `just format` goes through this so that formatting a
14-
# directory formats that directory.
15-
alias(
16-
name = "binary",
17-
actual = "@buildifier_prebuilt//:buildifier",
18-
)

misc/just/format.just

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ _py_formatter := if SEMMLE_CODE != "" { "uv run black" } else { "black" }
66

77
_cpp_formatter := if SEMMLE_CODE != "" { "uv run clang-format" } else { "clang-format" }
88

9-
# The `buildifier` bazel target always covers the whole workspace, so the binary behind
10-
# it is used instead and given paths. bazel is asked from the root of this repository,
11-
# even when it sits inside another, and the files are bounded to that root as well: each
12-
# repository then formats its own bazel files with the buildifier version it pins, and a
13-
# verb aimed at a tree spanning both is answered once by each. This is the opposite of
14-
# building, where a target needs the enclosing workspace to resolve at all, hence
15-
# `_bazel` in build.just going the other way.
9+
# The `buildifier` bazel target always covers the whole workspace, so the binary it wraps
10+
# is used instead and given paths. Naming that binary by its external label rather than
11+
# through a local alias keeps it valid from any workspace. bazel is asked from the root of
12+
# this repository, even when it sits inside another, and the files are bounded to that root
13+
# as well: each repository then formats its own bazel files with the buildifier version it
14+
# pins, and a verb aimed at a tree spanning both is answered once by each. This is the
15+
# opposite of building, where a target needs the enclosing workspace to resolve at all,
16+
# hence `_bazel` in build.just going the other way.
1617
_bazel_workspace := quote(parent_directory(parent_directory(source_dir())))
1718

18-
_bazel_formatter := "bazel run --noshow_progress --ui_event_filters=,+error,+fail //misc/bazel/buildifier:binary --"
19+
_bazel_formatter := "bazel run --noshow_progress --ui_event_filters=,+error,+fail @buildifier_prebuilt//:buildifier --"
1920

2021
# bazel files are named rather than suffixed, and buildifier has no exclude option of its
2122
# own, so the files skipped by the target above are skipped here too. That target formats

0 commit comments

Comments
 (0)