Skip to content

Add support for building queried targets in 1 command#28996

Open
keith wants to merge 8 commits intobazelbuild:masterfrom
keith:ks/add-support-for-build-query
Open

Add support for building queried targets in 1 command#28996
keith wants to merge 8 commits intobazelbuild:masterfrom
keith:ks/add-support-for-build-query

Conversation

@keith
Copy link
Member

@keith keith commented Mar 13, 2026

This allows combining the common pattern of build and then query into a
single build command that executes the passed query (or query_file)

Fixes #26938

RELNOTES[NEW]: Add 'build --target_query' / --target_query_file flags for
building the result of a bazel query in a single command

keith added 4 commits March 13, 2026 12:32
This allows combining the common pattern of build and then query into a
single build command that executes the passed query (or query_file)

Fixes bazelbuild#26938

RELNOTES[inc]: Add 'build --query' flag for building the result of a
bazel query in a single command
List<String> queryTargets;
if (hasQuery) {
try {
queryTargets = executeQuery(env, buildRequestOptions.query, options);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know whether there are any, but it would be good to verify that bazel query options that affect the results of a query are taken into account here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you thinking options like --tool_deps or something else? since those aren't accepted by the arg parsing

StarlarkSemantics starlarkSemantics =
options.getOptions(BuildLanguageOptions.class).toStarlarkSemantics();
LabelPrinter labelPrinter =
new QueryOptions().getLabelPrinter(starlarkSemantics, mainRepoTargetParser.getRepoMapping());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we take the actual query options into account or leave a comment explaining why they don't matter (it's not super surprising given that this is about printing labels and we don't).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some could matter, like --notool_deps, but im not sure we want to expose all of those to the build command

@keith keith requested a review from fmeum March 13, 2026 22:36
@keith keith marked this pull request as ready for review March 18, 2026 05:33
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --query flag to bazel build

2 participants