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`
11 files changed
tree: 96249ffdd811fa2695144ef0a1374c78d911f6d7
  1. .bazelci/
  2. .github/
  3. api_proto/
  4. build/
  5. build_proto/
  6. buildifier/
  7. buildozer/
  8. bzlenv/
  9. config/
  10. convertast/
  11. deps_proto/
  12. differ/
  13. edit/
  14. extra_actions_base_proto/
  15. file/
  16. generatetables/
  17. labels/
  18. lang/
  19. release/
  20. tables/
  21. testutils/
  22. unused_deps/
  23. warn/
  24. wspace/
  25. .bazelrc
  26. .bazelversion
  27. .gitignore
  28. .mailmap
  29. .pre-commit-config.yaml
  30. BUILD.bazel
  31. CODEOWNERS
  32. CONTRIBUTING.md
  33. CONTRIBUTORS
  34. go.mod
  35. go.sum
  36. launcher.js
  37. LICENSE
  38. MODULE.bazel
  39. README.md
  40. status.py
  41. update_generated.sh
  42. WARNINGS.md
  43. WORKSPACE
  44. WORKSPACE.bzlmod
README.md

Buildtools for bazel

This repository contains developer tools for working with Google's bazel buildtool.

Build status

Setup

See instructions in each tool's directory.