From 7920ffef472b25db3f4e564e5a3a28a4664c666e Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Tue, 29 Jun 2021 12:40:44 -0700 Subject: [PATCH] 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 https://github.com/bazelbuild/bazel/issues/13428 for extensive context. Closes #13491. PiperOrigin-RevId: 382143334 --- .../lib/runtime/commands/CqueryCommand.java | 24 +++++++++++-------- .../integration/configured_query_test.sh | 23 ++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java index b35487d93c77d6..15d85764d6e90c 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java @@ -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 diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh index 128a270097609b..fb7b8069737157 100755 --- a/src/test/shell/integration/configured_query_test.sh +++ b/src/test/shell/integration/configured_query_test.sh @@ -1232,4 +1232,27 @@ EOF assert_equals $? 1 } +function test_test_arg_in_bazelrc() { + local -r pkg=$FUNCNAME + mkdir -p $pkg + + cat >$pkg/BUILD <