target_compatible_with targets silently skipped when explicitly passed with shorthand labels
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
With this project in the root BUILD.bazel file:
```bzl
constraint_setting(name = "something")
constraint_value(
name = "never_matched",
constraint_setting = ":something",
)
cc_test(
name = "foo",
srcs = ["foo.cc"],
target_compatible_with = [":never_matched"],
)
```
If you run `bazel test //:foo` it correctly fails:
```
% bazel test //:foo
Target //:foo failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: Analysis of target '//:foo' failed; build aborted: Target //:foo is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
//:foo (f0d937) <-- target platform (@@platforms//host:host) didn't satisfy constraint //:never_matched
INFO: Elapsed time: 0.523s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: No test targets were found, yet testing was requested
```
But if you use any shorthand label syntax it does not fail and is skipped like if you did `bazel test //...`:
```
% bazel test foo
INFO: Analyzed target //:foo (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
Target //:foo was skipped
INFO: Elapsed time: 0.123s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
//:foo SKIPPED
Executed 0 out of 1 test: 1 was skipped.
```
In this case where I still specify it directly, I would expect it to fail and not skip.
More confusingly if you do this in a nested BUILD file and use `/` instead of `:` it will also skip.
### Which category does this issue belong to?
_No response_
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
_No response_
### Which operating system are you running Bazel on?
_No response_
### What is the output of `bazel info release`?
055e80c00569e7f41646f809abd8bee2bea56d2a
### 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 HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
[repro.zip](https://github.com/user-attachments/files/21760121/repro.zip)
Contributor guide
Research direction
Start by unpacking repro.zip and running the root BUILD.bazel example with the explicit and shorthand bazel test commands shown in the issue; compare the nested BUILD-file case using '/'. Trace the target-selection and label-resolution entry points involved in those commands, then verify that explicitly requested incompatible targets fail while shorthand-selected targets retain their intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100