Description
Description of the feature request:
bazel query is a powerful tool, but the most common way to connect it to bazel build is through a shell's command substitution, such as:
bazel build $(bazel query 'deps(foo) - deps(bar)')
This works fine, despite being a bit of a syntactic mess, until the query starts returning too many targets, and then the command line grows too long and things start breaking. At which point you might do something like:
temp_file=$(mktemp)
bazel query --output_file=${temp_file} 'deps(foo) - deps(bar)'
bazel build --target_pattern_file=${temp_file}
Which is okay, but this is difficult enough that it usually isn't implemented until after something has broken, instead of just working from the beginning. It is also burdensome when invoking bazel programmatically, instead of from a command line, especially in environments that don't have a builtin way to produce a tmp file (such as node.js).
This pain could be resolved by allowing the query syntax to be passed to bazel build (or test, or coverage) invocations in a similar way to --target_pattern_file, but instead of reading a file to discover additional targets to add to the invocation, it would execute a bazel query.
The invocation would then look like this:
bazel build --query='deps(foo) - deps(bar)'
This would be more efficient than any of the current alternatives, and wouldn't run into command line size limits for large results.
Additionally, the existing --query_file flag that already exists on bazel query could be added to build too.
Which category does this issue belong to?
Core