Bazel 6.x: Mismatched target_configured and target_completed events with aspects
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
If `//:x.bzl` re-exports the aspect `bar` defined in `//:private/x.bzl`, then applying `//:x.bzl%bar` yields a BES with mismatched aspect labels in the events: `target_configured` has `aspect: "//:x.bzl%bar"` but `target_completed` has `aspect: "//:private/x.bzl%bar"`.
The bug is fixed in Bazel 7 by https://github.com/bazelbuild/bazel/commit/5cd3d872ffa24c7816cc2962dc3e989b68ef7f79. There, both events have `aspect: "//:private/x.bzl%bar"`.
Filing this issue as a placeholder -- ultimately I'd like to cherry-pick this to the 6.x branch.
### Which category does this issue belong to?
Core, Remote Execution
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
You'll need to send the BES somewhere and dump the tool events.
Create an empty workspace, and these files:
`BUILD`:
```
genrule(
name = "x",
srcs = ["BUILD"],
outs = ["x.out"],
cmd = "echo $$FOO > $@",
)
```
`x.bzl`:
```
load("//:private/x.bzl", _bar = "bar")
bar = _bar
```
`private/x.bzl`:
```
def _impl(target, ctx):
return []
bar = aspect(
implementation = _impl,
attr_aspects = ["srcs"],
)
```
Then, build with Bazel 6.4.0 (or 6.5.0-rc1; it has the same bug):
```
echo "6.4.0" > .bazelversion
bazel \
--batch \
--ignore_all_rc_files \
build \
--bes_results_url=https://[YOUR_BES_SERVICE]/invocation/ \
--bes_backend=grpcs://[YOUR_BES_SERVICE] \
--aspects x.bzl%bar \
--action_env FOO=$RANDOM \
//:x
```
### Which operating system are you running Bazel on?
linux x86-64
### What is the output of `bazel info release`?
release 6.4.0
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
```text
n/a
```
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
All older Bazel versions I tried (6.4.0, 6.0.0, 5.4.0, 4.2.0) exhibit this issue. But it is fixed in Bazel 7.0.0.
The Bazel commit that **fixed** it was https://github.com/bazelbuild/bazel/commit/5cd3d872ffa24c7816cc2962dc3e989b68ef7f79
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Review the linked Bazel 7 fix commit, then reproduce the issue using BUILD, x.bzl, and private/x.bzl with Bazel 6.4.0 and a BES backend. Compare the aspect labels in target_configured and target_completed events; done means the 6.x behavior matches the corrected label handling and the reproduction no longer shows a mismatch.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100