Skip to content

Commit

Permalink
cquery inherits from test not build
Browse files Browse the repository at this point in the history
This makes directives like `test --test_arg=foo` present in `.bazelrc` files be
factored into the configuration hash for test targets.

See bazelbuild#13428 for extensive
context.

Closes bazelbuild#13491.

PiperOrigin-RevId: 382143334
  • Loading branch information
illicitonion committed Jul 13, 2021
1 parent 0cd1666 commit 7920ffe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@

/** Handles the 'cquery' command on the Blaze command line. */
@Command(
name = "cquery",
builds = true,
inherits = {BuildCommand.class},
options = {CqueryOptions.class},
usesConfigurationOptions = true,
shortDescription = "Loads, analyzes, and queries the specified targets w/ configurations.",
allowResidue = true,
completion = "label",
help = "resource:cquery.txt"
)
name = "cquery",
builds = true,
// We inherit from TestCommand so that we pick up changes like `test --test_arg=foo` in .bazelrc
// files.
// Without doing this, there is no easy way to use the output of cquery to determine whether a
// test has changed between two invocations, because the testrunner action is not easily
// introspectable.
inherits = {TestCommand.class},
options = {CqueryOptions.class},
usesConfigurationOptions = true,
shortDescription = "Loads, analyzes, and queries the specified targets w/ configurations.",
allowResidue = true,
completion = "label",
help = "resource:cquery.txt")
public final class CqueryCommand implements BlazeCommand {

@Override
Expand Down
23 changes: 23 additions & 0 deletions src/test/shell/integration/configured_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1232,4 +1232,27 @@ EOF
assert_equals $? 1
}

function test_test_arg_in_bazelrc() {
local -r pkg=$FUNCNAME
mkdir -p $pkg

cat >$pkg/BUILD <<EOF
sh_test(
name = "test",
srcs = ["test.sh"],
)
EOF

touch $pkg/test.sh
chmod +x $pkg/test.sh

output_before="$(bazel cquery "//$pkg:test")"

add_to_bazelrc "test --test_arg=foo"

output_after="$(bazel cquery "//$pkg:test")"

assert_not_equals "${output_before}" "${output_after}"
}

run_suite "${PRODUCT_NAME} configured query tests"

0 comments on commit 7920ffe

Please sign in to comment.