Add make-location lint for deprecated $(location) make variables (#1484) ## Summary - Add a new buildifier lint category, `make-location`, that flags deprecated `$(location)` and `$(locations)` make variables in BUILD files. - Dogfood the rule in this repo by replacing existing uses with `$(execpath ...)` and enforcing the lint via `//:make_location_lint`. ## Background / deprecation context Bazel's [`$(location)`](https://bazel.build/reference/be/make-variables) and [`$(locations)`](https://bazel.build/reference/be/make-variables) make variables are legacy pre-Starlark synonyms for [`$(execpath)`](https://bazel.build/reference/be/make-variables) and [`$(rootpath)`](https://bazel.build/reference/be/make-variables). 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](https://bazel.build/reference/be/make-variables) reference: > **`location`**: A synonym for either `execpath` or `rootpath`, depending on the attribute being expanded. This is legacy pre-Starlark behavior and **not recommended** unless you really know what it does for a particular rule. See [#2475](https://github.com/bazelbuild/bazel/issues/2475) for details. The underlying inconsistency is discussed in [bazelbuild/bazel#2475](https://github.com/bazelbuild/bazel/issues/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 ...)`](https://bazel.build/reference/be/make-variables) — path under the execroot where build actions run - [`$(rootpath ...)`](https://bazel.build/reference/be/make-variables) — runfiles-relative path for runtime lookup (prefer [`$(rlocationpath ...)`](https://bazel.build/reference/be/make-variables) for cross-platform runfiles) This lint nudges BUILD authors toward those explicit forms instead of the ambiguous legacy alias. ## Changes - New `make-location` warning in `warn/warn_bazel.go` (BUILD files only; does not flag `load("location", ...)`). - Tests, `WARNINGS.md` / `warnings.textproto` docs, and warning-list updates. - Repo fixes: `buildifier/BUILD.bazel`, `buildozer/BUILD.bazel`, `build/build_defs.bzl`. - New `buildifier_test` target `//:make_location_lint` added to `//:tests`. ## Test plan - [x] `bazel test //warn:warn_test --test_filter=TestMakeLocationVariable` - [x] `bazel test //warn/docs:docs_test` - [x] `bazel test //buildifier/config:config_test` - [x] `bazel test //:make_location_lint`
This repository contains developer tools for working with Google's bazel buildtool.
See instructions in each tool's directory.