Skip to content

Add support for building queried targets in 1 command#27058

Closed
keith wants to merge 3 commits intomasterfrom
ks/add-support-for-build-query
Closed

Add support for building queried targets in 1 command#27058
keith wants to merge 3 commits intomasterfrom
ks/add-support-for-build-query

Conversation

@keith
Copy link
Member

@keith keith commented Sep 22, 2025

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' flag for building the result of a
bazel query in a single command

@keith keith force-pushed the ks/add-support-for-build-query branch from decad34 to 4307f8c Compare September 22, 2025 22:31
} catch (QueryException | InterruptedException | IOException e) {
throw new TargetPatternsHelperException(
"Error executing query: " + e.getMessage(),
TargetPatterns.Code.TARGET_PATTERNS_UNKNOWN);
Copy link
Member Author

Choose a reason for hiding this comment

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

idk what exit codes i should really use here, i didn't want to force all callers to handle this same logic, so I kept only this 1 exception type that they're already handling

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[inc]: Add 'build --query' flag for building the result of a
bazel query in a single command
@keith keith force-pushed the ks/add-support-for-build-query branch from 4307f8c to fbb7c00 Compare September 22, 2025 22:38
@keith keith force-pushed the ks/add-support-for-build-query branch from 3d6f761 to 2d3e949 Compare September 22, 2025 23:06
@keith keith changed the title Add support for 'build --query' Add support for building queried targets in 1 command Sep 22, 2025
@fmeum
Copy link
Collaborator

fmeum commented Sep 23, 2025

RELNOTES[NEW] seems more appropriate for a new flag, it's not an incompatible change.

if (!targets.isEmpty() && !buildRequestOptions.targetPatternFile.isEmpty()) {

int optionCount = 0;
if (!targets.isEmpty()) optionCount++;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a design reason that residue targets can't be mixed with a query?
I am specifically interested in how it interacts with --remote_download_outputs=toplevel, as that is one place where we use a query like this to download only certain files, while still building everything:

bazel test --remote_download_outputs=top-level //... $(bazel query 'attr(tags, ci-download-outputs, //...)')

I haven't figured out if there is an existing technical limitation that would make supporting that difficult.

Copy link
Member Author

Choose a reason for hiding this comment

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

nothing inherent, i inherited this logic from targetPatternFile and I haven't traced back why it was done for that case

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 tried to look back at why it was done for that case and didn't find anything conclusive. i assumed it was because it would be complicated with negations, but didn't find that discussed. Specifically I was thinking:

# foo.txt
//bar/...
bazel build --target_patterns_file=foo.txt -- -//bar:baz

seems potentially confusing, but maybe it would be fine. im going to try to add support for it for this feature either way

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This pull request has been marked as stale since it has not had any activity in the last 30 days. It will be closed in the next 30 days unless any other activity occurs. If you think this PR is still relevant and should stay open, please post any comment here and the PR will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Feb 18, 2026
@brentleyjones
Copy link
Contributor

@keith This would be awesome to land.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Feb 19, 2026
@keith
Copy link
Member Author

keith commented Mar 13, 2026

somehow i submitted this with a branch on this repo, which i don't think i was supposed to have access to do, re-opened over here #28996

@keith keith closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --query flag to bazel build

4 participants