bazelbuild / bazelbuild/bazel

cquery output doesn't reflect test configuration trimming

Open
#20,757 1 comment 0 reactions 0 assignees View on GitHub
P2 team-Configurability type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

When `--trim_test_configuration` is enabled, the output of `cquery` can't be used to traverse `ConfiguredTarget` dependency edges.

If you clone https://github.com/illicitonion/repro-bazel-cquery-trim-test-configuration you can see the following chain of dependencies:

`//:cowsay_test` -> `@pip_parse//cowsay:pkg` -> `@pip_parse_cowpy//:pkg`

If you run `bazel cquery --output=jsonproto --transitions=lite 'deps(//:cowsay_test)'` you'll see:

* `//:cowsay_test` is in the target configuration and that configuration contains a `com.google.devtools.build.lib.analysis.test.TestConfiguration$TestOptions` fragment. Its `ruleInputs` contains `@pip_parse//cowpy:pkg` and its `configuredRuleInputs` contains `@pip_parse//cowpy:pkg` with no explicit configuration (i.e. no transition).
* `@pip_parse//cowpy:pkg` (an `alias` target) appears in the same configuration, and has a `ruleInput` of `@pip_parse_cowpy//:pkg` and no `configuredRuleInputs`.
* `@pip_parse_cowpy//:pkg` appears in a different configuration - this is the same configuration as the target configuration but doesn't have a `com.google.devtools.build.lib.analysis.test.TestConfiguration$TestOptions` fragment.

If you run the same cquery with `--trim_test_configuration` disabled, all three appear in the same configuration.

I think there are a few surprises/bugs in here:
1. I'm surprised that the `alias` target appears to be the one where the test fragment trimming happens - I would've expected that on the edge from the test target to the `alias`, rather than within the `alias`.
2. `@pip_parse//cowpy:pkg` should contain `@pip_parse_cowpy//:pkg` in its `configuredRuleInputs`.
3. _Something_ should explicitly give the configuration - if the `alias` is where the transition happens, its `configuredRuleInputs` should list its target in the trimmed configuration, or if the `py_test` is what should be transitioning, its `configuredRuleInputs` should contain the trimmed configuration.

### Which category does this issue belong to?

Configurability

### 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`?

release 7.0.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` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_No response_

### 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

Open the contributing guide

Research direction

Start by reproducing the reported `bazel cquery --output=jsonproto --transitions=lite 'deps(//:cowsay_test)'` query with and without `--trim_test_configuration` using the linked example repository. Inspect the configurations, `ruleInputs`, and `configuredRuleInputs` for the three targets. Done means the JSON output explicitly and consistently represents the configuration transition and dependency edges in both modes.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, cli
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.