Add make-location lint for deprecated $(location) make variables - #1484
Open
alexeagle wants to merge 2 commits into
Open
Add make-location lint for deprecated $(location) make variables#1484alexeagle wants to merge 2 commits into
alexeagle wants to merge 2 commits into
Conversation
Flag $(location) and $(locations) in BUILD files in favor of explicit $(execpath ...) or $(rootpath ...), dogfood the rule in this repo, and enforce it via a buildifier_test over the workspace.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
sh_test scripts pass args through rlocation, which expects runfiles paths like the legacy $(location) expansion, not execroot paths.
Contributor
Author
|
FYI @Wyverald as you mentioned this team is considering donating to bazel-contrib, I've got more PRs like this to improve the tool... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
make-location, that flags deprecated$(location)and$(locations)make variables in BUILD files.$(execpath ...)and enforcing the lint via//:make_location_lint.Background / deprecation context
Bazel's
$(location)and$(locations)make variables are legacy pre-Starlark synonyms for$(execpath)and$(rootpath). Which path they expand to depends on the attribute being expanded, which makes behavior hard to predict and easy to get wrong.From the Make Variables reference:
The underlying inconsistency is discussed in bazelbuild/bazel#2475 (e.g.
$(location)expanding to an exec path in some attributes but a runfiles path in others). Bazel's docs now steer users toward explicit variables:$(execpath ...)— path under the execroot where build actions run$(rootpath ...)— runfiles-relative path for runtime lookup (prefer$(rlocationpath ...)for cross-platform runfiles)This lint nudges BUILD authors toward those explicit forms instead of the ambiguous legacy alias.
Changes
make-locationwarning inwarn/warn_bazel.go(BUILD files only; does not flagload("location", ...)).WARNINGS.md/warnings.textprotodocs, and warning-list updates.buildifier/BUILD.bazel,buildozer/BUILD.bazel,build/build_defs.bzl.buildifier_testtarget//:make_location_lintadded to//:tests.Test plan
bazel test //warn:warn_test --test_filter=TestMakeLocationVariablebazel test //warn/docs:docs_testbazel test //buildifier/config:config_testbazel test //:make_location_lint