From 793b295ff4ccef97ea6a7ef9e2d976267c90e7f8 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 15 Nov 2022 21:56:46 -0500 Subject: [PATCH] Always include source files with --output=files --- site/en/query/cquery.md | 5 ++-- .../lib/query2/cquery/CqueryOptions.java | 8 ----- .../cquery/FilesOutputFormatterCallback.java | 8 ++--- .../FilesOutputFormatterCallbackTest.java | 30 +++---------------- .../integration/configured_query_test.sh | 8 +---- 5 files changed, 11 insertions(+), 48 deletions(-) diff --git a/site/en/query/cquery.md b/site/en/query/cquery.md index 2c6aefde34c0de..99ea8613585814 100644 --- a/site/en/query/cquery.md +++ b/site/en/query/cquery.md @@ -369,9 +369,8 @@ This option prints a list of the output files produced by each target matched by the query similar to the list printed at the end of a `bazel build` invocation. The output contains only the files advertised in the requested output groups as determined by the -[`--output_groups`](/reference/command-line-reference#flag--output_groups) flag -and does not contain source files unless `--files:include_source_files` is -specified. +[`--output_groups`](/reference/command-line-reference#flag--output_groups) flag. +It does include source files. Note: The output of `bazel cquery --output=files //pkg:foo` contains the output files of `//pkg:foo` in *all* configurations that occur in the build (also see diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryOptions.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryOptions.java index c2e670780f6522..0d85d0db680ea7 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryOptions.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/CqueryOptions.java @@ -107,12 +107,4 @@ public enum Transitions { + " error to specify both --starlark:expr and --starlark:file. See help for" + " --output=starlark for additional detail.") public String file; - - @Option( - name = "files:include_source_files", - defaultValue = "false", - documentationCategory = OptionDocumentationCategory.QUERY, - effectTags = {OptionEffectTag.TERMINAL_OUTPUT}, - help = "If true, source files are included in the output of cquery with --output=files.") - public boolean includeSourceFiles; } diff --git a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java index 619df99a316a27..48a5065a0ff11d 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java +++ b/src/main/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallback.java @@ -54,16 +54,16 @@ public void processOutput(Iterable partialResult) throws IOException, InterruptedException { for (KeyedConfiguredTarget keyedTarget : partialResult) { ConfiguredTarget target = keyedTarget.getConfiguredTarget(); - if (!TopLevelArtifactHelper.shouldConsiderForDisplay(target) && !(options.includeSourceFiles - && target instanceof InputFileConfiguredTarget)) { + if (!TopLevelArtifactHelper.shouldConsiderForDisplay(target) + && !(target instanceof InputFileConfiguredTarget)) { continue; } TopLevelArtifactHelper.getAllArtifactsToBuild(target, topLevelArtifactContext) .getImportantArtifacts() .toList() .stream() - .filter(artifact -> TopLevelArtifactHelper.shouldDisplay(artifact) || ( - artifact.isSourceArtifact() && options.includeSourceFiles)) + .filter(artifact -> TopLevelArtifactHelper.shouldDisplay(artifact) + || artifact.isSourceArtifact()) .map(Artifact::getExecPathString) .forEach(this::addResult); } diff --git a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java index 295bf048522a5c..317fd1169d5279 100644 --- a/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java +++ b/src/test/java/com/google/devtools/build/lib/query2/cquery/FilesOutputFormatterCallbackTest.java @@ -106,8 +106,7 @@ public final void setUpCqueryOptions() { this.reporter = new Reporter(new EventBus(), events::add); } - private List getOutput(String queryExpression, List outputGroups, - boolean includeSourceFiles) + private List getOutput(String queryExpression, List outputGroups) throws Exception { QueryExpression expression = QueryParser.parse(queryExpression, getDefaultFunctions()); Set targetPatternSet = new LinkedHashSet<>(); @@ -115,7 +114,6 @@ private List getOutput(String queryExpression, List outputGroups PostAnalysisQueryEnvironment env = ((ConfiguredTargetQueryHelper) helper).getPostAnalysisQueryEnvironment(targetPatternSet); - options.includeSourceFiles = includeSourceFiles; ByteArrayOutputStream output = new ByteArrayOutputStream(); FilesOutputFormatterCallback callback = new FilesOutputFormatterCallback( @@ -136,14 +134,7 @@ private List getOutput(String queryExpression, List outputGroups @Test public void basicQuery_defaultOutputGroup() throws Exception { - List output = getOutput("//pkg:all", ImmutableList.of(), false); - assertContainsExactlyWithBinDirPrefix( - output, "pkg/main_default_file", "pkg/other_default_file"); - } - - @Test - public void basicQuery_defaultOutputGroup_includeSourceFiles() throws Exception { - List output = getOutput("//pkg:all", ImmutableList.of(), true); + List output = getOutput("//pkg:all", ImmutableList.of()); var sourceAndGeneratedFiles = output.stream() .collect(Collectors.partitioningBy(path -> path.startsWith("bazel-out/"))); assertThat(sourceAndGeneratedFiles.get(false)).containsExactly("pkg/BUILD", "defs/rules.bzl"); @@ -153,14 +144,7 @@ public void basicQuery_defaultOutputGroup_includeSourceFiles() throws Exception @Test public void basicQuery_defaultAndCustomOutputGroup() throws Exception { - List output = getOutput("//pkg:main", ImmutableList.of("+foobar"), false); - assertContainsExactlyWithBinDirPrefix( - output, "pkg/main_default_file", "pkg/main_output_group_only"); - } - - @Test - public void basicQuery_defaultAndCustomOutputGroup_includeSourceFiles() throws Exception { - List output = getOutput("//pkg:main", ImmutableList.of("+foobar"), true); + List output = getOutput("//pkg:main", ImmutableList.of("+foobar")); var sourceAndGeneratedFiles = output.stream() .collect(Collectors.partitioningBy(path -> path.startsWith("bazel-out/"))); assertThat(sourceAndGeneratedFiles.get(false)).containsExactly("pkg/BUILD", "defs/rules.bzl"); @@ -170,13 +154,7 @@ public void basicQuery_defaultAndCustomOutputGroup_includeSourceFiles() throws E @Test public void basicQuery_customOutputGroupOnly() throws Exception { - List output = getOutput("//pkg:other", ImmutableList.of("foobar"), false); - assertContainsExactlyWithBinDirPrefix(output, "pkg/other_output_group_only"); - } - - @Test - public void basicQuery_customOutputGroupOnly_includeSourceFiles() throws Exception { - List output = getOutput("//pkg:other", ImmutableList.of("foobar"), true); + List output = getOutput("//pkg:other", ImmutableList.of("foobar")); var sourceAndGeneratedFiles = output.stream() .collect(Collectors.partitioningBy(path -> path.startsWith("bazel-out/"))); assertThat(sourceAndGeneratedFiles.get(false)).containsExactly("pkg/BUILD"); diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh index c77e2a3c66e764..391663d0dea460 100755 --- a/src/test/shell/integration/configured_query_test.sh +++ b/src/test/shell/integration/configured_query_test.sh @@ -1454,13 +1454,7 @@ alias(name="alias", actual="single_file") EOF touch $pkg/single_file - bazel cquery --output=files //$pkg:all \ - > output 2>"$TEST_log" || fail "Unexpected failure" - assert_not_contains "$pkg/BUILD" output - assert_not_contains "$pkg/single_file" output - - bazel cquery --output=files --files:include_source_files //$pkg:all \ - > output 2>"$TEST_log" || fail "Unexpected failure" + bazel cquery --output=files //$pkg:all > output 2>"$TEST_log" || fail "Unexpected failure" assert_contains "$pkg/BUILD" output assert_contains "$pkg/single_file" output }