From 9f67cdf3d51c05bc2209786aa24b72658b61362c Mon Sep 17 00:00:00 2001 From: gregce Date: Mon, 2 Aug 2021 16:24:22 -0700 Subject: [PATCH] cquery: disable `--build_tests_only`. PriorityCategory.SOFTWARE_REQUIREMENT cannot be overridden by the user, unlike PriorityCategory.COMPUTED_DEFAULT. Also another existing flag that I think deserves the same enforcement. Re: concerns about aquery: none of this affects aquery because aquery doesn't inherit from TestCommand: https://github.com/bazelbuild/bazel/blob/a03442dd7408cdc6ef936f96cd3146ff6b3d09dd/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java#L56 https://github.com/bazelbuild/bazel/blob/a03442dd7408cdc6ef936f96cd3146ff6b3d09dd/src/main/java/com/google/devtools/build/lib/runtime/commands/AqueryCommand.java#L48 PiperOrigin-RevId: 388330077 --- .../build/lib/runtime/commands/CqueryCommand.java | 6 +++++- .../shell/integration/configured_query_test.sh | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 89d1a97a49d44c..7f30a18e749fe7 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 @@ -81,7 +81,7 @@ public void editOptions(OptionsParser optionsParser) { "cquery should include 'tags = [\"manual\"]' targets by default", ImmutableList.of("--build_manual_tests")); optionsParser.parse( - PriorityCategory.COMPUTED_DEFAULT, + PriorityCategory.SOFTWARE_REQUIREMENT, // https://github.com/bazelbuild/bazel/issues/11078 "cquery should not exclude test_suite rules", ImmutableList.of("--noexpand_test_suites")); @@ -93,6 +93,10 @@ public void editOptions(OptionsParser optionsParser) { "--include_config_fragments_provider=" + cqueryOptions.showRequiredConfigFragments)); } + optionsParser.parse( + PriorityCategory.SOFTWARE_REQUIREMENT, + "cquery should not exclude tests", + ImmutableList.of("--nobuild_tests_only")); } catch (OptionsParsingException e) { throw new IllegalStateException("Cquery's known options failed to parse", e); } diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh index 9e4a89d8ea41b3..bc5c48e9d34ae0 100755 --- a/src/test/shell/integration/configured_query_test.sh +++ b/src/test/shell/integration/configured_query_test.sh @@ -819,6 +819,20 @@ EOF assert_contains "//$pkg:my_test" output } +function test_build_tests_only_override() { + local -r pkg=$FUNCNAME + mkdir -p $pkg + cat > $pkg/BUILD <<'EOF' +cc_binary( + name = "not_a_test", + srcs = ["not_a_test.cc"]) +EOF + + bazel cquery --build_tests_only "//$pkg:all" > output 2>"$TEST_log" || \ + fail "Expected success" + assert_contains "//$pkg:not_a_test" output +} + function test_label_output_shows_alias_labels() { local -r pkg=$FUNCNAME mkdir -p $pkg