Skip to content

Commit 7920ffe

Browse files
committed
cquery inherits from test not build
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
1 parent 0cd1666 commit 7920ffe

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@
4646

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

6165
@Override

src/test/shell/integration/configured_query_test.sh

+23
Original file line numberDiff line numberDiff line change
@@ -1232,4 +1232,27 @@ EOF
12321232
assert_equals $? 1
12331233
}
12341234

1235+
function test_test_arg_in_bazelrc() {
1236+
local -r pkg=$FUNCNAME
1237+
mkdir -p $pkg
1238+
1239+
cat >$pkg/BUILD <<EOF
1240+
sh_test(
1241+
name = "test",
1242+
srcs = ["test.sh"],
1243+
)
1244+
EOF
1245+
1246+
touch $pkg/test.sh
1247+
chmod +x $pkg/test.sh
1248+
1249+
output_before="$(bazel cquery "//$pkg:test")"
1250+
1251+
add_to_bazelrc "test --test_arg=foo"
1252+
1253+
output_after="$(bazel cquery "//$pkg:test")"
1254+
1255+
assert_not_equals "${output_before}" "${output_after}"
1256+
}
1257+
12351258
run_suite "${PRODUCT_NAME} configured query tests"

0 commit comments

Comments
 (0)