Remove FilesToCompileProvider and CompilationPrerequisitesProvider and replace them with output groups.
--
MOS_MIGRATED_REVID=87038548
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
index bbe3f5f..5794965 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java
@@ -789,7 +789,9 @@
private static void scheduleTestsIfRequested(Collection<ConfiguredTarget> targetsToTest,
Collection<ConfiguredTarget> targetsToTestExclusive, TopLevelArtifactContext topLevelOptions,
Collection<ConfiguredTarget> allTestTargets) {
- if (!topLevelOptions.compileOnly() && !topLevelOptions.compilationPrerequisitesOnly()
+ Set<String> outputGroups = topLevelOptions.outputGroups();
+ if (!outputGroups.contains(TopLevelArtifactProvider.FILES_TO_COMPILE)
+ && !outputGroups.contains(TopLevelArtifactProvider.COMPILATION_PREREQUISITES)
&& allTestTargets != null) {
scheduleTests(targetsToTest, targetsToTestExclusive, allTestTargets,
topLevelOptions.runTestsExclusively());
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/CompilationPrerequisitesProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/CompilationPrerequisitesProvider.java
deleted file mode 100644
index 8c3a6ce..0000000
--- a/src/main/java/com/google/devtools/build/lib/analysis/CompilationPrerequisitesProvider.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2014 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.analysis;
-
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
-/**
- * A provider for compilation prerequisites of a given target.
- */
-@Immutable
-public final class CompilationPrerequisitesProvider implements TransitiveInfoProvider {
-
- private final NestedSet<Artifact> compilationPrerequisites;
-
- public CompilationPrerequisitesProvider(NestedSet<Artifact> compilationPrerequisites) {
- this.compilationPrerequisites = compilationPrerequisites;
- }
-
- /**
- * Returns compilation prerequisites (e.g., generated sources and headers) for a rule.
- */
- public NestedSet<Artifact> getCompilationPrerequisites() {
- return compilationPrerequisites;
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/FilesToCompileProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/FilesToCompileProvider.java
deleted file mode 100644
index 025392c..0000000
--- a/src/main/java/com/google/devtools/build/lib/analysis/FilesToCompileProvider.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2014 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.analysis;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
-/**
- * A {@link TransitiveInfoProvider} that provides files to be built when the {@code --compile_only}
- * command line option is in effect. This is to avoid expensive build steps when the user only
- * wants a quick syntax check.
- */
-@Immutable
-public final class FilesToCompileProvider implements TransitiveInfoProvider {
-
- private final ImmutableList<Artifact> filesToCompile;
-
- public FilesToCompileProvider(ImmutableList<Artifact> filesToCompile) {
- this.filesToCompile = filesToCompile;
- }
-
- /**
- * Returns the list of artifacts to be built when the {@code --compile_only} command line option
- * is in effect.
- */
- public ImmutableList<Artifact> getFilesToCompile() {
- return filesToCompile;
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java
index daa24ec..5a053c6 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleConfiguredTargetBuilder.java
@@ -56,6 +56,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.TreeMap;
/**
* Builder class for analyzed rule instances (i.e., instances of {@link ConfiguredTarget}).
@@ -65,8 +66,7 @@
private final Map<Class<? extends TransitiveInfoProvider>, TransitiveInfoProvider> providers =
new LinkedHashMap<>();
private final ImmutableMap.Builder<String, Object> skylarkProviders = ImmutableMap.builder();
- private final ImmutableMap.Builder<String, NestedSet<Artifact>> outputGroups =
- ImmutableMap.builder();
+ private final Map<String, NestedSetBuilder<Artifact>> outputGroupBuilders = new TreeMap<>();
/** These are supported by all configured targets and need to be specially handled. */
private NestedSet<Artifact> filesToBuild = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
@@ -92,9 +92,13 @@
return null;
}
- ImmutableMap<String, NestedSet<Artifact>> outputGroupMap = outputGroups.build();
- if (!outputGroupMap.isEmpty()) {
- add(TopLevelArtifactProvider.class, new TopLevelArtifactProvider(outputGroupMap));
+ if (!outputGroupBuilders.isEmpty()) {
+ ImmutableMap.Builder<String, NestedSet<Artifact>> outputGroups = ImmutableMap.builder();
+ for (Map.Entry<String, NestedSetBuilder<Artifact>> entry : outputGroupBuilders.entrySet()) {
+ outputGroups.put(entry.getKey(), entry.getValue().build());
+ }
+
+ add(TopLevelArtifactProvider.class, new TopLevelArtifactProvider(outputGroups.build()));
}
FilesToRunProvider filesToRunProvider = new FilesToRunProvider(ruleContext.getLabel(),
@@ -401,19 +405,41 @@
return this;
}
+ private NestedSetBuilder<Artifact> getOutputGroupBuilder(String name) {
+ NestedSetBuilder<Artifact> result = outputGroupBuilders.get(name);
+ if (result != null) {
+ return result;
+ }
+
+ result = NestedSetBuilder.<Artifact>stableOrder();
+ outputGroupBuilders.put(name, result);
+ return result;
+ }
+
/**
- * Add an output group.
+ * Adds a set of files to an output group.
*/
public RuleConfiguredTargetBuilder addOutputGroup(String name, NestedSet<Artifact> artifacts) {
- outputGroups.put(name, artifacts);
+ getOutputGroupBuilder(name).addTransitive(artifacts);
return this;
}
/**
- * Add an output group.
+ * Adds a file to an output group.
*/
public RuleConfiguredTargetBuilder addOutputGroup(String name, Artifact artifact) {
- outputGroups.put(name, NestedSetBuilder.create(Order.STABLE_ORDER, artifact));
+ getOutputGroupBuilder(name).add(artifact);
+ return this;
+ }
+
+ /**
+ * Adds multiple output groups.
+ */
+ public RuleConfiguredTargetBuilder addOutputGroups(Map<String, NestedSet<Artifact>> groups) {
+ for (Map.Entry<String, NestedSet<Artifact>> group : groups.entrySet()) {
+ getOutputGroupBuilder(group.getKey()).addTransitive(group.getValue());
+ }
+
return this;
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactContext.java b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactContext.java
index 85cd1a1..d4c1061 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactContext.java
@@ -27,24 +27,18 @@
public final class TopLevelArtifactContext {
public static final TopLevelArtifactContext DEFAULT = new TopLevelArtifactContext(
- "", /*compileOnly=*/false, /*compilationPrerequisitesOnly*/false,
- /*buildDefaultArtifacts=*/true, /*runTestsExclusively=*/false,
+ "", /*buildDefaultArtifacts=*/true, /*runTestsExclusively=*/false,
/*outputGroups=*/ImmutableSet.<String>of(), /*shouldRunTests=*/false);
private final String buildCommand;
- private final boolean compileOnly;
- private final boolean compilationPrerequisitesOnly;
private final boolean buildDefaultArtifacts;
private final boolean runTestsExclusively;
private final ImmutableSet<String> outputGroups;
private final boolean shouldRunTests;
- public TopLevelArtifactContext(String buildCommand, boolean compileOnly,
- boolean compilationPrerequisitesOnly, boolean filesToRun, boolean runTestsExclusively,
- ImmutableSet<String> outputGroups, boolean shouldRunTests) {
+ public TopLevelArtifactContext(String buildCommand, boolean filesToRun,
+ boolean runTestsExclusively, ImmutableSet<String> outputGroups, boolean shouldRunTests) {
this.buildCommand = buildCommand;
- this.compileOnly = compileOnly;
- this.compilationPrerequisitesOnly = compilationPrerequisitesOnly;
this.buildDefaultArtifacts = filesToRun;
this.runTestsExclusively = runTestsExclusively;
this.outputGroups = outputGroups;
@@ -56,16 +50,6 @@
return buildCommand;
}
- /** Returns the value of the --compile_only flag. */
- public boolean compileOnly() {
- return compileOnly;
- }
-
- /** Returns the value of the --compilation_prerequisites_only flag. */
- public boolean compilationPrerequisitesOnly() {
- return compilationPrerequisitesOnly;
- }
-
/** Returns the value of the (undocumented) --build_default_artifacts flag. */
public boolean buildDefaultArtifacts() {
return buildDefaultArtifacts;
@@ -93,8 +77,6 @@
if (other instanceof TopLevelArtifactContext) {
TopLevelArtifactContext otherContext = (TopLevelArtifactContext) other;
return buildCommand.equals(otherContext.buildCommand)
- && compileOnly == otherContext.compileOnly
- && compilationPrerequisitesOnly == otherContext.compilationPrerequisitesOnly
&& buildDefaultArtifacts == otherContext.buildDefaultArtifacts
&& runTestsExclusively == otherContext.runTestsExclusively
&& outputGroups.equals(otherContext.outputGroups)
@@ -106,7 +88,7 @@
@Override
public int hashCode() {
- return Objects.hash(buildCommand, compileOnly, compilationPrerequisitesOnly,
- buildDefaultArtifacts, runTestsExclusively, outputGroups, shouldRunTests);
+ return Objects.hash(
+ buildCommand, buildDefaultArtifacts, runTestsExclusively, outputGroups, shouldRunTests);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java
index 964df0d..44d1e27 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactHelper.java
@@ -128,18 +128,9 @@
}
}
- if (context.compileOnly()) {
- FilesToCompileProvider provider = target.getProvider(FilesToCompileProvider.class);
- if (provider != null) {
- importantBuilder.addAll(provider.getFilesToCompile());
- }
- } else if (context.compilationPrerequisitesOnly()) {
- CompilationPrerequisitesProvider provider =
- target.getProvider(CompilationPrerequisitesProvider.class);
- if (provider != null) {
- importantBuilder.addTransitive(provider.getCompilationPrerequisites());
- }
- } else if (context.buildDefaultArtifacts()) {
+ if (context.buildDefaultArtifacts()
+ && !context.outputGroups().contains(TopLevelArtifactProvider.COMPILATION_PREREQUISITES)
+ && !context.outputGroups().contains(TopLevelArtifactProvider.FILES_TO_COMPILE)) {
FilesToRunProvider filesToRunProvider = target.getProvider(FilesToRunProvider.class);
boolean hasRunfilesSupport = false;
if (filesToRunProvider != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactProvider.java
index c91b90f..f44fddb 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/TopLevelArtifactProvider.java
@@ -38,6 +38,8 @@
public final class TopLevelArtifactProvider implements TransitiveInfoProvider {
public static final String HIDDEN_OUTPUT_GROUP_PREFIX = "_";
public static final String BASELINE_COVERAGE = HIDDEN_OUTPUT_GROUP_PREFIX + "_baseline_coverage";
+ public static final String FILES_TO_COMPILE = "files_to_compile";
+ public static final String COMPILATION_PREREQUISITES = "compilation_prerequisites";
private final ImmutableMap<String, NestedSet<Artifact>> outputGroups;