Makefile: reduce duplicated nogo/linter work across bazel_build, bazel_lint, bazel_lint_changed, and bazel_test
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
`make bazel_build`, `make bazel_lint`, `make bazel_lint_changed`, and `make bazel_test` currently perform a large amount of overlapping `nogo` / linter work.
### Problem
Today `nogo` is already registered globally in the Go toolchain:
```bazel
go_register_toolchains(
nogo = "@//build:tidb_nogo",
)
```
That means `make bazel_test` already runs baseline `nogo` checks while compiling test targets.
At the same time:
- `make bazel_lint` runs `bazel build //... --//build:with_nogo_flag=true`
- `make bazel_lint_changed` runs the same strict `nogo` mode on changed packages
- `make bazel_build` also uses `--//build:with_nogo_flag=true`
So in a normal local workflow, these targets can re-run very similar analyzers on highly overlapping source sets.
### Evidence
From local analysis:
- `tidb_nogo` contains 132 analyzers in total
- 38 `x/tools` passes
- 23 custom analyzers
- 65 `staticcheck` analyzers
- 6 extra analyzers behind `with_nogo_flag=true`
- For **test files** specifically:
- `make bazel_test` already applies 117 analyzers
- `make bazel_lint` applies 119 analyzers
- the extra analyzers that actually reach test files are only `allrevive` and `constructor`
- `bazel build //... --//build:with_nogo_flag=true` in a cold local run took about 675s / 29320 actions
- `bazel_prepare` adds another ~62s in local lint workflows
This suggests that a large portion of local Bazel lint/build time is duplicated analysis work, especially when developers run multiple targets in sequence.
### Why this matters
The current setup makes it unclear which target is the canonical owner of which linter tier:
- `bazel_test` already covers a broad baseline
- `bazel_build` / `bazel_lint` / `bazel_lint_changed` add stricter checks, but also overlap heavily with that baseline
- test targets pay for many analyzer runs even when the extra signal is small
### Suggested direction
Define clearer analyzer tiers and target ownership, for example:
- keep a correctness-focused baseline in `bazel_test`
- move stricter/style-oriented analyzers into dedicated lint-only targets
- or scope the stricter analyzers away from `go_test` targets / test files when the signal is low
- or otherwise avoid re-running nearly identical `nogo` work across `bazel_build`, `bazel_lint`, `bazel_lint_changed`, and `bazel_test`
This issue is mainly about reducing duplicated local analysis work while keeping the same correctness guarantees.
Contributor guide
Assessment
This issue has not been assessed yet.