bazelbuild / bazelbuild/bazel

Incompatible target skipping behaves unintuitively for "paths" on the command line

Open
#13,019 10 comments 0 reactions 0 assignees View on GitHub
not stale P2 team-Configurability type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

This is a dedicated ticket for an issue mentioned in #12948.

With this root BUILD file:
```python
sh_test(
name = "bar",
srcs = ["BUILD"],
target_compatible_with = ["@platforms//:incompatible"],
)

genquery(
name = "query",
testonly = True,
expression = "//:bar",
scope = ["//:bar"],
)
```
If you run bazel build //:query you get this failure:
```console
% bazel build //:query
ERROR: Target //:query is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
//:query
//:bar <-- target platform didn't satisfy constraint //:incompatible
INFO: Elapsed time: 0.075s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 5 targets configured)
```
If you omit the //: from the target, it skips the genquery all together:
```console
% bazel build query
INFO: Analyzed target //:query (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:query was skipped
INFO: Elapsed time: 0.100s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```

As per @gregestren , the `query` is indeed treated as an implicit target. More accurately, it's a [`PATH_AS_TARGET`](https://github.com/bazelbuild/bazel/blob/97bc48d455048cfe873da429ac83aec6c0d347a1/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java#L1106) instead of a `SINGLE_TARGET`. That means the following logic doesn't get triggered:
https://github.com/bazelbuild/bazel/blob/97bc48d455048cfe873da429ac83aec6c0d347a1/src/main/java/com/google/devtools/build/lib/buildtool/AnalysisPhaseRunner.java#L342-L344

I think it would be reasonable for `bazel build query` to produce the same error about incompatbility.

Contributor guide

Open the contributing guide

Research direction

Reproduce the two commands using the root BUILD file shown in the issue, then read TargetPattern.java around PATH_AS_TARGET and AnalysisPhaseRunner.java around lines 342-344. Trace how command-line paths are classified and how incompatible explicitly requested targets are handled; done means bazel build query reports the same incompatibility error as bazel build //:query.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.