diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD
index 367f5da856abf6..472f6a83aa9e2e 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD
@@ -1581,10 +1581,8 @@ java_library(
":config/fragment_options",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
- "//src/main/java/com/google/devtools/build/lib/skyframe/trimming:trimmed_configuration_cache",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/common/options",
- "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
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 077e6523122c9e..0801c6065fb6e4 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
@@ -100,49 +100,44 @@
import javax.annotation.Nullable;
/**
- * The BuildView presents a semantically-consistent and transitively-closed
- * dependency graph for some set of packages.
+ * The BuildView presents a semantically-consistent and transitively-closed dependency graph for
+ * some set of packages.
*
*
Package design
*
- * This package contains the Blaze dependency analysis framework (aka
- * "analysis phase"). The goal of this code is to perform semantic analysis of
- * all of the build targets required for a given build, to report
- * errors/warnings for any problems in the input, and to construct an "action
- * graph" (see {@code lib.actions} package) correctly representing the work to
- * be done during the execution phase of the build.
+ *
This package contains the Blaze dependency analysis framework (aka "analysis phase"). The goal
+ * of this code is to perform semantic analysis of all of the build targets required for a given
+ * build, to report errors/warnings for any problems in the input, and to construct an "action
+ * graph" (see {@code lib.actions} package) correctly representing the work to be done during the
+ * execution phase of the build.
*
- *
Configurations the inputs to a build come from two sources: the
- * intrinsic inputs, specified in the BUILD file, are called targets .
- * The environmental inputs, coming from the build tool, the command-line, or
- * configuration files, are called the configuration . Only when a
- * target and a configuration are combined is there sufficient information to
- * perform a build.
+ * Configurations the inputs to a build come from two sources: the intrinsic inputs,
+ * specified in the BUILD file, are called targets . The environmental inputs, coming from
+ * the build tool, the command-line, or configuration files, are called the configuration .
+ * Only when a target and a configuration are combined is there sufficient information to perform a
+ * build.
*
- *
Targets are implemented by the {@link Target} hierarchy in the {@code
- * lib.packages} code. Configurations are implemented by {@link
- * BuildConfiguration}. The pair of these together is represented by an
- * instance of class {@link ConfiguredTarget}; this is the root of a hierarchy
- * with different implementations for each kind of target: source file, derived
- * file, rules, etc.
+ *
Targets are implemented by the {@link Target} hierarchy in the {@code lib.packages} code.
+ * Configurations are implemented by {@link BuildConfiguration}. The pair of these together is
+ * represented by an instance of class {@link ConfiguredTarget}; this is the root of a hierarchy
+ * with different implementations for each kind of target: source file, derived file, rules, etc.
+ *
+ *
The framework code in this package (as opposed to its subpackages) is responsible for
+ * constructing the {@code ConfiguredTarget} graph for a given target and configuration, taking care
+ * of such issues as:
*
- *
The framework code in this package (as opposed to its subpackages) is
- * responsible for constructing the {@code ConfiguredTarget} graph for a given
- * target and configuration, taking care of such issues as:
*
* caching common subgraphs.
* detecting and reporting cycles.
* correct propagation of errors through the graph.
- * reporting universal errors, such as dependencies from production code
- * to tests, or to experimental branches.
+ * reporting universal errors, such as dependencies from production code to tests, or to
+ * experimental branches.
* capturing and replaying errors.
- * maintaining the graph from one build to the next to
- * avoid unnecessary recomputation.
+ * maintaining the graph from one build to the next to avoid unnecessary recomputation.
* checking software licenses.
*
*
- * See also {@link ConfiguredTarget} which documents some important
- * invariants.
+ *
See also {@link ConfiguredTarget} which documents some important invariants.
*/
public class BuildView {
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
@@ -154,12 +149,11 @@ public class BuildView {
private final ConfiguredRuleClassProvider ruleClassProvider;
- /**
- * A factory class to create the coverage report action. May be null.
- */
+ /** A factory class to create the coverage report action. May be null. */
@Nullable private final CoverageReportActionFactory coverageReportActionFactory;
- public BuildView(BlazeDirectories directories,
+ public BuildView(
+ BlazeDirectories directories,
ConfiguredRuleClassProvider ruleClassProvider,
SkyframeExecutor skyframeExecutor,
CoverageReportActionFactory coverageReportActionFactory) {
@@ -191,8 +185,7 @@ private ArtifactFactory getArtifactFactory() {
@VisibleForTesting
static LinkedHashSet filterTestsByTargets(
Collection targets, Set allowedTargetLabels) {
- return targets
- .stream()
+ return targets.stream()
.filter(ct -> allowedTargetLabels.contains(ct.getLabel()))
.collect(Collectors.toCollection(LinkedHashSet::new));
}
@@ -228,8 +221,9 @@ public AnalysisResult update(
if (viewOptions.skyframePrepareAnalysis) {
PrepareAnalysisPhaseValue prepareAnalysisPhaseValue;
try (SilentCloseable c = Profiler.instance().profile("Prepare analysis phase")) {
- prepareAnalysisPhaseValue = skyframeExecutor.prepareAnalysisPhase(
- eventHandler, targetOptions, multiCpu, loadingResult.getTargetLabels());
+ prepareAnalysisPhaseValue =
+ skyframeExecutor.prepareAnalysisPhase(
+ eventHandler, targetOptions, multiCpu, loadingResult.getTargetLabels());
// Determine the configurations
configurations =
@@ -243,12 +237,7 @@ public AnalysisResult update(
// needed. This requires cleaning up the invalidation in SkyframeBuildView.setConfigurations.
try (SilentCloseable c = Profiler.instance().profile("createConfigurations")) {
configurations =
- skyframeExecutor
- .createConfigurations(
- eventHandler,
- targetOptions,
- multiCpu,
- keepGoing);
+ skyframeExecutor.createConfigurations(eventHandler, targetOptions, multiCpu, keepGoing);
}
try (SilentCloseable c = Profiler.instance().profile("AnalysisUtils.getTargetsWithConfigs")) {
topLevelTargetsWithConfigsResult =
@@ -261,10 +250,9 @@ public AnalysisResult update(
eventHandler, configurations, viewOptions.maxConfigChangesToShow);
if (configurations.getTargetConfigurations().size() == 1) {
- eventBus
- .post(
- new MakeEnvironmentEvent(
- configurations.getTargetConfigurations().get(0).getMakeEnvironment()));
+ eventBus.post(
+ new MakeEnvironmentEvent(
+ configurations.getTargetConfigurations().get(0).getMakeEnvironment()));
}
for (BuildConfiguration targetConfig : configurations.getTargetConfigurations()) {
eventBus.post(targetConfig.toBuildEvent());
@@ -274,8 +262,7 @@ public AnalysisResult update(
topLevelTargetsWithConfigsResult.getTargetsAndConfigs();
// Report the generated association of targets to configurations
- Multimap byLabel =
- ArrayListMultimap.create();
+ Multimap byLabel = ArrayListMultimap.create();
for (TargetAndConfiguration pair : topLevelTargetsWithConfigs) {
byLabel.put(pair.getLabel(), pair.getConfiguration());
}
@@ -334,13 +321,6 @@ public AnalysisResult update(
String starlarkFunctionName = aspect.substring(delimiterPosition + 1);
for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) {
- if (targetSpec.getConfiguration() != null
- && targetSpec.getConfiguration().trimConfigurationsRetroactively()) {
- String errorMessage =
- "Aspects were requested, but are not supported in retroactive trimming mode.";
- throw new ViewCreationFailedException(
- errorMessage, createFailureDetail(errorMessage, Analysis.Code.ASPECT_PREREQ_UNMET));
- }
aspectConfigurations.put(
Pair.of(targetSpec.getLabel(), aspect), targetSpec.getConfiguration());
aspectKeys.add(
@@ -359,14 +339,6 @@ public AnalysisResult update(
if (aspectFactoryClass != null) {
for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) {
- if (targetSpec.getConfiguration() != null
- && targetSpec.getConfiguration().trimConfigurationsRetroactively()) {
- String errorMessage =
- "Aspects were requested, but are not supported in retroactive trimming mode.";
- throw new ViewCreationFailedException(
- errorMessage,
- createFailureDetail(errorMessage, Analysis.Code.ASPECT_PREREQ_UNMET));
- }
// For invoking top-level aspects, use the top-level configuration for both the
// aspect and the base target while the top-level configuration is untrimmed.
BuildConfiguration configuration = targetSpec.getConfiguration();
@@ -445,8 +417,10 @@ public AnalysisResult update(
int numTargetsToAnalyze = topLevelTargetsWithConfigs.size();
int numSuccessful = skyframeAnalysisResult.getConfiguredTargets().size();
if (0 < numSuccessful && numSuccessful < numTargetsToAnalyze) {
- String msg = String.format("Analysis succeeded for only %d of %d top-level targets",
- numSuccessful, numTargetsToAnalyze);
+ String msg =
+ String.format(
+ "Analysis succeeded for only %d of %d top-level targets",
+ numSuccessful, numTargetsToAnalyze);
eventHandler.handle(Event.info(msg));
logger.atInfo().log(msg);
}
@@ -765,7 +739,7 @@ private static Pair, ImmutableSet targetsToTest = ImmutableSet.builder();
ImmutableSet.Builder targetsToTestExclusive = ImmutableSet.builder();
for (ConfiguredTarget configuredTarget : allTestTargets) {
- Target target = null;
+ Target target;
try {
target = packageManager.getTarget(eventHandler, configuredTarget.getLabel());
} catch (NoSuchTargetException | NoSuchPackageException e) {
@@ -795,10 +769,10 @@ private void setArtifactRoots(PackageRoots packageRoots) {
}
/**
- * Tests and clears the current thread's pending "interrupted" status, and
- * throws InterruptedException iff it was set.
+ * Tests and clears the current thread's pending "interrupted" status, and throws
+ * InterruptedException iff it was set.
*/
- private final void pollInterruptedStatus() throws InterruptedException {
+ private static void pollInterruptedStatus() throws InterruptedException {
if (Thread.interrupted()) {
throw new InterruptedException();
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/CachingAnalysisEnvironment.java b/src/main/java/com/google/devtools/build/lib/analysis/CachingAnalysisEnvironment.java
index 35b3fc0edb8bcd..aa53a09c8ec4e1 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/CachingAnalysisEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/CachingAnalysisEnvironment.java
@@ -55,22 +55,15 @@
/**
* The implementation of AnalysisEnvironment used for analysis. It tracks metadata for each
- * configured target, such as the errors and warnings emitted by that target. It is intended that
- * a separate instance is used for each configured target, so that these don't mix up.
+ * configured target, such as the errors and warnings emitted by that target. It is intended that a
+ * separate instance is used for each configured target, so that these don't mix up.
*/
-public class CachingAnalysisEnvironment implements AnalysisEnvironment {
- private final ArtifactFactory artifactFactory;
+public final class CachingAnalysisEnvironment implements AnalysisEnvironment {
+ private final ArtifactFactory artifactFactory;
private final ActionLookupKey owner;
- /**
- * If this is the system analysis environment, then errors and warnings are directly reported
- * to the global reporter, rather than stored, i.e., we don't track here whether there are any
- * errors.
- */
- private final boolean isSystemEnv;
private final boolean extendedSanityChecks;
private final boolean allowAnalysisFailures;
-
private final ActionKeyContext actionKeyContext;
private boolean enabled = true;
@@ -88,19 +81,18 @@ public class CachingAnalysisEnvironment implements AnalysisEnvironment {
*
* The artifact is stored so that we can deduplicate artifacts created multiple times.
*/
- private Map artifacts;
+ private Map artifacts = new HashMap<>();
/**
* The list of actions registered by the configured target this analysis environment is
* responsible for. May get cleared out at the end of the analysis of said target.
*/
- final List actions = new ArrayList<>();
+ private final List actions = new ArrayList<>();
public CachingAnalysisEnvironment(
ArtifactFactory artifactFactory,
ActionKeyContext actionKeyContext,
ActionLookupKey owner,
- boolean isSystemEnv,
boolean extendedSanityChecks,
boolean allowAnalysisFailures,
ExtendedEventHandler errorEventListener,
@@ -109,14 +101,12 @@ public CachingAnalysisEnvironment(
this.artifactFactory = artifactFactory;
this.actionKeyContext = actionKeyContext;
this.owner = Preconditions.checkNotNull(owner);
- this.isSystemEnv = isSystemEnv;
this.extendedSanityChecks = extendedSanityChecks;
this.allowAnalysisFailures = allowAnalysisFailures;
this.errorEventListener = errorEventListener;
this.skyframeEnv = env;
this.starlarkBuiltinsValue = starlarkBuiltinsValue;
middlemanFactory = new MiddlemanFactory(artifactFactory, this);
- artifacts = new HashMap<>();
}
public void disable(Target target) {
@@ -146,7 +136,7 @@ private static StringBuilder shortDescription(ActionAnalysisMetadata action) {
*/
public void verifyGeneratedArtifactHaveActions(Target target) {
Collection orphanArtifacts = getOrphanArtifactMap().values();
- List checkedActions = null;
+ List checkedActions;
if (!orphanArtifacts.isEmpty()) {
checkedActions = Lists.newArrayListWithCapacity(actions.size());
for (ActionAnalysisMetadata action : actions) {
@@ -244,10 +234,6 @@ public ActionKeyContext getActionKeyContext() {
@Override
public boolean hasErrors() {
- // The system analysis environment never has errors.
- if (isSystemEnv) {
- return false;
- }
Preconditions.checkState(enabled);
return ((StoredEventHandler) errorEventListener).hasErrors();
}
@@ -295,7 +281,7 @@ public Artifact.DerivedArtifact getDerivedArtifact(
PathFragment rootRelativePath, ArtifactRoot root, boolean contentBasedPath) {
Preconditions.checkState(enabled);
return dedupAndTrackArtifactAndOrigin(
- artifactFactory.getDerivedArtifact(rootRelativePath, root, getOwner(), contentBasedPath),
+ artifactFactory.getDerivedArtifact(rootRelativePath, root, owner, contentBasedPath),
extendedSanityChecks ? new Throwable() : null);
}
@@ -304,7 +290,7 @@ public SpecialArtifact getTreeArtifact(PathFragment rootRelativePath, ArtifactRo
Preconditions.checkState(enabled);
return (SpecialArtifact)
dedupAndTrackArtifactAndOrigin(
- artifactFactory.getTreeArtifact(rootRelativePath, root, getOwner()),
+ artifactFactory.getTreeArtifact(rootRelativePath, root, owner),
extendedSanityChecks ? new Throwable() : null);
}
@@ -313,7 +299,7 @@ public SpecialArtifact getSymlinkArtifact(PathFragment rootRelativePath, Artifac
Preconditions.checkState(enabled);
return (SpecialArtifact)
dedupAndTrackArtifactAndOrigin(
- artifactFactory.getSymlinkArtifact(rootRelativePath, root, getOwner()),
+ artifactFactory.getSymlinkArtifact(rootRelativePath, root, owner),
extendedSanityChecks ? new Throwable() : null);
}
@@ -327,13 +313,13 @@ public Artifact.DerivedArtifact getFilesetArtifact(
PathFragment rootRelativePath, ArtifactRoot root) {
Preconditions.checkState(enabled);
return dedupAndTrackArtifactAndOrigin(
- artifactFactory.getFilesetArtifact(rootRelativePath, root, getOwner()),
+ artifactFactory.getFilesetArtifact(rootRelativePath, root, owner),
extendedSanityChecks ? new Throwable() : null);
}
@Override
public Artifact getConstantMetadataArtifact(PathFragment rootRelativePath, ArtifactRoot root) {
- return artifactFactory.getConstantMetadataArtifact(rootRelativePath, root, getOwner());
+ return artifactFactory.getConstantMetadataArtifact(rootRelativePath, root, owner);
}
@Override
@@ -363,12 +349,12 @@ public SkyFunction.Environment getSkyframeEnv() {
}
@Override
- public StarlarkSemantics getStarlarkSemantics() throws InterruptedException {
+ public StarlarkSemantics getStarlarkSemantics() {
return starlarkBuiltinsValue.starlarkSemantics;
}
@Override
- public ImmutableMap getStarlarkDefinedBuiltins() throws InterruptedException {
+ public ImmutableMap getStarlarkDefinedBuiltins() {
return starlarkBuiltinsValue.exportedToJava;
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index ad63bb92140364..fbd8e11f81c5af 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -768,14 +768,6 @@ public boolean trimConfigurations() {
return options.configsMode == CoreOptions.ConfigsMode.ON;
}
- /**
- * Returns whether we should trim configurations to only include the fragments needed to correctly
- * analyze a rule.
- */
- public boolean trimConfigurationsRetroactively() {
- return options.configsMode == CoreOptions.ConfigsMode.RETROACTIVE;
- }
-
/**
* >Experimental feature: if true, qualifying outputs use path prefixes based on their
* content instead of the traditional blaze-out/$CPU-$COMPILATION_MODE
.
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildOptions.java
index 92ef5509c4a873..bb123e896a81fa 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildOptions.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.analysis.config;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.VisibleForTesting;
@@ -38,7 +37,6 @@
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.SerializationContext;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.skyframe.trimming.ConfigurationComparer;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.util.OrderedSetMultimap;
import com.google.devtools.common.options.OptionDefinition;
@@ -87,12 +85,10 @@ public static Map labelizeStarlarkOptions(Map sta
public static BuildOptions getDefaultBuildOptionsForFragments(
List> fragmentClasses) {
- ArrayList collector = new ArrayList<>();
try {
- String[] stringCollector = new String[collector.size()];
- return BuildOptions.of(fragmentClasses, collector.toArray(stringCollector));
+ return BuildOptions.of(fragmentClasses);
} catch (OptionsParsingException e) {
- throw new IllegalArgumentException("Failed to parse default options", e);
+ throw new IllegalArgumentException("Failed to parse empty options", e);
}
}
@@ -531,11 +527,6 @@ public Builder addStarlarkOption(Label key, Object value) {
return this;
}
- /** Returns whether the builder contains a particular Starlark option. */
- boolean contains(Label key) {
- return starlarkOptions.containsKey(key);
- }
-
/** Removes the value for the {@link FragmentOptions} with the given FragmentOptions class. */
public Builder removeFragmentOptions(Class extends FragmentOptions> key) {
fragmentOptions.remove(key);
@@ -974,82 +965,6 @@ private boolean isEmpty() {
&& extraSecondStarlarkOptions.isEmpty();
}
- /**
- * Compares the fragment sets in the options described by two diffs with the same base.
- *
- * @see ConfigurationComparer
- */
- public static ConfigurationComparer.Result compareFragments(
- OptionsDiffForReconstruction left, OptionsDiffForReconstruction right) {
- // TODO: Add support for marking Starlark options as known default when trimming
- // (sentinel object?)
- checkArgument(
- Arrays.equals(left.baseFingerprint, right.baseFingerprint),
- "Can't compare diffs with different bases: %s and %s",
- left,
- right);
- // This code effectively looks up each piece of data (native fragment or Starlark option) in
- // this table (numbers reference comments in the code below):
- // ▼left right▶ (none) extraSecond extraFirst differing
- // (none) equal right only (#4) left only (#4) different (#1)
- // extraSecond left only (#4) compare (#3) (impossible) (impossible)
- // extraFirst right only (#4) (impossible) equal right only (#4)
- // differing different (#1) (impossible) left only (#4) compare (#2)
-
- // Any difference in shared data is grounds to return DIFFERENT, which happens if:
- // 1a. any starlark option was changed by one diff, but is neither changed nor removed by
- // the other
- if (left.hasChangeToStarlarkOptionUnchangedIn(right)
- || right.hasChangeToStarlarkOptionUnchangedIn(left)) {
- return ConfigurationComparer.Result.DIFFERENT;
- }
- // 1b. any native fragment was changed by one diff, but is neither changed nor removed by
- // the other
- if (left.hasChangeToNativeFragmentUnchangedIn(right)
- || right.hasChangeToNativeFragmentUnchangedIn(left)) {
- return ConfigurationComparer.Result.DIFFERENT;
- }
- // 2a. any starlark option was changed by both diffs, but to different values
- if (!commonKeysHaveEqualValues(
- left.differingStarlarkOptions, right.differingStarlarkOptions)) {
- return ConfigurationComparer.Result.DIFFERENT;
- }
- // 2b. any native fragment was changed by both diffs, but to different values
- if (!commonKeysHaveEqualValues(left.differingOptions, right.differingOptions)) {
- return ConfigurationComparer.Result.DIFFERENT;
- }
- // 3a. any starlark option was added by both diffs, but with different values
- if (!commonKeysHaveEqualValues(
- left.extraSecondStarlarkOptions, right.extraSecondStarlarkOptions)) {
- return ConfigurationComparer.Result.DIFFERENT;
- }
- // 3b. any native fragment was added by both diffs, but with different values
- if (!commonKeysHaveEqualValues(
- left.getExtraSecondFragmentsByClass(), right.getExtraSecondFragmentsByClass())) {
- return ConfigurationComparer.Result.DIFFERENT;
- }
-
- // At this point DIFFERENT is definitely not the result, so depending on which side(s) have
- // extra data, we can decide which of the remaining choices to return. (#4)
- boolean leftHasExtraData = left.hasExtraNativeFragmentsOrStarlarkOptionsNotIn(right);
- boolean rightHasExtraData = right.hasExtraNativeFragmentsOrStarlarkOptionsNotIn(left);
-
- if (leftHasExtraData && rightHasExtraData) {
- // If both have data that the other does not, all-shared-fragments-are-equal is all
- // that can be said.
- return ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL;
- } else if (leftHasExtraData) {
- // If only the left instance has extra data, left is a superset of right.
- return ConfigurationComparer.Result.SUPERSET;
- } else if (rightHasExtraData) {
- // If only the right instance has extra data, left is a subset of right.
- return ConfigurationComparer.Result.SUBSET;
- } else {
- // If there is no extra data, the two options described by these diffs are equal.
- return ConfigurationComparer.Result.EQUAL;
- }
- }
-
/**
* Clears {@link #cachedReconstructed} so that tests can cover the core logic of {@link
* #applyDiff}.
@@ -1059,67 +974,6 @@ void clearCachedReconstructedForTesting() {
cachedReconstructed = new SoftReference<>(null);
}
- private boolean hasChangeToStarlarkOptionUnchangedIn(OptionsDiffForReconstruction that) {
- Set starlarkOptionsChangedOrRemovedInThat =
- Sets.union(
- that.differingStarlarkOptions.keySet(),
- ImmutableSet.copyOf(that.extraFirstStarlarkOptions));
- return !starlarkOptionsChangedOrRemovedInThat.containsAll(
- this.differingStarlarkOptions.keySet());
- }
-
- private boolean hasChangeToNativeFragmentUnchangedIn(OptionsDiffForReconstruction that) {
- Set> nativeFragmentsChangedOrRemovedInThat =
- Sets.union(that.differingOptions.keySet(), that.extraFirstFragmentClasses);
- return !nativeFragmentsChangedOrRemovedInThat.containsAll(this.differingOptions.keySet());
- }
-
- private Map, FragmentOptions>
- getExtraSecondFragmentsByClass() {
- ImmutableMap.Builder, FragmentOptions> builder =
- new ImmutableMap.Builder<>();
- for (FragmentOptions options : extraSecondFragments) {
- builder.put(options.getClass(), options);
- }
- return builder.build();
- }
-
- private static boolean commonKeysHaveEqualValues(Map left, Map right) {
- Set commonKeys = Sets.intersection(left.keySet(), right.keySet());
- for (K commonKey : commonKeys) {
- if (!Objects.equals(left.get(commonKey), right.get(commonKey))) {
- return false;
- }
- }
- return true;
- }
-
- private boolean hasExtraNativeFragmentsOrStarlarkOptionsNotIn(
- OptionsDiffForReconstruction that) {
- // extra fragments/options can be...
- // starlark options added by this diff, but not that one
- if (!that.extraSecondStarlarkOptions
- .keySet()
- .containsAll(this.extraSecondStarlarkOptions.keySet())) {
- return true;
- }
- // native fragments added by this diff, but not that one
- if (!that.getExtraSecondFragmentsByClass()
- .keySet()
- .containsAll(this.getExtraSecondFragmentsByClass().keySet())) {
- return true;
- }
- // starlark options removed by that diff, but not this one
- if (!this.extraFirstStarlarkOptions.containsAll(that.extraFirstStarlarkOptions)) {
- return true;
- }
- // native fragments removed by that diff, but not this one
- if (!this.extraFirstFragmentClasses.containsAll(that.extraFirstFragmentClasses)) {
- return true;
- }
- return false;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java
index c0a2d630714305..5f67920b45fd90 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java
@@ -44,7 +44,6 @@
import com.google.devtools.build.lib.packages.AttributeTransitionData;
import com.google.devtools.build.lib.packages.ConfiguredAttributeMapper;
import com.google.devtools.build.lib.packages.Target;
-import com.google.devtools.build.lib.packages.TargetUtils;
import com.google.devtools.build.lib.skyframe.BuildConfigurationValue;
import com.google.devtools.build.lib.skyframe.PackageValue;
import com.google.devtools.build.lib.skyframe.PlatformMappingValue;
@@ -58,7 +57,6 @@
import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@@ -216,24 +214,7 @@ private Dependency resolveNullTransition(
}
private Dependency resolveHostTransition(
- Dependency.Builder dependencyBuilder, DependencyKey dependencyKey)
- throws DependencyEvaluationException {
- // The current rule's host configuration can also be used for the dep. We short-circuit
- // the standard transition logic for host transitions because these transitions are
- // uniquely frequent. It's possible, e.g., for every node in the configured target graph
- // to incur multiple host transitions. So we aggressively optimize to avoid hurting
- // analysis time.
- if (hostConfiguration.trimConfigurationsRetroactively()
- && !dependencyKey.getAspects().isEmpty()) {
- String message =
- ctgValue.getLabel()
- + " has aspects attached, but these are not supported in retroactive"
- + " trimming mode.";
- env.getListener()
- .handle(Event.error(TargetUtils.getLocationMaybe(ctgValue.getTarget()), message));
- throw new DependencyEvaluationException(new InvalidConfigurationException(message));
- }
-
+ Dependency.Builder dependencyBuilder, DependencyKey dependencyKey) {
return dependencyBuilder
.setConfiguration(hostConfiguration)
.setAspects(dependencyKey.getAspects())
@@ -332,8 +313,7 @@ private ImmutableList resolveGenericTransition(
throw new DependencyEvaluationException(e);
}
- Collections.sort(dependencies, SPLIT_DEP_ORDERING);
- return ImmutableList.copyOf(dependencies);
+ return ImmutableList.sortedCopyOf(SPLIT_DEP_ORDERING, dependencies);
}
private ImmutableList collectTransitionKeys(Attribute attribute)
@@ -566,13 +546,8 @@ public static TopLevelTargetsAndConfigsResult getConfigurationsFromExecutor(
LinkedHashSet result = new LinkedHashSet<>();
for (TargetAndConfiguration originalInput : defaultContext) {
- if (successfullyEvaluatedTargets.containsKey(originalInput)) {
- // The configuration was successfully evaluated.
- result.add(successfullyEvaluatedTargets.get(originalInput));
- } else {
- // Either the configuration couldn't be determined (e.g. loading phase error) or it's null.
- result.add(originalInput);
- }
+ // If the configuration couldn't be determined (e.g. loading phase error), use the original.
+ result.add(successfullyEvaluatedTargets.getOrDefault(originalInput, originalInput));
}
return new TopLevelTargetsAndConfigsResult(result, hasError);
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java
index 0097e18acc616b..6d501e3d1485e6 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java
@@ -622,13 +622,7 @@ public enum ConfigsMode {
*/
ON,
/** Default mode: Each configured target is evaluated with all fragments known to Blaze. */
- NOTRIM,
- /**
- * Experimental mode: Each configured target is evaluated with only the configuration fragments
- * it needs by visiting them with a full configuration to begin with and collapsing the
- * configuration down to the fragments which were actually used.
- */
- RETROACTIVE;
+ NOTRIM
}
/** Converter for --experimental_dynamic_configs. */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
index 971e2e1183c569..91b121adf27245 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectFunction.java
@@ -128,7 +128,7 @@ public final class AspectFunction implements SkyFunction {
* @throws AspectCreationException if the value loaded is not a {@link StarlarkDefinedAspect}.
*/
@Nullable
- static StarlarkDefinedAspect loadStarlarkDefinedAspect(
+ private static StarlarkDefinedAspect loadStarlarkDefinedAspect(
Environment env, StarlarkAspectClass starlarkAspectClass)
throws AspectCreationException, InterruptedException {
Label extensionLabel = starlarkAspectClass.getExtensionLabel();
@@ -269,9 +269,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
throw new IllegalStateException("Unexpected exception from BuildConfigurationFunction when "
+ "computing " + key.getAspectConfigurationKey(), e);
}
- if (aspectConfiguration.trimConfigurationsRetroactively()) {
- throw new AssertionError("Aspects should NEVER be evaluated in retroactive trimming mode.");
- }
}
ConfiguredTarget associatedTarget = baseConfiguredTargetValue.getConfiguredTarget();
@@ -301,9 +298,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
configuration =
((BuildConfigurationValue) result.get(associatedTarget.getConfigurationKey()))
.getConfiguration();
- if (configuration.trimConfigurationsRetroactively()) {
- throw new AssertionError("Aspects should NEVER be evaluated in retroactive trimming mode.");
- }
}
try {
associatedConfiguredTargetAndData =
@@ -389,8 +383,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
ToolchainContextKey.key()
.configurationKey(BuildConfigurationValue.key(configuration))
.requiredToolchainTypeLabels(requiredToolchains)
- .shouldSanityCheckConfiguration(
- configuration.trimConfigurationsRetroactively())
.build(),
ToolchainException.class);
} catch (ToolchainException e) {
@@ -553,14 +545,13 @@ private static ConfiguredTarget getBaseTarget(
}
/**
- * Collect all SkyKeys that are needed for a given list of AspectKeys,
- * including transitive dependencies.
+ * Collect all SkyKeys that are needed for a given list of AspectKeys, including transitive
+ * dependencies.
*
- * Also collects all propagating aspects in correct order.
+ * Also collects all propagating aspects in correct order.
*/
- private ImmutableMap getSkyKeysForAspectsAndCollectAspectPath(
- ImmutableList keys,
- ImmutableList.Builder aspectPathBuilder) {
+ private static ImmutableMap getSkyKeysForAspectsAndCollectAspectPath(
+ ImmutableList keys, ImmutableList.Builder aspectPathBuilder) {
HashMap result = new HashMap<>();
for (AspectKey key : keys) {
buildSkyKeys(key, result, aspectPathBuilder);
@@ -568,7 +559,9 @@ private ImmutableMap getSkyKeysForAspectsAndCollectAsp
return ImmutableMap.copyOf(result);
}
- private void buildSkyKeys(AspectKey key, HashMap result,
+ private static void buildSkyKeys(
+ AspectKey key,
+ HashMap result,
ImmutableList.Builder aspectPathBuilder) {
if (result.containsKey(key.getAspectDescriptor())) {
return;
@@ -657,7 +650,7 @@ private AspectValue createAspect(
StoredEventHandler events = new StoredEventHandler();
CachingAnalysisEnvironment analysisEnvironment =
view.createAnalysisEnvironment(
- key, false, events, env, aspectConfiguration, starlarkBuiltinsValue);
+ key, events, env, aspectConfiguration, starlarkBuiltinsValue);
ConfiguredAspect configuredAspect;
if (aspect.getDefinition().applyToGeneratingRules()
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
index 165cf989e68e34..0ad6577eaec0ae 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BUILD
@@ -8,7 +8,6 @@ filegroup(
"//src/main/java/com/google/devtools/build/lib/skyframe/packages:srcs",
"//src/main/java/com/google/devtools/build/lib/skyframe/proto:srcs",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization:srcs",
- "//src/main/java/com/google/devtools/build/lib/skyframe/trimming:srcs",
],
visibility = ["//src:__subpackages__"],
)
@@ -78,7 +77,6 @@ java_library(
"TopLevelActionLookupConflictFindingFunction.java",
"ToplevelStarlarkAspectFunction.java",
"TransitiveTargetFunction.java",
- "TrimmedConfigurationProgressReceiver.java",
"WorkspaceFileFunction.java",
"actiongraph/ActionGraphDump.java",
"actiongraph/v2/ActionGraphDump.java",
@@ -299,7 +297,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/rules/cpp:cpp_interface",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:serialization-constant",
- "//src/main/java/com/google/devtools/build/lib/skyframe/trimming:trimmed_configuration_cache",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:TestType",
"//src/main/java/com/google/devtools/build/lib/util:abrupt_exit_exception",
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index 950693aae752a7..5f03dc0a87dd0a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -317,7 +317,7 @@ public SkyValue compute(SkyKey key, Environment env) throws ConfiguredTargetFunc
env,
resolver,
ctgValue,
- ImmutableList.of(),
+ ImmutableList.of(),
configConditions.asProviders(),
unloadedToolchainContexts == null
? null
@@ -521,8 +521,7 @@ static ToolchainCollection computeUnloadedToolchainCon
ToolchainContextKey.key()
.configurationKey(toolchainConfig)
.requiredToolchainTypeLabels(requiredDefaultToolchains)
- .execConstraintLabels(defaultExecConstraintLabels)
- .shouldSanityCheckConfiguration(configuration.trimConfigurationsRetroactively());
+ .execConstraintLabels(defaultExecConstraintLabels);
if (parentToolchainContextKey != null) {
// Find out what execution platform the parent used, and force that.
@@ -550,7 +549,6 @@ static ToolchainCollection computeUnloadedToolchainCon
.configurationKey(toolchainConfig)
.requiredToolchainTypeLabels(execGroup.requiredToolchains())
.execConstraintLabels(execGroup.execCompatibleWith())
- .shouldSanityCheckConfiguration(configuration.trimConfigurationsRetroactively())
.build());
}
@@ -610,7 +608,6 @@ public static ImmutableSet getExecutionPlatformConstraints(
* @param env the Skyframe environment
* @param resolver the dependency resolver
* @param ctgValue the label and the configuration of the node
- * @param aspects
* @param configConditions the configuration conditions for evaluating the attributes of the node
* @param toolchainContexts the toolchain context for this target
* @param ruleClassProvider rule class provider for determining the right configuration fragments
@@ -739,15 +736,6 @@ static ConfigConditions getConfigConditions(
.collect(Collectors.toList());
if (configLabels.isEmpty()) {
return ConfigConditions.EMPTY;
- } else if (ctgValue.getConfiguration().trimConfigurationsRetroactively()) {
- String message =
- target.getLabel()
- + " has configurable attributes, but these are not supported in retroactive trimming "
- + "mode.";
- env.getListener().handle(Event.error(TargetUtils.getLocationMaybe(target), message));
- throw new DependencyEvaluationException(
- new ConfiguredValueCreationException(
- message, ctgValue.getLabel(), ctgValue.getConfiguration()));
}
// Collect the actual deps without a configuration transition (since by definition config
@@ -905,20 +893,7 @@ private static Map resolveConfiguredTargetDepen
BuildConfiguration depConfiguration = dep.getConfiguration();
BuildConfigurationValue.Key depKey =
depValue.getConfiguredTarget().getConfigurationKey();
- // Retroactive trimming may change the configuration associated with the dependency.
- // If it does, we need to get that instance.
- // TODO(b/140632978): doing these individually instead of doing them all at once may
- // end up being wasteful use of Skyframe. Although these configurations are guaranteed
- // to be in the Skyframe cache (because the dependency would have had to retrieve them
- // to be created in the first place), looking them up repeatedly may be slower than
- // just keeping a local cache and assigning the same configuration to all the CTs
- // which need it. Profile this and see if there's a better way.
if (depKey != null && !depKey.equals(BuildConfigurationValue.key(depConfiguration))) {
- if (!depConfiguration.trimConfigurationsRetroactively()) {
- throw new AssertionError(
- "Loading configurations mid-dependency resolution should ONLY happen when "
- + "retroactive trimming is enabled.");
- }
depConfiguration =
((BuildConfigurationValue) env.getValue(depKey)).getConfiguration();
}
@@ -973,7 +948,7 @@ public String extractTag(SkyKey skyKey) {
}
@Nullable
- private ConfiguredTargetValue createConfiguredTarget(
+ private static ConfiguredTargetValue createConfiguredTarget(
SkyframeBuildView view,
Environment env,
Target target,
@@ -994,7 +969,7 @@ private ConfiguredTargetValue createConfiguredTarget(
StoredEventHandler events = new StoredEventHandler();
CachingAnalysisEnvironment analysisEnvironment =
view.createAnalysisEnvironment(
- configuredTargetKey, false, events, env, configuration, starlarkBuiltinsValue);
+ configuredTargetKey, events, env, configuration, starlarkBuiltinsValue);
Preconditions.checkNotNull(depValueMap);
ConfiguredTarget configuredTarget;
@@ -1032,8 +1007,7 @@ private ConfiguredTargetValue createConfiguredTarget(
configuration == null
? null
: configuration.getEventId().getConfiguration(),
- createDetailedExitCode(
- event.getMessage(), Code.CONFIGURED_VALUE_CREATION_FAILED)))
+ createDetailedExitCode(event.getMessage())))
.collect(Collectors.toList()));
throw new ConfiguredTargetFunctionException(
new ConfiguredValueCreationException(
@@ -1070,11 +1044,11 @@ private ConfiguredTargetValue createConfiguredTarget(
}
}
- private static DetailedExitCode createDetailedExitCode(String message, Code code) {
+ private static DetailedExitCode createDetailedExitCode(String message) {
return DetailedExitCode.of(
FailureDetail.newBuilder()
.setMessage(message)
- .setAnalysis(Analysis.newBuilder().setCode(code))
+ .setAnalysis(Analysis.newBuilder().setCode(Code.CONFIGURED_VALUE_CREATION_FAILED))
.build());
}
@@ -1093,16 +1067,16 @@ static DetailedExitCode getPrioritizedDetailedExitCode(NestedSet causes)
* Used to declare all the exception types that can be wrapped in the exception thrown by {@link
* ConfiguredTargetFunction#compute}.
*/
- static final class ConfiguredTargetFunctionException extends SkyFunctionException {
- private ConfiguredTargetFunctionException(ConfiguredValueCreationException e) {
+ private static final class ConfiguredTargetFunctionException extends SkyFunctionException {
+ ConfiguredTargetFunctionException(ConfiguredValueCreationException e) {
super(e, Transience.PERSISTENT);
}
- private ConfiguredTargetFunctionException(ActionConflictException e) {
+ ConfiguredTargetFunctionException(ActionConflictException e) {
super(e, Transience.PERSISTENT);
}
- private ConfiguredTargetFunctionException(InvalidExecGroupException e) {
+ ConfiguredTargetFunctionException(InvalidExecGroupException e) {
super(e, Transience.PERSISTENT);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java b/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java
index e49675f28e6466..f0317b0c923030 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtil.java
@@ -14,17 +14,13 @@
package com.google.devtools.build.lib.skyframe;
-import static com.google.common.base.Predicates.equalTo;
-import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
-import static java.util.stream.Collectors.joining;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.ConfiguredTargetValue;
-import com.google.devtools.build.lib.analysis.PlatformConfiguration;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.PlatformProviderUtils;
import com.google.devtools.build.lib.cmdline.Label;
@@ -49,11 +45,8 @@ public class PlatformLookupUtil {
@Nullable
public static Map getPlatformInfo(
- ImmutableList platformKeys,
- Environment env,
- boolean sanityCheckConfiguration)
+ ImmutableList platformKeys, Environment env)
throws InterruptedException, InvalidPlatformException {
-
validatePlatformKeys(platformKeys, env);
if (env.valuesMissing()) {
return null;
@@ -72,7 +65,7 @@ public static Map getPlatformInfo(
boolean valuesMissing = env.valuesMissing();
Map platforms = valuesMissing ? null : new HashMap<>();
for (ConfiguredTargetKey key : platformKeys) {
- PlatformInfo platformInfo = findPlatformInfo(key, values.get(key), sanityCheckConfiguration);
+ PlatformInfo platformInfo = findPlatformInfo(key, values.get(key));
if (!valuesMissing && platformInfo != null) {
platforms.put(key, platformInfo);
}
@@ -142,8 +135,7 @@ private static PlatformInfo findPlatformInfo(
ConfiguredTargetKey key,
ValueOrException3<
ConfiguredValueCreationException, NoSuchThingException, ActionConflictException>
- valueOrException,
- boolean sanityCheckConfiguration)
+ valueOrException)
throws InvalidPlatformException {
try {
@@ -153,29 +145,6 @@ private static PlatformInfo findPlatformInfo(
}
ConfiguredTarget configuredTarget = ctv.getConfiguredTarget();
- BuildConfigurationValue.Key configurationKey = configuredTarget.getConfigurationKey();
- // This check is necessary because trimming for other rules assumes that platform resolution
- // uses the platform fragment and _only_ the platform fragment. Without this check, it's
- // possible another fragment could slip in without us realizing, and thus break this
- // assumption.
- if (sanityCheckConfiguration
- && configurationKey.getFragments().stream()
- .anyMatch(not(equalTo(PlatformConfiguration.class)))) {
- // Only the PlatformConfiguration fragment may be present on a platform rule in retroactive
- // trimming mode.
- String extraFragmentDescription =
- configurationKey.getFragments().stream()
- .filter(not(equalTo(PlatformConfiguration.class)))
- .map(Class::getSimpleName)
- .collect(joining(","));
- throw new InvalidPlatformException(
- configuredTarget.getLabel(),
- "has fragments other than PlatformConfiguration, "
- + "which is forbidden in retroactive trimming mode: "
- + "extra fragments are ["
- + extraFragmentDescription
- + "]");
- }
PlatformInfo platformInfo = PlatformProviderUtils.platform(configuredTarget);
if (platformInfo == null) {
throw new InvalidPlatformException(configuredTarget.getLabel());
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
index b4ca46d0ef9dcc..65d7cb10c8b313 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunction.java
@@ -14,8 +14,6 @@
package com.google.devtools.build.lib.skyframe;
-import static com.google.common.base.Predicates.equalTo;
-import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableList.toImmutableList;
import com.google.auto.value.AutoValue;
@@ -97,8 +95,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
// Load the configured target for each, and get the declared execution platforms providers.
ImmutableList registeredExecutionPlatformKeys =
- configureRegisteredExecutionPlatforms(
- env, configuration, configuration.trimConfigurationsRetroactively(), platformLabels);
+ configureRegisteredExecutionPlatforms(env, configuration, platformLabels);
if (env.valuesMissing()) {
return null;
}
@@ -125,13 +122,9 @@ public static List getWorkspaceExecutionPlatforms(Environment env)
return externalPackage.getRegisteredExecutionPlatforms();
}
- private ImmutableList configureRegisteredExecutionPlatforms(
- Environment env,
- BuildConfiguration configuration,
- boolean sanityCheckConfiguration,
- List labels)
+ private static ImmutableList configureRegisteredExecutionPlatforms(
+ Environment env, BuildConfiguration configuration, List labels)
throws InterruptedException, RegisteredExecutionPlatformsFunctionException {
-
ImmutableList keys =
labels.stream()
.map(
@@ -157,22 +150,6 @@ private ImmutableList configureRegisteredExecutionPlatforms
}
ConfiguredTarget target =
((ConfiguredTargetValue) valueOrException.get()).getConfiguredTarget();
- // This check is necessary because trimming for other rules assumes that platform resolution
- // uses the platform fragment and _only_ the platform fragment. Without this check, it's
- // possible another fragment could slip in without us realizing, and thus break this
- // assumption.
- if (sanityCheckConfiguration
- && target.getConfigurationKey().getFragments().stream()
- .anyMatch(not(equalTo(PlatformConfiguration.class)))) {
- // Only the PlatformConfiguration fragment may be present on a platform rule in
- // retroactive trimming mode.
- throw new RegisteredExecutionPlatformsFunctionException(
- new InvalidPlatformException(
- target.getLabel(),
- "has fragments other than PlatformConfiguration, "
- + "which is forbidden in retroactive trimming mode"),
- Transience.PERSISTENT);
- }
PlatformInfo platformInfo = PlatformProviderUtils.platform(target);
if (platformInfo == null) {
throw new RegisteredExecutionPlatformsFunctionException(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
index 024601dc0e13ac..e90f6c88f8e6aa 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunction.java
@@ -14,8 +14,8 @@
package com.google.devtools.build.lib.skyframe;
+import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
-import static java.util.stream.Collectors.joining;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
@@ -97,13 +97,9 @@ public SkyValue compute(SkyKey skyKey, Environment env)
return RegisteredToolchainsValue.create(registeredToolchains);
}
- private Iterable extends String> getWorkspaceToolchains(Environment env)
+ private static ImmutableList getWorkspaceToolchains(Environment env)
throws InterruptedException {
- List patterns = getRegisteredToolchains(env);
- if (patterns == null) {
- return ImmutableList.of();
- }
- return patterns;
+ return firstNonNull(getRegisteredToolchains(env), ImmutableList.of());
}
/**
@@ -113,7 +109,8 @@ private Iterable extends String> getWorkspaceToolchains(Environment env)
*/
@Nullable
@VisibleForTesting
- public static List getRegisteredToolchains(Environment env) throws InterruptedException {
+ public static ImmutableList getRegisteredToolchains(Environment env)
+ throws InterruptedException {
PackageValue externalPackageValue =
(PackageValue) env.getValue(PackageValue.key(LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER));
if (externalPackageValue == null) {
@@ -124,10 +121,8 @@ public static List getRegisteredToolchains(Environment env) throws Inter
return externalPackage.getRegisteredToolchains();
}
- private ImmutableList configureRegisteredToolchains(
- Environment env,
- BuildConfiguration configuration,
- List labels)
+ private static ImmutableList configureRegisteredToolchains(
+ Environment env, BuildConfiguration configuration, List labels)
throws InterruptedException, RegisteredToolchainsFunctionException {
ImmutableList keys =
labels.stream()
@@ -155,28 +150,6 @@ private ImmutableList configureRegisteredToolchains(
ConfiguredTarget target =
((ConfiguredTargetValue) valueOrException.get()).getConfiguredTarget();
- if (configuration.trimConfigurationsRetroactively()
- && !target.getConfigurationKey().getFragments().isEmpty()) {
- // No fragment may be present on a toolchain rule in retroactive trimming mode.
- // This is because trimming expects that platform and toolchain resolution uses only
- // the platform configuration. In theory, this means toolchains could use platforms, but
- // the current expectation is that toolchains should not use anything at all, so better
- // to go with the stricter expectation for now.
- String extraFragmentDescription =
- target.getConfigurationKey().getFragments().stream()
- .map(cl -> cl.getSimpleName())
- .collect(joining(","));
-
- throw new RegisteredToolchainsFunctionException(
- new InvalidToolchainLabelException(
- toolchainLabel,
- "this toolchain uses configuration, which is forbidden in retroactive trimming "
- + "mode: "
- + "extra fragments are ["
- + extraFragmentDescription
- + "]"),
- Transience.PERSISTENT);
- }
DeclaredToolchainInfo toolchainInfo = PlatformProviderUtils.declaredToolchainInfo(target);
if (toolchainInfo == null) {
throw new RegisteredToolchainsFunctionException(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java
index 8d92213f577572..ee67d95feef40a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunction.java
@@ -88,7 +88,6 @@ public SkyValue compute(SkyKey skyKey, Environment env)
key.toolchainTypeLabel(),
key.availableExecutionPlatformKeys(),
key.targetPlatformKey(),
- configuration.trimConfigurationsRetroactively(),
toolchains.registeredToolchains(),
env,
debug ? env.getListener() : null);
@@ -104,7 +103,6 @@ private static SingleToolchainResolutionValue resolveConstraints(
Label toolchainTypeLabel,
List availableExecutionPlatformKeys,
ConfiguredTargetKey targetPlatformKey,
- boolean sanityCheckConfigurations,
ImmutableList toolchains,
Environment env,
@Nullable EventHandler eventHandler)
@@ -113,15 +111,14 @@ private static SingleToolchainResolutionValue resolveConstraints(
// Load the PlatformInfo needed to check constraints.
Map platforms;
try {
-
platforms =
PlatformLookupUtil.getPlatformInfo(
- new ImmutableList.Builder()
+ ImmutableList.builderWithExpectedSize(
+ availableExecutionPlatformKeys.size() + 1)
.add(targetPlatformKey)
.addAll(availableExecutionPlatformKeys)
.build(),
- env,
- sanityCheckConfigurations);
+ env);
if (env.valuesMissing()) {
return null;
}
@@ -318,15 +315,15 @@ public Label missingToolchainTypeLabel() {
* Used to indicate errors during the computation of an {@link SingleToolchainResolutionValue}.
*/
private static final class ToolchainResolutionFunctionException extends SkyFunctionException {
- public ToolchainResolutionFunctionException(NoToolchainFoundException e) {
+ ToolchainResolutionFunctionException(NoToolchainFoundException e) {
super(e, Transience.PERSISTENT);
}
- public ToolchainResolutionFunctionException(InvalidToolchainLabelException e) {
+ ToolchainResolutionFunctionException(InvalidToolchainLabelException e) {
super(e, Transience.PERSISTENT);
}
- public ToolchainResolutionFunctionException(InvalidPlatformException e) {
+ ToolchainResolutionFunctionException(InvalidPlatformException e) {
super(e, Transience.PERSISTENT);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
index 1554ccf7c716e5..713d543165251f 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
@@ -332,12 +332,7 @@ public void setConfigurations(
skyframeExecutor.handleAnalysisInvalidatingChange();
}
}
- if (configurations.getTargetConfigurations().stream()
- .anyMatch(BuildConfiguration::trimConfigurationsRetroactively)) {
- skyframeExecutor.activateRetroactiveTrimming();
- } else {
- skyframeExecutor.deactivateRetroactiveTrimming();
- }
+
skyframeAnalysisWasDiscarded = false;
this.configurations = configurations;
setTopLevelHostConfiguration(configurations.getHostConfiguration());
@@ -981,7 +976,6 @@ public ArtifactFactory getArtifactFactory() {
CachingAnalysisEnvironment createAnalysisEnvironment(
ActionLookupKey owner,
- boolean isSystemEnv,
ExtendedEventHandler eventHandler,
Environment env,
BuildConfiguration config,
@@ -992,7 +986,6 @@ CachingAnalysisEnvironment createAnalysisEnvironment(
artifactFactory,
skyframeExecutor.getActionKeyContext(),
owner,
- isSystemEnv,
extendedSanityChecks,
allowAnalysisFailures,
eventHandler,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index 86fe88dd9dc457..56715ae6eebee6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -87,7 +87,6 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
-import com.google.devtools.build.lib.analysis.config.BuildOptions.OptionsDiffForReconstruction;
import com.google.devtools.build.lib.analysis.config.BuildOptionsView;
import com.google.devtools.build.lib.analysis.config.ConfigurationResolver;
import com.google.devtools.build.lib.analysis.config.CoreOptions;
@@ -171,7 +170,6 @@
import com.google.devtools.build.lib.skyframe.PackageLookupFunction.CrossRepositoryLabelViolationStrategy;
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ActionCompletedReceiver;
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ProgressSupplier;
-import com.google.devtools.build.lib.skyframe.trimming.TrimmedConfigurationCache;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.util.DetailedExitCode;
import com.google.devtools.build.lib.util.ResourceUsage;
@@ -375,11 +373,6 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory, Configur
private final PathResolverFactory pathResolverFactory = new PathResolverFactoryImpl();
@Nullable private final NonexistentFileReceiver nonexistentFileReceiver;
- private final TrimmedConfigurationCache
- trimmingCache = TrimmedConfigurationProgressReceiver.buildCache();
- private final TrimmedConfigurationProgressReceiver trimmingListener =
- new TrimmedConfigurationProgressReceiver(trimmingCache);
-
private boolean siblingRepositoryLayout = false;
private Map lastRemoteDefaultExecProperties;
@@ -855,7 +848,6 @@ protected SkyframeProgressReceiver newSkyframeProgressReceiver() {
public void resetEvaluator() {
init();
emittedEventState.clear();
- clearTrimmingCache();
skyframeBuildView.reset();
}
@@ -885,26 +877,11 @@ public void postLoggingStatsWhenCrashing(ExtendedEventHandler eventHandler) {
public void handleAnalysisInvalidatingChange() {
logger.atInfo().log("Dropping configured target data");
analysisCacheDiscarded = true;
- clearTrimmingCache();
skyframeBuildView.clearInvalidatedActionLookupKeys();
skyframeBuildView.clearLegacyData();
ArtifactNestedSetFunction.getInstance().resetArtifactNestedSetFunctionMaps();
}
- /** Activates retroactive trimming (idempotently, so has no effect if already active). */
- void activateRetroactiveTrimming() {
- trimmingListener.activate();
- }
-
- /** Deactivates retroactive trimming (idempotently, so has no effect if already inactive). */
- void deactivateRetroactiveTrimming() {
- trimmingListener.deactivate();
- }
-
- protected void clearTrimmingCache() {
- trimmingCache.clear();
- }
-
/** Used with dump --rules. */
public static class RuleStat {
private final String key;
@@ -1901,19 +1878,6 @@ public ImmutableMultimap getConfiguredTa
// when depConfig is non-null, so we need to explicitly override it in that case.
resolvedConfig = null;
} else if (!configKey.equals(BuildConfigurationValue.key(depConfig))) {
- // Retroactive trimming may change the configuration associated with the dependency.
- // If it does, we need to get that instance.
- // TODO(b/140632978): doing these individually instead of doing them all at once may
- // end up being wasteful use of Skyframe. Although these configurations are guaranteed
- // to be in the Skyframe cache (because the dependency would have had to retrieve
- // them to be created in the first place), looking them up repeatedly may be slower
- // than just keeping a local cache and assigning the same configuration to all the
- // CTs which need it. Profile this and see if there's a better way.
- if (!depConfig.trimConfigurationsRetroactively()) {
- throw new AssertionError(
- "Loading configurations mid-dependency resolution should ONLY happen when "
- + "retroactive trimming is enabled.");
- }
resolvedConfig = getConfiguration(eventHandler, mergedTarget.getConfigurationKey());
}
cts.put(
@@ -1923,7 +1887,6 @@ public ImmutableMultimap getConfiguredTa
packageValue.getPackage().getTarget(configuredTarget.getLabel().getName()),
resolvedConfig,
null));
-
} catch (DuplicateException | NoSuchTargetException e) {
throw new IllegalStateException(
String.format("Error creating %s", configuredTarget.getLabel()), e);
@@ -3104,7 +3067,6 @@ protected class SkyframeProgressReceiver implements EvaluationProgressReceiver {
/** This receiver is only needed for loading, so it is null otherwise. */
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
- trimmingListener.invalidated(skyKey, state);
if (ignoreInvalidations) {
return;
}
@@ -3113,7 +3075,6 @@ public void invalidated(SkyKey skyKey, InvalidationState state) {
@Override
public void enqueueing(SkyKey skyKey) {
- trimmingListener.enqueueing(skyKey);
if (ignoreInvalidations) {
return;
}
@@ -3130,7 +3091,6 @@ public void evaluated(
@Nullable ErrorInfo newError,
Supplier evaluationSuccessState,
EvaluationState state) {
- trimmingListener.evaluated(skyKey, newValue, newError, evaluationSuccessState, state);
if (ignoreInvalidations) {
return;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainContextKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainContextKey.java
index f82b27a05306e7..1062675c4f2e69 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainContextKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainContextKey.java
@@ -33,7 +33,6 @@ public static Builder key() {
return new AutoValue_ToolchainContextKey.Builder()
.requiredToolchainTypeLabels(ImmutableSet.of())
.execConstraintLabels(ImmutableSet.of())
- .shouldSanityCheckConfiguration(false)
.forceExecutionPlatform(Optional.empty());
}
@@ -48,8 +47,6 @@ public SkyFunctionName functionName() {
abstract ImmutableSet execConstraintLabels();
- abstract boolean shouldSanityCheckConfiguration();
-
abstract Optional forceExecutionPlatform();
/** Builder for {@link ToolchainContextKey}. */
@@ -65,8 +62,6 @@ public interface Builder {
Builder execConstraintLabels(Label... execConstraintLabels);
- Builder shouldSanityCheckConfiguration(boolean shouldSanityCheckConfiguration);
-
ToolchainContextKey build();
Builder forceExecutionPlatform(Optional execPlatform);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
index 470f9fda37adfc..714cfb431176cf 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunction.java
@@ -87,11 +87,7 @@ public UnloadedToolchainContext compute(SkyKey skyKey, Environment env)
// Load the configured target for the toolchain types to ensure that they are valid and
// resolve aliases.
ImmutableMap resolvedToolchainTypes =
- loadToolchainTypes(
- env,
- configuration,
- key.requiredToolchainTypeLabels(),
- key.shouldSanityCheckConfiguration());
+ loadToolchainTypes(env, configuration, key.requiredToolchainTypeLabels());
builder.setRequestedLabelToToolchainType(resolvedToolchainTypes);
ImmutableSet resolvedToolchainTypeLabels =
resolvedToolchainTypes.values().stream()
@@ -106,8 +102,7 @@ public UnloadedToolchainContext compute(SkyKey skyKey, Environment env)
key.configurationKey(),
configuration,
platformConfiguration,
- key.execConstraintLabels(),
- key.shouldSanityCheckConfiguration());
+ key.execConstraintLabels());
if (env.valuesMissing()) {
return null;
}
@@ -119,8 +114,7 @@ public UnloadedToolchainContext compute(SkyKey skyKey, Environment env)
resolvedToolchainTypeLabels,
key.forceExecutionPlatform().map(platformKeys::find),
builder,
- platformKeys,
- key.shouldSanityCheckConfiguration());
+ platformKeys);
UnloadedToolchainContext unloadedToolchainContext = builder.build();
if (debug) {
@@ -150,11 +144,10 @@ public UnloadedToolchainContext compute(SkyKey skyKey, Environment env)
}
/** Returns a map from the requested toolchain type to the {@link ToolchainTypeInfo} provider. */
- private ImmutableMap loadToolchainTypes(
+ private static ImmutableMap loadToolchainTypes(
Environment environment,
BuildConfiguration configuration,
- ImmutableSet requestedToolchainTypeLabels,
- boolean shouldSanityCheckConfiguration)
+ ImmutableSet requestedToolchainTypeLabels)
throws InvalidToolchainTypeException, InterruptedException, ValueMissingException {
ImmutableSet toolchainTypeKeys =
requestedToolchainTypeLabels.stream()
@@ -167,8 +160,7 @@ private ImmutableMap loadToolchainTypes(
.collect(toImmutableSet());
ImmutableMap resolvedToolchainTypes =
- ToolchainTypeLookupUtil.resolveToolchainTypes(
- environment, toolchainTypeKeys, shouldSanityCheckConfiguration);
+ ToolchainTypeLookupUtil.resolveToolchainTypes(environment, toolchainTypeKeys);
if (environment.valuesMissing()) {
throw new ValueMissingException();
}
@@ -210,14 +202,13 @@ static PlatformKeys create(
}
}
- private PlatformKeys loadPlatformKeys(
+ private static PlatformKeys loadPlatformKeys(
SkyFunction.Environment environment,
boolean debug,
BuildConfigurationValue.Key configurationKey,
BuildConfiguration configuration,
PlatformConfiguration platformConfiguration,
- ImmutableSet execConstraintLabels,
- boolean shouldSanityCheckConfiguration)
+ ImmutableSet execConstraintLabels)
throws InterruptedException, ValueMissingException, InvalidConstraintValueException,
InvalidPlatformException {
// Determine the target and host platform keys.
@@ -237,9 +228,7 @@ private PlatformKeys loadPlatformKeys(
// Load the host and target platforms early, to check for errors.
PlatformLookupUtil.getPlatformInfo(
- ImmutableList.of(hostPlatformKey, targetPlatformKey),
- environment,
- shouldSanityCheckConfiguration);
+ ImmutableList.of(hostPlatformKey, targetPlatformKey), environment);
if (environment.valuesMissing()) {
throw new ValueMissingException();
}
@@ -251,20 +240,18 @@ private PlatformKeys loadPlatformKeys(
configurationKey,
configuration,
hostPlatformKey,
- execConstraintLabels,
- shouldSanityCheckConfiguration);
+ execConstraintLabels);
return PlatformKeys.create(hostPlatformKey, targetPlatformKey, executionPlatformKeys);
}
- private ImmutableList loadExecutionPlatformKeys(
+ private static ImmutableList loadExecutionPlatformKeys(
SkyFunction.Environment environment,
boolean debug,
BuildConfigurationValue.Key configurationKey,
BuildConfiguration configuration,
ConfiguredTargetKey defaultPlatformKey,
- ImmutableSet execConstraintLabels,
- boolean shouldSanityCheckConfiguration)
+ ImmutableSet execConstraintLabels)
throws InterruptedException, ValueMissingException, InvalidConstraintValueException,
InvalidPlatformException {
RegisteredExecutionPlatformsValue registeredExecutionPlatforms =
@@ -294,20 +281,15 @@ private ImmutableList loadExecutionPlatformKeys(
.collect(toImmutableList());
return filterAvailablePlatforms(
- environment,
- debug,
- availableExecutionPlatformKeys,
- execConstraintKeys,
- shouldSanityCheckConfiguration);
+ environment, debug, availableExecutionPlatformKeys, execConstraintKeys);
}
/** Returns only the platform keys that match the given constraints. */
- private ImmutableList filterAvailablePlatforms(
+ private static ImmutableList filterAvailablePlatforms(
SkyFunction.Environment environment,
boolean debug,
ImmutableList platformKeys,
- ImmutableList constraintKeys,
- boolean shouldSanityCheckConfiguration)
+ ImmutableList constraintKeys)
throws InterruptedException, ValueMissingException, InvalidConstraintValueException,
InvalidPlatformException {
@@ -323,8 +305,7 @@ private ImmutableList filterAvailablePlatforms(
// platform is the host platform), Skyframe will return the correct results immediately without
// need of a restart.
Map platformInfoMap =
- PlatformLookupUtil.getPlatformInfo(
- platformKeys, environment, shouldSanityCheckConfiguration);
+ PlatformLookupUtil.getPlatformInfo(platformKeys, environment);
if (platformInfoMap == null) {
throw new ValueMissingException();
}
@@ -340,7 +321,7 @@ private ImmutableList filterAvailablePlatforms(
}
/** Returns {@code true} if the given platform has all of the constraints. */
- private boolean filterPlatform(
+ private static boolean filterPlatform(
SkyFunction.Environment environment,
boolean debug,
PlatformInfo platformInfo,
@@ -365,14 +346,13 @@ private boolean filterPlatform(
return missingConstraints.isEmpty();
}
- private void determineToolchainImplementations(
+ private static void determineToolchainImplementations(
Environment environment,
BuildConfigurationValue.Key configurationKey,
ImmutableSet requiredToolchainTypeLabels,
Optional forcedExecutionPlatform,
UnloadedToolchainContextImpl.Builder builder,
- PlatformKeys platformKeys,
- boolean shouldSanityCheckConfiguration)
+ PlatformKeys platformKeys)
throws InterruptedException, ValueMissingException, InvalidPlatformException,
NoMatchingPlatformException, UnresolvedToolchainsException,
InvalidToolchainLabelException {
@@ -452,8 +432,7 @@ private void determineToolchainImplementations(
Map platforms =
PlatformLookupUtil.getPlatformInfo(
ImmutableList.of(selectedExecutionPlatformKey.get(), platformKeys.targetPlatformKey()),
- environment,
- shouldSanityCheckConfiguration);
+ environment);
if (platforms == null) {
throw new ValueMissingException();
}
@@ -521,13 +500,11 @@ private static boolean isPlatformSuitable(
return false;
}
- Map toolchains = resolvedToolchains.row(executionPlatformKey);
- if (!toolchains.keySet().containsAll(requiredToolchainTypes)) {
- // Not all toolchains are present, ignore this execution platform.
- return false;
- }
-
- return true;
+ // Unless all toolchains are present, ignore this execution platform.
+ return resolvedToolchains
+ .row(executionPlatformKey)
+ .keySet()
+ .containsAll(requiredToolchainTypes);
}
@@ -614,7 +591,7 @@ private static String getMessage(List missingToolchainTypes) {
/** Used to indicate errors during the computation of an {@link UnloadedToolchainContextImpl}. */
private static final class ToolchainResolutionFunctionException extends SkyFunctionException {
- public ToolchainResolutionFunctionException(ToolchainException e) {
+ ToolchainResolutionFunctionException(ToolchainException e) {
super(e, Transience.PERSISTENT);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtil.java b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtil.java
index c77da6817acbb7..df229c1dc7661e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtil.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.skyframe;
-import static java.util.stream.Collectors.joining;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
@@ -37,9 +36,7 @@ public class ToolchainTypeLookupUtil {
@Nullable
public static ImmutableMap resolveToolchainTypes(
- Environment env,
- Iterable toolchainTypeKeys,
- boolean sanityCheckConfiguration)
+ Environment env, Iterable toolchainTypeKeys)
throws InterruptedException, InvalidToolchainTypeException {
Map<
SkyKey,
@@ -55,8 +52,7 @@ public static ImmutableMap resolveToolchainTypes(
Map results = valuesMissing ? null : new HashMap<>();
for (ConfiguredTargetKey key : toolchainTypeKeys) {
Label originalLabel = key.getLabel();
- ToolchainTypeInfo toolchainTypeInfo =
- findToolchainTypeInfo(key, values.get(key), sanityCheckConfiguration);
+ ToolchainTypeInfo toolchainTypeInfo = findToolchainTypeInfo(key, values.get(key));
if (!valuesMissing && toolchainTypeInfo != null) {
// These are only different if the toolchain type was aliased.
results.put(originalLabel, toolchainTypeInfo);
@@ -75,8 +71,7 @@ private static ToolchainTypeInfo findToolchainTypeInfo(
ConfiguredTargetKey key,
ValueOrException3<
ConfiguredValueCreationException, NoSuchThingException, ActionConflictException>
- valueOrException,
- boolean sanityCheckConfiguration)
+ valueOrException)
throws InvalidToolchainTypeException {
try {
@@ -86,26 +81,6 @@ private static ToolchainTypeInfo findToolchainTypeInfo(
}
ConfiguredTarget configuredTarget = ctv.getConfiguredTarget();
- BuildConfigurationValue.Key configurationKey = configuredTarget.getConfigurationKey();
- // This check is necessary because trimming for other rules assumes that platform resolution
- // uses the platform fragment and _only_ the platform fragment. Without this check, it's
- // possible another fragment could slip in without us realizing, and thus break this
- // assumption.
- if (sanityCheckConfiguration && !configurationKey.getFragments().isEmpty()) {
- // No fragments may be present on a toolchain_type rule in retroactive
- // trimming mode.
- String extraFragmentDescription =
- configurationKey.getFragments().stream()
- .map(cl -> cl.getSimpleName())
- .collect(joining(","));
- throw new InvalidToolchainTypeException(
- configuredTarget.getLabel(),
- "has configuration fragments, "
- + "which is forbidden in retroactive trimming mode: "
- + "extra fragments are ["
- + extraFragmentDescription
- + "]");
- }
ToolchainTypeInfo toolchainTypeInfo = PlatformProviderUtils.toolchainType(configuredTarget);
if (toolchainTypeInfo == null) {
if (PlatformProviderUtils.declaredToolchainInfo(configuredTarget) != null) {
@@ -120,9 +95,9 @@ private static ToolchainTypeInfo findToolchainTypeInfo(
return toolchainTypeInfo;
} catch (ConfiguredValueCreationException e) {
- throw new InvalidToolchainTypeException(key.getLabel(), e);
+ throw new InvalidToolchainTypeException(e);
} catch (NoSuchThingException e) {
- throw new InvalidToolchainTypeException(key.getLabel(), e);
+ throw new InvalidToolchainTypeException(e);
} catch (ActionConflictException e) {
throw new InvalidToolchainTypeException(key.getLabel(), e);
}
@@ -136,12 +111,12 @@ public static final class InvalidToolchainTypeException extends ToolchainExcepti
super(formatError(label, DEFAULT_ERROR));
}
- InvalidToolchainTypeException(Label label, ConfiguredValueCreationException e) {
+ InvalidToolchainTypeException(ConfiguredValueCreationException e) {
// Just propagate the inner exception, because it's directly actionable.
super(e);
}
- public InvalidToolchainTypeException(Label label, NoSuchThingException e) {
+ public InvalidToolchainTypeException(NoSuchThingException e) {
// Just propagate the inner exception, because it's directly actionable.
super(e);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TrimmedConfigurationProgressReceiver.java b/src/main/java/com/google/devtools/build/lib/skyframe/TrimmedConfigurationProgressReceiver.java
deleted file mode 100644
index 0480cf7864817a..00000000000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TrimmedConfigurationProgressReceiver.java
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright 2019 The Bazel Authors. 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.skyframe;
-
-import com.google.common.base.Preconditions;
-import com.google.devtools.build.lib.analysis.config.BuildOptions;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.skyframe.trimming.TrimmedConfigurationCache;
-import com.google.devtools.build.skyframe.ErrorInfo;
-import com.google.devtools.build.skyframe.EvaluationProgressReceiver;
-import com.google.devtools.build.skyframe.SkyKey;
-import com.google.devtools.build.skyframe.SkyValue;
-import java.util.function.Supplier;
-import javax.annotation.Nullable;
-
-/**
- * Skyframe progress receiver which keeps a {@link TrimmedConfigurationCache} in sync with Skyframe
- * invalidations and revalidations.
- */
-public final class TrimmedConfigurationProgressReceiver implements EvaluationProgressReceiver {
-
- private final TrimmedConfigurationCache
- cache;
-
- private boolean enabled = true;
-
- public TrimmedConfigurationProgressReceiver(
- TrimmedConfigurationCache cache) {
- this.cache = cache;
- }
-
- public static TrimmedConfigurationCache
- buildCache() {
- return new TrimmedConfigurationCache<>(
- TrimmedConfigurationProgressReceiver::extractLabel,
- TrimmedConfigurationProgressReceiver::extractOptionsDiff,
- BuildOptions.OptionsDiffForReconstruction::compareFragments);
- }
-
- public TrimmedConfigurationCache
- getCache() {
- return this.cache;
- }
-
- public static Label extractLabel(SkyKey key) {
- Preconditions.checkArgument(isKeyCacheable(key));
- ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key;
- return configuredTargetKey.getLabel();
- }
-
- public static BuildOptions.OptionsDiffForReconstruction extractOptionsDiff(SkyKey key) {
- Preconditions.checkArgument(isKeyCacheable(key));
- ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key;
- BuildConfigurationValue.Key configurationKey = configuredTargetKey.getConfigurationKey();
- return configurationKey.getOptionsDiff();
- }
-
- public static boolean isKeyCacheable(SkyKey key) {
- if (!(key instanceof ConfiguredTargetKey)) {
- // Only configured targets go in the cache.
- // TODO(b/129286648): add aspect support
- return false;
- }
- ConfiguredTargetKey configuredTargetKey = (ConfiguredTargetKey) key;
- if (configuredTargetKey.getConfigurationKey() == null) {
- // Null-configured targets do not go in the cache.
- return false;
- }
- return true;
- }
-
- public void activate() {
- if (this.enabled) {
- return;
- }
- this.enabled = true;
- }
-
- public void deactivate() {
- if (!this.enabled) {
- return;
- }
- this.enabled = false;
- this.cache.clear();
- }
-
- @Override
- public void invalidated(SkyKey key, InvalidationState state) {
- if (!enabled || !isKeyCacheable(key)) {
- return;
- }
- switch (state) {
- case DIRTY:
- cache.invalidate(key);
- break;
- case DELETED:
- cache.remove(key);
- break;
- }
- }
-
- @Override
- public void evaluated(
- SkyKey key,
- @Nullable SkyValue newValue,
- @Nullable ErrorInfo newError,
- Supplier evaluationSuccessState,
- EvaluationState state) {
- if (!enabled || !isKeyCacheable(key)) {
- return;
- }
- switch (state) {
- case BUILT:
- // Do nothing; the evaluation would have handled putting itself (back) in the cache.
- break;
- case CLEAN:
- cache.revalidate(key);
- break;
- }
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/trimming/BUILD
deleted file mode 100644
index fb1310475c5288..00000000000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/BUILD
+++ /dev/null
@@ -1,26 +0,0 @@
-# Classes which provide support for automatically trimming configuration to avoid wasted work during a build.
-
-load("@rules_java//java:defs.bzl", "java_library")
-
-package(
- default_visibility = ["//src:__subpackages__"],
-)
-
-filegroup(
- name = "srcs",
- srcs = glob(["**"]),
- visibility = ["//src:__subpackages__"],
-)
-
-java_library(
- name = "trimmed_configuration_cache",
- srcs = [
- "ConfigurationComparer.java",
- "KeyAndState.java",
- "TrimmedConfigurationCache.java",
- ],
- deps = [
- "//third_party:auto_value",
- "//third_party:guava",
- ],
-)
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/ConfigurationComparer.java b/src/main/java/com/google/devtools/build/lib/skyframe/trimming/ConfigurationComparer.java
deleted file mode 100644
index 91b63b4662fadb..00000000000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/ConfigurationComparer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2018 The Bazel Authors. 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.skyframe.trimming;
-
-import java.util.function.BiFunction;
-
-/**
- * Interface describing a function which compares two configurations and determines their
- * relationship.
- */
-@FunctionalInterface
-public interface ConfigurationComparer
- extends BiFunction {
- /** The outcome of comparing two configurations. */
- public enum Result {
- /**
- * All fragments in the first configuration are present and equal in the second, and vice versa.
- */
- EQUAL(true, true, true),
- /**
- * All shared fragments are equal, but the second configuration has additional fragments the
- * first does not.
- */
- SUBSET(true, false, true),
- /**
- * All shared fragments are equal, but the first configuration has additional fragments the
- * second does not.
- */
- SUPERSET(false, true, true),
- /**
- * The two configurations each have fragments the other does not, but the shared fragments are
- * equal.
- */
- ALL_SHARED_FRAGMENTS_EQUAL(false, false, true),
- /** At least one fragment shared between the two configurations is unequal. */
- DIFFERENT(false, false, false);
-
- private final boolean isSubsetOrEqual;
- private final boolean isSupersetOrEqual;
- private final boolean hasEqualSharedFragments;
-
- Result(boolean isSubsetOrEqual, boolean isSupersetOrEqual, boolean hasEqualSharedFragments) {
- this.isSubsetOrEqual = isSubsetOrEqual;
- this.isSupersetOrEqual = isSupersetOrEqual;
- this.hasEqualSharedFragments = hasEqualSharedFragments;
- }
-
- public boolean isSubsetOrEqual() {
- return isSubsetOrEqual;
- }
-
- public boolean isSupersetOrEqual() {
- return isSupersetOrEqual;
- }
-
- public boolean hasEqualSharedFragments() {
- return hasEqualSharedFragments;
- }
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/KeyAndState.java b/src/main/java/com/google/devtools/build/lib/skyframe/trimming/KeyAndState.java
deleted file mode 100644
index b30f42c3b4d4c8..00000000000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/KeyAndState.java
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2018 The Bazel Authors. 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.skyframe.trimming;
-
-import com.google.auto.value.AutoValue;
-
-/**
- * A pair of some key type and a valid/invalid state, for use in {@link TrimmedConfigurationCache}.
- */
-@AutoValue
-abstract class KeyAndState {
- enum State {
- VALID(true),
- POSSIBLY_INVALID(false);
-
- private final boolean isKnownValid;
-
- State(boolean isKnownValid) {
- this.isKnownValid = isKnownValid;
- }
-
- boolean isKnownValid() {
- return isKnownValid;
- }
- }
-
- abstract KeyT getKey();
-
- abstract State getState();
-
- static KeyAndState create(KeyT key) {
- return create(key, State.VALID);
- }
-
- private static KeyAndState create(KeyT key, State state) {
- return new AutoValue_KeyAndState<>(key, state);
- }
-
- KeyAndState asValidated() {
- if (State.VALID.equals(getState())) {
- return this;
- }
- return create(getKey(), State.VALID);
- }
-
- KeyAndState asInvalidated() {
- if (State.POSSIBLY_INVALID.equals(getState())) {
- return this;
- }
- return create(getKey(), State.POSSIBLY_INVALID);
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/TrimmedConfigurationCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/trimming/TrimmedConfigurationCache.java
deleted file mode 100644
index ea82f136e8605c..00000000000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/trimming/TrimmedConfigurationCache.java
+++ /dev/null
@@ -1,392 +0,0 @@
-// Copyright 2018 The Bazel Authors. 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.skyframe.trimming;
-
-import com.google.common.base.Preconditions;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-/**
- * Cache which tracks canonical invocations and matches keys to equivalent keys (after trimming).
- *
- * This cache can be built independently of the massive build dependency that is build-base
- * (SkyFunctions and BuildConfiguration and so on), and so it is - thus, it uses type parameters to
- * speak more abstractly about what it cares about.
- *
- *
Consider a {@code } as a pair of {@code } and {@code }. The
- * descriptor describes what the key builds, while the configuration describes how to build it.
- *
- * For example, a ConfiguredTargetKey is made up of a Label, which is its descriptor, and a
- * BuildConfiguration, which is its configuration. An AspectKey is made up of a Label and a set of
- * AspectDescriptors describing the aspect and the aspects it depends on, all of which are part of
- * the AspectKey's descriptor, and also has a BuildConfiguration, which is its configuration.
- *
- *
A key always uses all of its descriptor, but it may only use part of its configuration. A Java
- * configured target may have no use for Python configuration, for example. Thus, it would produce
- * the same result to evaluate that target with a configuration which doesn't include Python data.
- * Reducing the configuration to the subset configuration which only includes the bits the target
- * actually needs is called trimming the configuration.
- *
- *
If this trimmed configuration is a subset of another configuration, then building whatever the
- * descriptor refers to with that other configuration will produce the same result as the trimmed
- * configuration, which is the same result as the configuration that the trimmed configuration was
- * trimmed from.
- *
- *
This cache provides methods for matching keys which would evaluate to the same result because
- * they have the same descriptor and trim to the same configuration, allowing callers to avoid doing
- * work that has already been done. It also permits invalidating, revalidating, and removing these
- * keys, as might happen during their lifecycle (if something they depend on has changed, etc.).
- *
- *
Internally, this cache is essentially a very sparse table. Each row, headed by a descriptor,
- * describes the possible configurations of that descriptor. Columns, headed by a trimmed
- * configuration, represent minimal configurations that descriptors can be invoked with. And a cell
- * contains the key which corresponds to the canonical invocation of that descriptor with that
- * configuration.
- *
- *
This class expects to be used in ways which are consistent with trimming. That is to say:
- *
- *
- * If the same key is put in the cache twice with different trimmed configurations, it must be
- * invalidated between the two puts. Afterward, the original trimmed configuration is no
- * longer valid for the rest of this build.
- * No trimmed configuration must be put in the cache which has equal values for every fragment
- * it shares with another trimmed configuration already in the cache, unless the key
- * associated with the other configuration has been invalidated. Afterward, the configuration
- * which had previously been invalidated is no longer valid for the rest of this build.
- * Methods which read and add to the cache - {@link #get(KeyT)}, {@link #revalidate(KeyT)},
- * and {@link #putIfAbsent(KeyT, ConfigurationT)} - may be used together in one phase of the
- * build. Methods which remove from the cache - {@link #invalidate(KeyT)}, {@link
- * #remove(KeyT)}, and {@link #clear()} - may be used together in another phase of the build.
- * Calls to these groups of methods must never be interleaved.
- *
- *
- * If used as described above, this class is thread-safe.
- */
-public final class TrimmedConfigurationCache {
-
- // ======== Tuning parameters ==========
- /** The initial capacity of the cache of descriptors. */
- private static final int CACHE_INITIAL_SIZE = 100;
- /** The table density for the cache of descriptors. */
- private static final float CACHE_LOAD_FACTOR = 0.9f;
- /** The number of threads expected to be writing to the descriptor cache at a time. */
- private static final int CACHE_CONCURRENCY_LEVEL = 16;
- /**
- * The number of configurations to expect in a single descriptor - that is, the initial capacity
- * of descriptors' maps.
- */
- private static final int EXPECTED_CONFIGURATIONS_PER_DESCRIPTOR = 4;
- /**
- * The table density for the {@link ConcurrentHashMap ConcurrentHashMaps} created for tracking
- * configurations of each descriptor.
- */
- private static final float DESCRIPTOR_LOAD_FACTOR = 0.9f;
- /** The number of threads expected to be writing to a single descriptor at a time. */
- private static final int DESCRIPTOR_CONCURRENCY_LEVEL = 1;
-
- private final Function descriptorExtractor;
- private final Function configurationExtractor;
-
- private final ConfigurationComparer configurationComparer;
-
- private volatile ConcurrentHashMap<
- DescriptorT, ConcurrentHashMap>>
- descriptors;
-
- /**
- * Constructs a new TrimmedConfigurationCache with the given methods of extracting descriptors and
- * configurations from keys, and uses the given predicate to determine the relationship between
- * two configurations.
- *
- * {@code configurationComparer} should be consistent with equals - that is,
- * {@code a.equals(b) == b.equals(a) == configurationComparer.compare(a, b).equals(Result.EQUAL)}
- */
- public TrimmedConfigurationCache(
- Function descriptorExtractor,
- Function configurationExtractor,
- ConfigurationComparer configurationComparer) {
- this.descriptorExtractor = descriptorExtractor;
- this.configurationExtractor = configurationExtractor;
- this.configurationComparer = configurationComparer;
- this.descriptors = newCacheMap();
- }
-
- /**
- * Looks for a key with the same descriptor as the input key, which has a configuration that
- * trimmed to a subset of the input key's.
- *
- * Note that this is not referring to a proper subset; it's quite possible for a key
- * to "trim" to a configuration equal to its configuration. That is, without anything being
- * removed.
- *
- *
If such a key has been added to this cache, it is returned in a present {@link Optional}.
- * Invoking this key will produce the same result as invoking the input key.
- *
- *
If no such key has been added to this cache, or if a key has been added to the cache and
- * subsequently been the subject of an {@link #invalidate(KeyT)}, an absent Optional will be
- * returned instead. No currently-valid key has trimmed to an equivalent configuration, and so the
- * input key should be executed.
- */
- public Optional get(KeyT input) {
- DescriptorT descriptor = getDescriptorFor(input);
- ConcurrentHashMap> trimmingsOfDescriptor =
- descriptors.get(descriptor);
- if (trimmingsOfDescriptor == null) {
- // There are no entries at all for this descriptor.
- return Optional.empty();
- }
- ConfigurationT candidateConfiguration = getConfigurationFor(input);
- for (Entry> entry : trimmingsOfDescriptor.entrySet()) {
- ConfigurationT trimmedConfig = entry.getKey();
- KeyAndState canonicalKeyAndState = entry.getValue();
- if (canSubstituteFor(candidateConfiguration, trimmedConfig, canonicalKeyAndState)) {
- return Optional.of(canonicalKeyAndState.getKey());
- }
- }
- return Optional.empty();
- }
-
- /**
- * Returns whether the given trimmed configuration and key are a suitable substitute for the
- * candidate configuration.
- */
- private boolean canSubstituteFor(
- ConfigurationT candidateConfiguration,
- ConfigurationT trimmedConfiguration,
- KeyAndState canonicalKeyAndState) {
- return canonicalKeyAndState.getState().isKnownValid()
- && compareConfigurations(trimmedConfiguration, candidateConfiguration).isSubsetOrEqual();
- }
-
- /**
- * Attempts to record the given key as the canonical invocation for its descriptor and the
- * passed-in trimmed configuration.
- *
- * The trimmed configuration must be a subset of the input key's configuration. Otherwise,
- * {@link IllegalArgumentException} will be thrown.
- *
- *
If another key matching this configuration is found, that key will be returned. That key
- * represents the canonical invocation, which should produce the same result as the input key. It
- * may have been previously invalidated, but will be considered revalidated at this point.
- *
- *
Otherwise, if the input key is the first to trim to this configuration, the input key is
- * returned.
- */
- public KeyT putIfAbsent(KeyT canonicalKey, ConfigurationT trimmedConfiguration) {
- ConfigurationT fullConfiguration = getConfigurationFor(canonicalKey);
- Preconditions.checkArgument(
- compareConfigurations(trimmedConfiguration, fullConfiguration).isSubsetOrEqual());
- ConcurrentHashMap> trimmingsOfDescriptor =
- descriptors.computeIfAbsent(getDescriptorFor(canonicalKey), unused -> newDescriptorMap());
- KeyAndState currentMapping =
- trimmingsOfDescriptor.compute(
- trimmedConfiguration,
- (configuration, currentValue) -> {
- if (currentValue == null) {
- return KeyAndState.create(canonicalKey);
- } else {
- return currentValue.asValidated();
- }
- });
- boolean newlyAdded = currentMapping.getKey().equals(canonicalKey);
- int failedRemoves;
- do {
- failedRemoves = 0;
- for (Entry> entry : trimmingsOfDescriptor.entrySet()) {
- if (entry.getValue().getState().equals(KeyAndState.State.POSSIBLY_INVALID)) {
- // Remove invalidated keys where:
- // * the same key evaluated to a different configuration than it does now
- // * (for trimmed configurations not yet seen) the new trimmed configuration has equal
- // values for every fragment it shares with the old configuration (including subsets
- // or supersets).
- // These are keys we know will not be revalidated as part of the current build.
- // Although it also ensures that we don't remove the entry we just added, the check for
- // invalidation is mainly to avoid wasting time checking entries that are still valid for
- // the current build and therefore will not match either of these properties.
- if (entry.getValue().getKey().equals(canonicalKey)
- || (newlyAdded
- && compareConfigurations(trimmedConfiguration, entry.getKey())
- .hasEqualSharedFragments())) {
- if (!trimmingsOfDescriptor.remove(entry.getKey(), entry.getValue())) {
- // It's possible that this entry was removed by another thread in the meantime.
- failedRemoves += 1;
- }
- }
- }
- }
- } while (failedRemoves > 0);
- return currentMapping.getKey();
- }
-
- /**
- * Marks the given key as invalidated.
- *
- * An invalidated key will not be returned from {@link #get(KeyT)}, as it cannot be proven that
- * the key will still trim to the same configuration.
- *
- *
This invalidation is undone if the input key is passed to {@link #revalidate(KeyT)}, or if
- * the configuration it originally trimmed to is passed to a call of {@link putIfAbsent(KeyT,
- * ConfigurationT)}. This is true regardless of whether the key passed to putIfAbsent is the same
- * as the input to this method.
- *
- *
If the key is not currently canonical for any descriptor/configuration pair, or if the key
- * had previously been invalidated and not revalidated, this method has no effect.
- */
- public void invalidate(KeyT key) {
- updateEntryWithRetries(key, KeyAndState::asInvalidated);
- }
-
- /**
- * Unmarks the given key as invalidated.
- *
- *
This undoes the effects of {@link #invalidate(KeyT)}, allowing the key to be returned from
- * {@link #get(KeyT)} again.
- *
- *
If the key is not currently canonical for any descriptor/configuration pair, or if the key
- * had not previously been invalidated or had since been revalidated, this method has no effect.
- */
- public void revalidate(KeyT key) {
- updateEntryWithRetries(key, KeyAndState::asValidated);
- }
-
- /**
- * Completely removes the given key from the cache.
- *
- *
After this call, {@link #get(KeyT)} and {@link #putIfAbsent(KeyT, ConfigurationT)} will no
- * longer return this key unless it is put back in the cache with putIfAbsent.
- *
- *
If the key is not currently canonical for any descriptor/configuration pair, this method has
- * no effect.
- */
- public void remove(KeyT key) {
- // Return null from the transformer to remove the key from the map.
- updateEntryWithRetries(key, unused -> null);
-
- DescriptorT descriptor = getDescriptorFor(key);
- ConcurrentHashMap> trimmingsOfDescriptor =
- descriptors.get(descriptor);
- if (trimmingsOfDescriptor != null && trimmingsOfDescriptor.isEmpty()) {
- descriptors.remove(descriptor, trimmingsOfDescriptor);
- }
- }
-
- /**
- * Finds the entry in the cache where the given key is canonical and updates or removes it.
- *
- * The transformation is applied transactionally; that is, if another change has happened since
- * the value was first looked up, the new value is retrieved and the transformation is applied
- * again. This repeats until there are no conflicts.
- *
- *
This method has no effect if this key is currently not canonical.
- *
- * @param transformation The transformation to apply to the given entry. The entry will be
- * replaced with the value returned from invoking this on the original value. If it returns
- * null, the entry will be removed instead. If it returns the same instance, nothing will be
- * done to the entry.
- */
- private void updateEntryWithRetries(KeyT key, UnaryOperator> transformation) {
- while (!updateEntryIfNoConflicts(key, transformation)) {}
- }
-
- /**
- * Finds the entry in the cache where the given key is canonical and updates or removes it.
- *
- * Only one attempt is made, and if there's a collision with another change, false is returned
- * and the map is not changed.
- *
- *
This method succeeds (returns {@code true}) without doing anything if this key is currently
- * not canonical.
- *
- * @param transformation The transformation to apply to the given entry. The entry will be
- * replaced with the value returned from invoking this on the original value. If it returns
- * null, the entry will be removed instead. If it returns the same instance, nothing will be
- * done to the entry.
- */
- private boolean updateEntryIfNoConflicts(
- KeyT key, UnaryOperator> transformation) {
- DescriptorT descriptor = getDescriptorFor(key);
- ConcurrentHashMap> trimmingsOfDescriptor =
- descriptors.get(descriptor);
- if (trimmingsOfDescriptor == null) {
- // There are no entries at all for this descriptor.
- return true;
- }
-
- for (Entry> entry : trimmingsOfDescriptor.entrySet()) {
- KeyAndState currentValue = entry.getValue();
- if (currentValue.getKey().equals(key)) {
- KeyAndState newValue = transformation.apply(currentValue);
- if (newValue == null) {
- return trimmingsOfDescriptor.remove(entry.getKey(), currentValue);
- } else if (newValue != currentValue) {
- return trimmingsOfDescriptor.replace(entry.getKey(), currentValue, newValue);
- } else {
- // newValue == currentValue, there's nothing to do
- return true;
- }
- }
- }
- // The key requested wasn't in the map, so there's nothing to do
- return true;
- }
-
- /**
- * Removes all keys from this cache, resetting it to its empty state.
- *
- * This is equivalent to calling {@link #remove(KeyT)} on every key which had ever been passed
- * to {@link #putIfAbsent(KeyT, ConfigurationT)}.
- */
- public void clear() {
- // Getting a brand new instance lets the old map be garbage collected, reducing its memory
- // footprint from its previous expansions.
- this.descriptors = newCacheMap();
- }
-
- /** Retrieves the descriptor by calling the descriptorExtractor. */
- private DescriptorT getDescriptorFor(KeyT key) {
- return descriptorExtractor.apply(key);
- }
-
- /** Retrieves the configuration by calling the configurationExtractor. */
- private ConfigurationT getConfigurationFor(KeyT key) {
- return configurationExtractor.apply(key);
- }
-
- /**
- * Checks whether the first configuration is equal to or a subset of the second by calling the
- * configurationComparer.
- */
- private ConfigurationComparer.Result compareConfigurations(
- ConfigurationT left, ConfigurationT right) {
- return configurationComparer.apply(left, right);
- }
-
- /** Generates a new map suitable for storing the cache as a whole. */
- private ConcurrentHashMap>>
- newCacheMap() {
- return new ConcurrentHashMap<>(CACHE_INITIAL_SIZE, CACHE_LOAD_FACTOR, CACHE_CONCURRENCY_LEVEL);
- }
-
- /** Generates a new map suitable for storing the cache of configurations for a descriptor. */
- private ConcurrentHashMap> newDescriptorMap() {
- return new ConcurrentHashMap<>(
- EXPECTED_CONFIGURATIONS_PER_DESCRIPTOR,
- DESCRIPTOR_LOAD_FACTOR,
- DESCRIPTOR_CONCURRENCY_LEVEL);
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BUILD b/src/test/java/com/google/devtools/build/lib/analysis/BUILD
index a7c1bef22a3877..f7c236ac8a6b35 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BUILD
@@ -137,7 +137,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils:depsutils",
- "//src/main/java/com/google/devtools/build/lib/skyframe/trimming:trimmed_configuration_cache",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
"//src/main/java/com/google/devtools/build/lib/util:filetype",
@@ -160,12 +159,10 @@ java_library(
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/rules/platform:testutil",
"//src/test/java/com/google/devtools/build/lib/skyframe:testutil",
- "//src/test/java/com/google/devtools/build/lib/skyframe/trimming:trimmable_test_fragments",
"//src/test/java/com/google/devtools/build/lib/testutil",
"//src/test/java/com/google/devtools/build/lib/testutil:JunitUtils",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
"//src/test/java/com/google/devtools/build/skyframe:testutil",
- "//third_party:auto_value",
"//third_party:guava",
"//third_party:guava-testlib",
"//third_party:jsr305",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildOptionsCompareFragmentsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildOptionsCompareFragmentsTest.java
deleted file mode 100644
index 3464e5f1f91ccc..00000000000000
--- a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildOptionsCompareFragmentsTest.java
+++ /dev/null
@@ -1,474 +0,0 @@
-// Copyright 2018 The Bazel Authors. 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.config;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
-import com.google.auto.value.AutoValue;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.devtools.build.lib.analysis.config.BuildOptions.OptionsDiffForReconstruction;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.skyframe.trimming.ConfigurationComparer;
-import com.google.devtools.build.lib.skyframe.trimming.TrimmableTestConfigurationFragments.AOptions;
-import com.google.devtools.build.lib.skyframe.trimming.TrimmableTestConfigurationFragments.BOptions;
-import java.util.Objects;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-/** Tests of compareFragments in BuildOptions.OptionsDiffForReconstruction. */
-public final class BuildOptionsCompareFragmentsTest {
-
- /** Test cases for BuildOptionsCompareFragmentsTest. */
- @AutoValue
- public abstract static class Case {
- public abstract String getName();
-
- public abstract BuildOptions getBase();
-
- public abstract BuildOptions getLeft();
-
- public abstract BuildOptions getRight();
-
- public abstract ConfigurationComparer.Result getLeftToRightResult();
-
- public abstract ConfigurationComparer.Result getRightToLeftResult();
-
- public static Builder named(String name) {
- return new AutoValue_BuildOptionsCompareFragmentsTest_Case.Builder().setName(name);
- }
-
- /** Quick builder for test cases. */
- @AutoValue.Builder
- public abstract static class Builder {
- public abstract Builder setName(String name);
-
- public abstract Builder setBase(BuildOptions base);
-
- public Builder setBase(OptionsBuilder base) throws Exception {
- return this.setBase(base.build());
- }
-
- public abstract Builder setLeft(BuildOptions left);
-
- public Builder setLeft(OptionsBuilder left) throws Exception {
- return this.setLeft(left.build());
- }
-
- public abstract Builder setRight(BuildOptions right);
-
- public Builder setRight(OptionsBuilder right) throws Exception {
- return this.setRight(right.build());
- }
-
- public Builder setResult(ConfigurationComparer.Result result) {
- return this.setLeftToRightResult(result).setRightToLeftResult(result);
- }
-
- public abstract Builder setLeftToRightResult(ConfigurationComparer.Result result);
-
- public abstract Builder setRightToLeftResult(ConfigurationComparer.Result result);
-
- public abstract Case build();
- }
-
- @Override
- public final String toString() {
- if (Objects.equals(this.getLeftToRightResult(), this.getRightToLeftResult())) {
- return String.format("%s [result = %s]", this.getName(), this.getLeftToRightResult());
- } else {
- return String.format(
- "%s [compare(left, right) = %s; compare(right, left) = %s]",
- this.getName(), this.getLeftToRightResult(), this.getRightToLeftResult());
- }
- }
- }
-
- /** Quick builder for BuildOptions instances. */
- public static final class OptionsBuilder {
- private final ImmutableMap.Builder starlarkOptions =
- new ImmutableMap.Builder<>();
- private final ImmutableList.Builder> fragments =
- new ImmutableList.Builder<>();
- private final ImmutableList.Builder nativeOptions = new ImmutableList.Builder<>();
-
- public OptionsBuilder withNativeFragment(
- Class extends FragmentOptions> fragment, String... flags) {
- this.fragments.add(fragment);
- this.nativeOptions.add(flags);
- return this;
- }
-
- public OptionsBuilder withStarlarkOption(String setting, Object value) {
- this.starlarkOptions.put(Label.parseAbsoluteUnchecked(setting), value);
- return this;
- }
-
- public OptionsBuilder withStarlarkOption(String setting) {
- return this.withStarlarkOption(setting, setting);
- }
-
- public BuildOptions build() throws Exception {
- return BuildOptions.builder()
- .addStarlarkOptions(this.starlarkOptions.build())
- .merge(
- BuildOptions.of(
- this.fragments.build(), this.nativeOptions.build().toArray(new String[0])))
- .build();
- }
- }
-
- /** Test cases for compareFragments which produce an ordinary result. */
- @RunWith(Parameterized.class)
- public static final class NormalCases {
-
- @Parameters(name = "{index}: {0}")
- public static Iterable cases() throws Exception {
- return ImmutableList.of(
- Case.named("both options equal to the base")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class)
- .withStarlarkOption("//alpha"))
- .setLeft(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class)
- .withStarlarkOption("//alpha"))
- .setRight(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class)
- .withStarlarkOption("//alpha"))
- .build(),
- Case.named("both sides change native fragment to same value")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=base"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=new"))
- .setRight(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=new"))
- .build(),
- Case.named("both sides add native fragment with same value")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=new"))
- .setRight(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=new"))
- .build(),
- Case.named("both sides remove same native fragment")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setLeft(new OptionsBuilder())
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("both sides change Starlark option to same value")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha", "base"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "new"))
- .setRight(new OptionsBuilder().withStarlarkOption("//alpha", "new"))
- .build(),
- Case.named("both sides add Starlark option with same value")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "new"))
- .setRight(new OptionsBuilder().withStarlarkOption("//alpha", "new"))
- .build(),
- Case.named("both sides remove same Starlark option")
- .setResult(ConfigurationComparer.Result.EQUAL)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setLeft(new OptionsBuilder())
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("native fragment removed from right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUPERSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUBSET)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("native fragment added to right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUBSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUPERSET)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder())
- .setRight(new OptionsBuilder().withNativeFragment(AOptions.class))
- .build(),
- Case.named("native fragment changed in left and removed from right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUPERSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUBSET)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=base"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=left"))
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("native fragment added to left and another fragment removed from right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUPERSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUBSET)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setLeft(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class)
- .withNativeFragment(BOptions.class))
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("Starlark option removed from right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUPERSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUBSET)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("Starlark option added to right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUBSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUPERSET)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder())
- .setRight(new OptionsBuilder().withStarlarkOption("//alpha"))
- .build(),
- Case.named("Starlark option changed in left and removed from right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUPERSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUBSET)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha", "base"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "left"))
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("Starlark option added to left and another option removed from right")
- .setLeftToRightResult(ConfigurationComparer.Result.SUPERSET)
- .setRightToLeftResult(ConfigurationComparer.Result.SUBSET)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setLeft(
- new OptionsBuilder().withStarlarkOption("//alpha").withStarlarkOption("//bravo"))
- .setRight(new OptionsBuilder())
- .build(),
- Case.named("different native fragment added to each side")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class))
- .build(),
- Case.named("different native fragment removed from each side")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class)
- .withNativeFragment(BOptions.class))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class))
- .build(),
- Case.named("native fragment added and different fragment removed on left")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder().withNativeFragment(BOptions.class))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class))
- .build(),
- Case.named(
- "native fragment added to right; "
- + "other fragment changed on left and removed from right")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=base"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=left"))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class))
- .build(),
- Case.named("native fragment changed on each side, removed from the other")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class, "--alpha=base")
- .withNativeFragment(BOptions.class, "--bravo=base"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=left"))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class, "--bravo=right"))
- .build(),
- Case.named(
- "native fragment changed on left, removed from right; "
- + "other fragment removed from left")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class, "--alpha=base")
- .withNativeFragment(BOptions.class))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=left"))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class))
- .build(),
- Case.named("different Starlark option added to each side")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo"))
- .build(),
- Case.named("different Starlark option removed from each side")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder().withStarlarkOption("//alpha").withStarlarkOption("//bravo"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo"))
- .build(),
- Case.named("Starlark option added and different option removed on left")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder().withStarlarkOption("//bravo"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo"))
- .build(),
- Case.named(
- "Starlark option added to right; "
- + "other option changed on left and removed from right")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha", "base"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "left"))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo"))
- .build(),
- Case.named("Starlark option changed on each side, removed from the other")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder()
- .withStarlarkOption("//alpha", "base")
- .withStarlarkOption("//bravo", "base"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "left"))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo", "right"))
- .build(),
- Case.named(
- "Starlark option changed on left, removed from right; "
- + "other option removed from left")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder()
- .withStarlarkOption("//alpha", "base")
- .withStarlarkOption("//bravo"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "left"))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo"))
- .build(),
- Case.named("Starlark option removed from left, native option removed from right")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(
- new OptionsBuilder()
- .withNativeFragment(AOptions.class)
- .withStarlarkOption("//bravo"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class))
- .setRight(new OptionsBuilder().withStarlarkOption("//bravo"))
- .build(),
- Case.named("Starlark option added to left, native option added to right")
- .setResult(ConfigurationComparer.Result.ALL_SHARED_FRAGMENTS_EQUAL)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha"))
- .setRight(new OptionsBuilder().withNativeFragment(BOptions.class))
- .build(),
- Case.named("native fragment is unchanged in left, changes in right")
- .setResult(ConfigurationComparer.Result.DIFFERENT)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=base"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=base"))
- .setRight(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=right"))
- .build(),
- Case.named("native fragment is changed to different values")
- .setResult(ConfigurationComparer.Result.DIFFERENT)
- .setBase(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=base"))
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=left"))
- .setRight(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=right"))
- .build(),
- Case.named("native fragment is added with different values")
- .setResult(ConfigurationComparer.Result.DIFFERENT)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=left"))
- .setRight(new OptionsBuilder().withNativeFragment(AOptions.class, "--alpha=right"))
- .build(),
- Case.named("Starlark option is unchanged in left, changes in right")
- .setResult(ConfigurationComparer.Result.DIFFERENT)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha", "base"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "base"))
- .setRight(new OptionsBuilder().withStarlarkOption("//alpha", "right"))
- .build(),
- Case.named("Starlark option is changed to different values")
- .setResult(ConfigurationComparer.Result.DIFFERENT)
- .setBase(new OptionsBuilder().withStarlarkOption("//alpha", "base"))
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "left"))
- .setRight(new OptionsBuilder().withStarlarkOption("//alpha", "right"))
- .build(),
- Case.named("Starlark option is added with different values")
- .setResult(ConfigurationComparer.Result.DIFFERENT)
- .setBase(new OptionsBuilder())
- .setLeft(new OptionsBuilder().withStarlarkOption("//alpha", "left"))
- .setRight(new OptionsBuilder().withStarlarkOption("//alpha", "right"))
- .build());
- }
-
- private final Case testCase;
-
- public NormalCases(Case testCase) {
- this.testCase = testCase;
- }
-
- @Test
- public void compareLeftToRight() throws Exception {
- OptionsDiffForReconstruction diffLeft =
- BuildOptions.diffForReconstruction(testCase.getBase(), testCase.getLeft());
- OptionsDiffForReconstruction diffRight =
- BuildOptions.diffForReconstruction(testCase.getBase(), testCase.getRight());
-
- assertThat(OptionsDiffForReconstruction.compareFragments(diffLeft, diffRight))
- .isEqualTo(testCase.getLeftToRightResult());
- }
-
- @Test
- public void compareRightToLeft() throws Exception {
- OptionsDiffForReconstruction diffLeft =
- BuildOptions.diffForReconstruction(testCase.getBase(), testCase.getLeft());
- OptionsDiffForReconstruction diffRight =
- BuildOptions.diffForReconstruction(testCase.getBase(), testCase.getRight());
-
- assertThat(OptionsDiffForReconstruction.compareFragments(diffRight, diffLeft))
- .isEqualTo(testCase.getRightToLeftResult());
- }
- }
-
- /** Test cases for compareFragments which produce errors. */
- @RunWith(JUnit4.class)
- public static final class ExceptionalCases {
- @Test
- public void withDifferentBases_throwsError() throws Exception {
- BuildOptions baseA =
- new OptionsBuilder()
- .withNativeFragment(AOptions.class, "--alpha=A")
- .withNativeFragment(BOptions.class, "--bravo=base")
- .build();
- BuildOptions newA =
- new OptionsBuilder()
- .withNativeFragment(AOptions.class, "--alpha=A")
- .withNativeFragment(BOptions.class, "--bravo=new")
- .build();
- BuildOptions baseB =
- new OptionsBuilder()
- .withNativeFragment(AOptions.class, "--alpha=B")
- .withNativeFragment(BOptions.class, "--bravo=base")
- .build();
- BuildOptions newB =
- new OptionsBuilder()
- .withNativeFragment(AOptions.class, "--alpha=B")
- .withNativeFragment(BOptions.class, "--bravo=old")
- .build();
-
- OptionsDiffForReconstruction diffA = BuildOptions.diffForReconstruction(baseA, newA);
- OptionsDiffForReconstruction diffB = BuildOptions.diffForReconstruction(baseB, newB);
-
- IllegalArgumentException forwardException =
- assertThrows(
- IllegalArgumentException.class,
- () -> OptionsDiffForReconstruction.compareFragments(diffA, diffB));
- assertThat(forwardException).hasMessageThat().contains("diffs with different bases");
-
- IllegalArgumentException reverseException =
- assertThrows(
- IllegalArgumentException.class,
- () -> OptionsDiffForReconstruction.compareFragments(diffB, diffA));
- assertThat(reverseException).hasMessageThat().contains("diffs with different bases");
- }
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewForTesting.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewForTesting.java
index 3f8b306cabd260..293a0b777752ff 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewForTesting.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewForTesting.java
@@ -18,7 +18,6 @@
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.Streams.stream;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Functions;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
@@ -32,7 +31,6 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
-import com.google.common.collect.Streams;
import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.actions.ActionLookupKey;
import com.google.devtools.build.lib.actions.ArtifactFactory;
@@ -160,7 +158,6 @@ public BuildViewForTesting(
this.skyframeBuildView = skyframeExecutor.getSkyframeBuildView();
}
- @VisibleForTesting
public Set getSkyframeEvaluatedActionLookupKeyCountForTesting() {
Set actionLookupKeys = populateActionLookupKeyMapAndGetDiff();
Preconditions.checkState(
@@ -188,7 +185,6 @@ private Set populateActionLookupKeyMapAndGetDiff() {
/**
* Returns whether the given configured target has errors.
*/
- @VisibleForTesting
public boolean hasErrors(ConfiguredTarget configuredTarget) {
return configuredTarget == null;
}
@@ -223,8 +219,7 @@ public AnalysisResult update(
eventBus);
}
- /** Sets the configurations. Not thread-safe. DO NOT CALL except from tests! */
- @VisibleForTesting
+ /** Sets the configurations. Not thread-safe. */
public void setConfigurationsForTesting(
EventHandler eventHandler, BuildConfigurationCollection configurations) {
skyframeBuildView.setConfigurations(
@@ -242,7 +237,6 @@ public ArtifactFactory getArtifactFactory() {
* the fragments needed by the fragment and its transitive closure. Else unconditionally includes
* all fragments.
*/
- @VisibleForTesting
public BuildConfiguration getConfigurationForTesting(
Target target, BuildConfiguration config, ExtendedEventHandler eventHandler)
throws InvalidConfigurationException, InterruptedException {
@@ -262,22 +256,19 @@ public BuildConfiguration getConfigurationForTesting(
* Sets the possible artifact roots in the artifact factory. This allows the factory to resolve
* paths with unknown roots to artifacts.
*/
- @VisibleForTesting // for BuildViewTestCase
public void setArtifactRoots(PackageRoots packageRoots) {
getArtifactFactory().setPackageRoots(packageRoots.getPackageRootLookup());
}
- @VisibleForTesting
// TODO(janakr): pass the configuration in as a parameter here.
public Collection getDirectPrerequisitesForTesting(
ExtendedEventHandler eventHandler,
ConfiguredTarget ct,
BuildConfigurationCollection configurations)
- throws DependencyResolver.Failure, InvalidConfigurationException, InterruptedException,
+ throws DependencyResolver.Failure, InvalidConfigurationException,
InconsistentAspectOrderException, StarlarkTransition.TransitionException {
return Collections2.transform(
- getConfiguredTargetAndDataDirectPrerequisitesForTesting(
- eventHandler, ct, ct.getConfigurationKey(), configurations),
+ getConfiguredTargetAndDataDirectPrerequisitesForTesting(eventHandler, ct, configurations),
ConfiguredTargetAndData::getConfiguredTarget);
}
@@ -285,9 +276,8 @@ public Collection getDirectPrerequisitesForTesting(
getConfiguredTargetAndDataDirectPrerequisitesForTesting(
ExtendedEventHandler eventHandler,
ConfiguredTarget ct,
- BuildConfigurationValue.Key configuration,
BuildConfigurationCollection configurations)
- throws DependencyResolver.Failure, InvalidConfigurationException, InterruptedException,
+ throws DependencyResolver.Failure, InvalidConfigurationException,
InconsistentAspectOrderException, StarlarkTransition.TransitionException {
SkyframeExecutorWrappingWalkableGraph walkableGraph =
@@ -313,23 +303,18 @@ public Collection getDirectPrerequisitesForTesting(
walkableGraph.getDirectDeps(
ConfiguredTargetKey.builder().setConfiguredTarget(ct).build());
- // Turn the keys back into ConfiguredTarget instances, possibly merging in aspects that
- // were propagated from the original target.
- Collection cts =
- Streams.stream(directPrerequisites)
- .filter(dep -> dep instanceof ConfiguredTargetKey)
- .map(dep -> (ConfiguredTargetKey) dep)
- .map(configuredTargetKey -> getConfiguredTarget(walkableGraph, configuredTargetKey))
- // For each configured target, add in any aspects from depNodeNames.
- .map(
- configuredTarget ->
- mergeAspects(
- walkableGraph,
- configuredTarget,
- findDependencyKey(dependencyKeys, configuredTarget)))
- .collect(toImmutableList());
-
- return cts;
+ // Turn the keys back into ConfiguredTarget instances, possibly merging in aspects that were
+ // propagated from the original target.
+ return stream(Iterables.filter(directPrerequisites, ConfiguredTargetKey.class))
+ .map(configuredTargetKey -> getConfiguredTarget(walkableGraph, configuredTargetKey))
+ // For each configured target, add in any aspects from depNodeNames.
+ .map(
+ configuredTarget ->
+ mergeAspects(
+ walkableGraph,
+ configuredTarget,
+ findDependencyKey(dependencyKeys, configuredTarget)))
+ .collect(toImmutableList());
} catch (InterruptedException e) {
return ImmutableList.of();
}
@@ -363,7 +348,7 @@ private static ConfiguredTargetAndData getConfiguredTarget(
}
@Nullable
- private DependencyKey findDependencyKey(
+ private static DependencyKey findDependencyKey(
Multimap dependencyKeys, ConfiguredTargetAndData configuredTarget) {
// TODO(blaze-configurability): Figure out how to map the ConfiguredTarget back to the correct
// DependencyKey when there are more than one.
@@ -371,7 +356,7 @@ private DependencyKey findDependencyKey(
}
// Helper method to find the aspects needed for a target and merge them.
- protected ConfiguredTargetAndData mergeAspects(
+ protected static ConfiguredTargetAndData mergeAspects(
WalkableGraph graph, ConfiguredTargetAndData ctd, @Nullable DependencyKey dependencyKey) {
if (dependencyKey == null || dependencyKey.getAspects().getUsedAspects().isEmpty()) {
return ctd;
@@ -400,7 +385,6 @@ protected ConfiguredTargetAndData mergeAspects(
}
}
- @VisibleForTesting
public OrderedSetMultimap
getDirectPrerequisiteDependenciesForTesting(
final ExtendedEventHandler eventHandler,
@@ -410,7 +394,7 @@ protected ConfiguredTargetAndData mergeAspects(
throws DependencyResolver.Failure, InterruptedException, InconsistentAspectOrderException,
StarlarkTransition.TransitionException, InvalidConfigurationException {
- Target target = null;
+ Target target;
try {
target = skyframeExecutor.getPackageManager().getTarget(eventHandler, ct.getLabel());
} catch (NoSuchPackageException | NoSuchTargetException | InterruptedException e) {
@@ -558,7 +542,6 @@ private ConfigurationTransition getTopLevelTransitionForTarget(
*
* Returns {@code null} if something goes wrong.
*/
- @VisibleForTesting
public ConfiguredTarget getConfiguredTargetForTesting(
ExtendedEventHandler eventHandler, Label label, BuildConfiguration config)
throws StarlarkTransition.TransitionException, InvalidConfigurationException,
@@ -571,7 +554,6 @@ public ConfiguredTarget getConfiguredTargetForTesting(
return skyframeExecutor.getConfiguredTargetForTesting(eventHandler, label, config, transition);
}
- @VisibleForTesting
ConfiguredTargetAndData getConfiguredTargetAndDataForTesting(
ExtendedEventHandler eventHandler, Label label, BuildConfiguration config)
throws StarlarkTransition.TransitionException, InvalidConfigurationException,
@@ -588,7 +570,6 @@ ConfiguredTargetAndData getConfiguredTargetAndDataForTesting(
/**
* Returns a RuleContext which is the same as the original RuleContext of the target parameter.
*/
- @VisibleForTesting
public RuleContext getRuleContextForTesting(
ConfiguredTarget target,
StoredEventHandler eventHandler,
@@ -611,7 +592,6 @@ public RuleContext getRuleContextForTesting(
.setLabel(target.getLabel())
.setConfiguration(targetConfig)
.build(),
- /*isSystemEnv=*/ false,
targetConfig.extendedSanityChecks(),
targetConfig.allowAnalysisFailures(),
eventHandler,
@@ -624,7 +604,6 @@ public RuleContext getRuleContextForTesting(
* Creates and returns a rule context that is equivalent to the one that was used to create the
* given configured target.
*/
- @VisibleForTesting
public RuleContext getRuleContextForTesting(
ExtendedEventHandler eventHandler,
ConfiguredTarget configuredTarget,
@@ -635,7 +614,7 @@ public RuleContext getRuleContextForTesting(
StarlarkTransition.TransitionException, InvalidExecGroupException {
BuildConfiguration targetConfig =
skyframeExecutor.getConfiguration(eventHandler, configuredTarget.getConfigurationKey());
- Target target = null;
+ Target target;
try {
target =
skyframeExecutor.getPackageManager().getTarget(eventHandler, configuredTarget.getLabel());
@@ -740,7 +719,6 @@ public RuleContext getRuleContextForTesting(
}
/** Clears the analysis cache as in --discard_analysis_cache. */
- @VisibleForTesting
void clearAnalysisCache(
Collection topLevelTargets, ImmutableSet topLevelAspects) {
skyframeBuildView.clearAnalysisCache(topLevelTargets, topLevelAspects);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index b1da3f99160c67..aac74b6f7ed62c 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -338,9 +338,9 @@ public void initializeSkyframeExecutor(boolean doPackageLoadingChecks) throws Ex
packageOptions,
buildLanguageOptions,
UUID.randomUUID(),
- ImmutableMap.of(),
+ ImmutableMap.of(),
tsgm);
- skyframeExecutor.setActionEnv(ImmutableMap.of());
+ skyframeExecutor.setActionEnv(ImmutableMap.of());
useConfiguration();
setUpSkyframe();
this.actionLogBufferPathGenerator =
@@ -411,7 +411,7 @@ protected final PackageFactory getPackageFactory() {
}
protected Iterable getEnvironmentExtensions() {
- return ImmutableList.of();
+ return ImmutableList.of();
}
protected StarlarkSemantics getStarlarkSemantics() {
@@ -452,8 +452,7 @@ protected final BuildConfigurationCollection createConfigurations(
optionsParser.setStarlarkOptions(starlarkOptions);
BuildOptions buildOptions = ruleClassProvider.createBuildOptions(optionsParser);
- return skyframeExecutor.createConfigurations(
- reporter, buildOptions, ImmutableSet.of(), false);
+ return skyframeExecutor.createConfigurations(reporter, buildOptions, ImmutableSet.of(), false);
}
protected Target getTarget(String label)
@@ -559,8 +558,6 @@ protected void invalidatePackages() throws InterruptedException {
* Invalidates all existing packages. Optionally invalidates configurations too.
*
* Tests should invalidate both unless they have specific reason not to.
- *
- * @throws InterruptedException
*/
protected void invalidatePackages(boolean alsoConfigs) throws InterruptedException {
skyframeExecutor.invalidateFilesUnderPathForTesting(
@@ -605,7 +602,6 @@ protected Iterable getDefaultsForConfiguration() {
* @param starlarkOptions map of Starlark-defined options where the keys are option names (in the
* form of label-like strings) and the values are option values
* @param args native option name/pair descriptions in command line form (e.g. "--cpu=k8")
- * @throws IllegalArgumentException
*/
protected void useConfiguration(ImmutableMap starlarkOptions, String... args)
throws Exception {
@@ -624,11 +620,10 @@ protected void useConfiguration(String... args) throws Exception {
}
/**
- * Creates BuildView using current hostConfig/targetConfig values.
- * Ensures that hostConfig is either identical to the targetConfig or has
- * 'host' short name.
+ * Creates BuildView using current hostConfig/targetConfig values. Ensures that hostConfig is
+ * either identical to the targetConfig or has 'host' short name.
*/
- protected final void createBuildView() throws Exception {
+ protected final void createBuildView() {
Preconditions.checkNotNull(masterConfig);
Preconditions.checkState(getHostConfiguration().equals(getTargetConfiguration())
|| getHostConfiguration().isHostConfiguration(),
@@ -664,7 +659,6 @@ public SkyFunctionName functionName() {
return null;
}
},
- /*isSystemEnv=*/ true,
/*extendedSanityChecks=*/ false,
/*allowAnalysisFailures=*/ false,
reporter,
@@ -680,7 +674,7 @@ public SkyFunctionName functionName() {
*/
protected final Collection getDirectPrerequisites(ConfiguredTarget target)
throws TransitionException, InvalidConfigurationException, InconsistentAspectOrderException,
- Failure, InterruptedException {
+ Failure {
return view.getDirectPrerequisitesForTesting(reporter, target, masterConfig);
}
@@ -703,7 +697,6 @@ protected final ConfiguredTargetAndData getConfiguredTargetAndDataDirectPrerequi
view.getConfiguredTargetAndDataDirectPrerequisitesForTesting(
reporter,
ctad.getConfiguredTarget(),
- ctad.getConfiguredTarget().getConfigurationKey(),
masterConfig)) {
if (candidate.getConfiguredTarget().getLabel().equals(candidateLabel)) {
return candidate;
@@ -733,10 +726,10 @@ private static BuildOptions trimConfiguration(
* comparison.
*
* Generally, this means they share the same checksum, which is computed by iterating over all
- * the individual @Option annotated values contained within the {@link FragmentOption} classes
+ * the individual @Option annotated values contained within the {@link FragmentOptions} classes
* contained within the {@link BuildOptions} inside the given configurations.
*/
- protected void assertConfigurationsEqual(
+ protected static void assertConfigurationsEqual(
BuildConfiguration config1,
BuildConfiguration config2,
Set> excludeFragmentOptions) {
@@ -747,8 +740,9 @@ protected void assertConfigurationsEqual(
.isEqualTo(trimConfiguration(config1.cloneOptions(), excludeFragmentOptions));
}
- protected void assertConfigurationsEqual(BuildConfiguration config1, BuildConfiguration config2) {
- assertConfigurationsEqual(config1, config2, ImmutableSet.of());
+ protected static void assertConfigurationsEqual(
+ BuildConfiguration config1, BuildConfiguration config2) {
+ assertConfigurationsEqual(config1, config2, /*excludeFragmentOptions=*/ ImmutableSet.of());
}
/**
@@ -1099,11 +1093,9 @@ public void rewriteWorkspace(String... lines) throws Exception {
* @param ruleName the name of the rule.
* @param lines the text of the rule.
* @return the configured target instance for the created rule.
- * @throws IOException
- * @throws Exception
*/
protected ConfiguredTarget scratchConfiguredTarget(
- String packageName, String ruleName, String... lines) throws IOException, Exception {
+ String packageName, String ruleName, String... lines) throws Exception {
return scratchConfiguredTarget(packageName, ruleName, targetConfig, lines);
}
@@ -1115,12 +1107,10 @@ protected ConfiguredTarget scratchConfiguredTarget(
* @param config the configuration to use to construct the configured rule.
* @param lines the text of the rule.
* @return the configured target instance for the created rule.
- * @throws IOException
- * @throws Exception
*/
protected ConfiguredTarget scratchConfiguredTarget(
String packageName, String ruleName, BuildConfiguration config, String... lines)
- throws IOException, Exception {
+ throws Exception {
ConfiguredTargetAndData ctad =
scratchConfiguredTargetAndData(packageName, ruleName, config, lines);
return ctad == null ? null : ctad.getConfiguredTarget();
@@ -1133,7 +1123,6 @@ protected ConfiguredTarget scratchConfiguredTarget(
* @param rulename the name of the rule.
* @param lines the text of the rule.
* @return the configured tatarget and target instance for the created rule.
- * @throws Exception
*/
protected ConfiguredTargetAndData scratchConfiguredTargetAndData(
String packageName, String rulename, String... lines) throws Exception {
@@ -1148,8 +1137,6 @@ protected ConfiguredTargetAndData scratchConfiguredTargetAndData(
* @param config the configuration to use to construct the configured rule.
* @param lines the text of the rule.
* @return the ConfiguredTargetAndData instance for the created rule.
- * @throws IOException
- * @throws Exception
*/
protected ConfiguredTargetAndData scratchConfiguredTargetAndData(
String packageName, String ruleName, BuildConfiguration config, String... lines)
@@ -1165,8 +1152,6 @@ protected ConfiguredTargetAndData scratchConfiguredTargetAndData(
* @param ruleName the name of the rule.
* @param lines the text of the rule.
* @return the rule instance for the created rule.
- * @throws IOException
- * @throws Exception
*/
protected Rule scratchRule(String packageName, String ruleName, String... lines)
throws Exception {
@@ -1427,7 +1412,7 @@ private Artifact getPackageRelativeDerivedArtifact(
}
/** Returns the input {@link Artifact}s to the given {@link Action} with the given exec paths. */
- protected List getInputs(Action owner, Collection execPaths) {
+ protected static List getInputs(Action owner, Collection execPaths) {
Set expectedPaths = new HashSet<>(execPaths);
List result = new ArrayList<>();
for (Artifact output : owner.getInputs().toList()) {
@@ -1664,11 +1649,11 @@ protected String stripCppPrefixForTrimmedConfigs(String outputPath) {
: outputPath;
}
- protected String fileName(Artifact artifact) {
+ protected static String fileName(Artifact artifact) {
return artifact.getExecPathString();
}
- protected String fileName(FileConfiguredTarget target) {
+ protected static String fileName(FileConfiguredTarget target) {
return fileName(target.getArtifact());
}
@@ -1722,8 +1707,9 @@ protected void assertSrcsValidityForRuleType(String packageName, String ruleType
"'" + packageName + ":a.foo' does not produce any " + descriptionPlural);
}
- protected void assertSrcsValidity(String ruleType, String targetName, boolean expectedError,
- String... expectedMessages) throws Exception{
+ protected void assertSrcsValidity(
+ String ruleType, String targetName, boolean expectedError, String... expectedMessages)
+ throws Exception {
ConfiguredTarget target = getConfiguredTarget(targetName);
if (expectedError) {
assertThat(view.hasErrors(target)).isTrue();
@@ -1757,10 +1743,10 @@ private ConfiguredTargetKey makeConfiguredTargetKey(String label) {
.build();
}
- protected static List actionInputsToPaths(NestedSet extends ActionInput> actionInputs) {
+ protected static ImmutableList actionInputsToPaths(
+ NestedSet extends ActionInput> actionInputs) {
return ImmutableList.copyOf(
- Iterables.transform(
- actionInputs.toList(), (actionInput) -> actionInput.getExecPathString()));
+ Lists.transform(actionInputs.toList(), ActionInput::getExecPathString));
}
/**
@@ -1774,20 +1760,19 @@ protected void assertSameContentsWithCommonElements(Iterable artifacts,
}
/**
- * Utility method for asserting that a list contains the elements of a
- * sublist. This is useful for checking that a list of arguments contains a
- * particular set of arguments.
+ * Utility method for asserting that a list contains the elements of a sublist. This is useful for
+ * checking that a list of arguments contains a particular set of arguments.
*/
- protected void assertContainsSublist(List list, List sublist) {
+ protected static void assertContainsSublist(List list, List sublist) {
assertContainsSublist(null, list, sublist);
}
/**
- * Utility method for asserting that a list contains the elements of a
- * sublist. This is useful for checking that a list of arguments contains a
- * particular set of arguments.
+ * Utility method for asserting that a list contains the elements of a sublist. This is useful for
+ * checking that a list of arguments contains a particular set of arguments.
*/
- protected void assertContainsSublist(String message, List list, List sublist) {
+ protected static void assertContainsSublist(
+ String message, List list, List sublist) {
if (Collections.indexOfSubList(list, sublist) == -1) {
fail((message == null ? "" : (message + ' '))
+ "expected: <" + list + "> to contain sublist: <" + sublist + ">");
@@ -1795,10 +1780,10 @@ protected void assertContainsSublist(String message, List list, List collectRunfiles(ConfiguredTarget target) {
+ protected static NestedSet collectRunfiles(ConfiguredTarget target) {
RunfilesProvider runfilesProvider = target.getProvider(RunfilesProvider.class);
if (runfilesProvider != null) {
return runfilesProvider.getDefaultRunfiles().getAllArtifacts();
@@ -1807,7 +1792,7 @@ protected NestedSet collectRunfiles(ConfiguredTarget target) {
}
}
- protected NestedSet getFilesToBuild(TransitiveInfoCollection target) {
+ protected static NestedSet getFilesToBuild(TransitiveInfoCollection target) {
return target.getProvider(FileProvider.class).getFilesToBuild();
}
@@ -1851,15 +1836,16 @@ protected ImmutableList getFilesToBuildActions(ConfiguredTarget target)
return ImmutableList.copyOf(result);
}
- protected NestedSet getOutputGroup(
+ protected static NestedSet getOutputGroup(
TransitiveInfoCollection target, String outputGroup) {
OutputGroupInfo provider = OutputGroupInfo.get(target);
return provider == null
- ? NestedSetBuilder.emptySet(Order.STABLE_ORDER)
+ ? NestedSetBuilder.emptySet(Order.STABLE_ORDER)
: provider.getOutputGroup(outputGroup);
}
- protected NestedSet getExtraActionArtifacts(ConfiguredTarget target) {
+ protected static NestedSet getExtraActionArtifacts(
+ ConfiguredTarget target) {
return target.getProvider(ExtraActionArtifactsProvider.class).getExtraActionArtifacts();
}
@@ -1867,15 +1853,15 @@ protected Artifact getExecutable(String label) throws Exception {
return getConfiguredTarget(label).getProvider(FilesToRunProvider.class).getExecutable();
}
- protected Artifact getExecutable(TransitiveInfoCollection target) {
+ protected static Artifact getExecutable(TransitiveInfoCollection target) {
return target.getProvider(FilesToRunProvider.class).getExecutable();
}
- protected NestedSet getFilesToRun(TransitiveInfoCollection target) {
+ protected static NestedSet getFilesToRun(TransitiveInfoCollection target) {
return target.getProvider(FilesToRunProvider.class).getFilesToRun();
}
- protected NestedSet getFilesToRun(Label label) throws Exception {
+ protected NestedSet getFilesToRun(Label label) {
return getConfiguredTarget(label, targetConfig)
.getProvider(FilesToRunProvider.class).getFilesToRun();
}
@@ -1888,7 +1874,7 @@ protected RunfilesSupport getRunfilesSupport(String label) throws Exception {
return getConfiguredTarget(label).getProvider(FilesToRunProvider.class).getRunfilesSupport();
}
- protected RunfilesSupport getRunfilesSupport(TransitiveInfoCollection target) {
+ protected static RunfilesSupport getRunfilesSupport(TransitiveInfoCollection target) {
return target.getProvider(FilesToRunProvider.class).getRunfilesSupport();
}
@@ -1984,7 +1970,7 @@ protected AnalysisResult update(List targets,
boolean doAnalysis,
EventBus eventBus) throws Exception {
return update(
- targets, ImmutableList.of(), keepGoing, loadingPhaseThreads, doAnalysis, eventBus);
+ targets, ImmutableList.of(), keepGoing, loadingPhaseThreads, doAnalysis, eventBus);
}
protected AnalysisResult update(
@@ -2058,51 +2044,53 @@ public static Set asLabelSet(Iterable strings) throws LabelSyntax
return result;
}
- protected String getErrorMsgNoGoodFiles(String attrName, String ruleType, String ruleName,
- String depRuleName) {
+ protected static String getErrorMsgNoGoodFiles(
+ String attrName, String ruleType, String ruleName, String depRuleName) {
return "in " + attrName + " attribute of " + ruleType + " rule " + ruleName + ": '"
+ depRuleName + "' does not produce any " + ruleType + " " + attrName + " files";
}
- protected String getErrorMsgMisplacedFiles(String attrName, String ruleType, String ruleName,
- String fileName) {
+ protected static String getErrorMsgMisplacedFiles(
+ String attrName, String ruleType, String ruleName, String fileName) {
return "in " + attrName + " attribute of " + ruleType + " rule " + ruleName + ": source file '"
+ fileName + "' is misplaced here";
}
- protected String getErrorNonExistingTarget(String attrName, String ruleType, String ruleName,
- String targetName) {
+ protected static String getErrorNonExistingTarget(
+ String attrName, String ruleType, String ruleName, String targetName) {
return "in " + attrName + " attribute of " + ruleType + " rule " + ruleName + ": target '"
+ targetName + "' does not exist";
}
- protected String getErrorNonExistingRule(String attrName, String ruleType, String ruleName,
- String targetName) {
+ protected static String getErrorNonExistingRule(
+ String attrName, String ruleType, String ruleName, String targetName) {
return "in " + attrName + " attribute of " + ruleType + " rule " + ruleName + ": rule '"
+ targetName + "' does not exist";
}
- protected String getErrorMsgMisplacedRules(String attrName, String ruleType, String ruleName,
- String depRuleType, String depRuleName) {
+ protected static String getErrorMsgMisplacedRules(
+ String attrName, String ruleType, String ruleName, String depRuleType, String depRuleName) {
return "in " + attrName + " attribute of " + ruleType + " rule " + ruleName + ": "
+ depRuleType + " rule '" + depRuleName + "' is misplaced here";
}
- protected String getErrorMsgNonEmptyList(String attrName, String ruleType, String ruleName) {
+ protected static String getErrorMsgNonEmptyList(
+ String attrName, String ruleType, String ruleName) {
return "in " + attrName + " attribute of " + ruleType + " rule " + ruleName + ": attribute "
+ "must be non empty";
}
- protected String getErrorMsgMandatoryMissing(String attrName, String ruleType) {
+ protected static String getErrorMsgMandatoryMissing(String attrName, String ruleType) {
return "missing value for mandatory attribute '" + attrName + "' in '" + ruleType + "' rule";
}
- protected String getErrorMsgWrongAttributeValue(String value, String... expected) {
+ protected static String getErrorMsgWrongAttributeValue(String value, String... expected) {
return String.format("has to be one of %s instead of '%s'",
StringUtil.joinEnglishList(ImmutableSet.copyOf(expected), "or", "'"), value);
}
- protected String getErrorMsgMandatoryProviderMissing(String offendingRule, String providerName) {
+ protected static String getErrorMsgMandatoryProviderMissing(
+ String offendingRule, String providerName) {
return String.format("'%s' does not have mandatory providers: '%s'",
offendingRule, providerName);
}
@@ -2122,7 +2110,7 @@ protected com.google.devtools.build.lib.packages.Package createScratchPackageFor
String packageName, String... lines) throws Exception {
eventCollector.clear();
reporter.removeHandler(failFastHandler);
- scratch.file("" + packageName + "/BUILD", lines);
+ scratch.file(packageName + "/BUILD", lines);
return getPackageManager()
.getPackage(reporter, PackageIdentifier.createInMainRepo(packageName));
}
@@ -2193,7 +2181,7 @@ public StarlarkSemantics getStarlarkSemantics() {
}
@Override
- public ImmutableMap getStarlarkDefinedBuiltins() throws InterruptedException {
+ public ImmutableMap getStarlarkDefinedBuiltins() {
throw new UnsupportedOperationException();
}
@@ -2427,7 +2415,7 @@ protected static ImmutableList flagValue(String flagName, Iterable clientEnv = new TreeMap<>();
+ private final TreeMap clientEnv = new TreeMap<>();
private ArtifactExpander artifactExpander = null;
private Executor executor = new DummyExecutor(fileSystem, getExecRoot());
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/CompileOnlyTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/CompileOnlyTestCase.java
index a3c196d8bfdfd1..84f760cf02cee0 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/CompileOnlyTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/CompileOnlyTestCase.java
@@ -22,7 +22,7 @@
*/
public abstract class CompileOnlyTestCase extends BuildViewTestCase {
- protected Artifact getArtifactByExecPathSuffix(ConfiguredTarget target, String path) {
+ protected static Artifact getArtifactByExecPathSuffix(ConfiguredTarget target, String path) {
for (Artifact artifact : getOutputGroup(target, OutputGroupInfo.FILES_TO_COMPILE).toList()) {
if (artifact.getExecPathString().endsWith(path)) {
return artifact;
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
index 2fe0e5d762012a..d81d1fe3d57056 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
@@ -210,10 +210,6 @@ Artifact getResource(String pathString) {
return getArtifact(RESOURCE_ROOT, pathString);
}
- Artifact getOutput(String pathString) {
- return getArtifact("outputs", pathString);
- }
-
private Artifact getArtifact(String subdir, String pathString) {
Path path = fileSystem.getPath("/" + subdir + "/" + pathString);
return new Artifact.SourceArtifact(
@@ -244,7 +240,6 @@ public RuleContext getRuleContextForActionTesting(ConfiguredTarget dummyTarget)
.setLabel(dummyTarget.getLabel())
.setConfiguration(targetConfig)
.build(),
- /*isSystemEnv=*/ false,
targetConfig.extendedSanityChecks(),
targetConfig.allowAnalysisFailures(),
eventHandler,
@@ -262,7 +257,7 @@ public RuleContext getRuleContextForActionTesting(ConfiguredTarget dummyTarget)
/**
* Assets that the action used to generate the given outputs has the expected inputs and outputs.
*/
- void assertActionArtifacts(
+ static void assertActionArtifacts(
RuleContext ruleContext, ImmutableList inputs, ImmutableList outputs) {
// Actions must have at least one output
assertThat(outputs).isNotEmpty();
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java
index 173b3ea20faada..194998bdb6eeab 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java
@@ -1479,10 +1479,7 @@ private void doTestCcLinkingContext(
assertThat(userLinkFlags.getImmutableList())
.containsExactly("-la", "-lc2", "-DEP2_LINKOPT", "-lc1", "-lc2", "-DEP1_LINKOPT");
Depset additionalInputs = info.getValue("additional_inputs", Depset.class);
- assertThat(
- additionalInputs.toList(Artifact.class).stream()
- .map(x -> x.getFilename())
- .collect(ImmutableList.toImmutableList()))
+ assertThat(additionalInputs.toList(Artifact.class).stream().map(Artifact::getFilename))
.containsExactly("b.lds", "d.lds");
Collection librariesToLink =
info.getValue("libraries_to_link", Depset.class).toList(LibraryToLink.class);
@@ -4661,11 +4658,11 @@ public void testCcToolchainInfoFromStarlarkNoLegacyFeatures() throws Exception {
(CcToolchainConfigInfo) target.get(CcToolchainConfigInfo.PROVIDER.getKey());
ImmutableSet featureNames =
ccToolchainConfigInfo.getFeatures().stream()
- .map(feature -> feature.getName())
+ .map(Feature::getName)
.collect(ImmutableSet.toImmutableSet());
ImmutableSet actionConfigNames =
ccToolchainConfigInfo.getActionConfigs().stream()
- .map(actionConfig -> actionConfig.getActionName())
+ .map(ActionConfig::getActionName)
.collect(ImmutableSet.toImmutableSet());
assertThat(featureNames).containsExactly("no_legacy_features", "custom_feature");
assertThat(actionConfigNames).containsExactly("custom_action");
@@ -4730,11 +4727,11 @@ public void testCcToolchainInfoFromStarlarkWithLegacyFeatures() throws Exception
(CcToolchainConfigInfo) target.get(CcToolchainConfigInfo.PROVIDER.getKey());
ImmutableList featureNames =
ccToolchainConfigInfo.getFeatures().stream()
- .map(feature -> feature.getName())
+ .map(Feature::getName)
.collect(ImmutableList.toImmutableList());
ImmutableSet actionConfigNames =
ccToolchainConfigInfo.getActionConfigs().stream()
- .map(actionConfig -> actionConfig.getActionName())
+ .map(ActionConfig::getActionName)
.collect(ImmutableSet.toImmutableSet());
// fdo_optimize should not be re-added to the list of features by legacy behavior
assertThat(featureNames).containsNoDuplicates();
@@ -4882,7 +4879,7 @@ public void testCcToolchainInfoToProto() throws Exception {
assertThat(toolchain.getCcTargetOs()).isEqualTo("os");
assertThat(
toolchain.getFeatureList().stream()
- .map(feature -> feature.getName())
+ .map(CToolchain.Feature::getName)
.collect(ImmutableList.toImmutableList()))
.containsAtLeast("featureone", "sysroot")
.inOrder();
@@ -4925,7 +4922,7 @@ public void testCcToolchainInfoToProto() throws Exception {
assertThat(
toolchain.getActionConfigList().stream()
- .map(actionConfig -> actionConfig.getActionName())
+ .map(CToolchain.ActionConfig::getActionName)
.collect(ImmutableList.toImmutableList()))
.containsAtLeast("action_one", "action_two")
.inOrder();
@@ -5318,7 +5315,7 @@ public void testCreateStaticLibraries() throws Exception {
ConfiguredTarget target = getConfiguredTarget("//foo:starlark_lib");
assertThat(
getFilesToBuild(target).toList().stream()
- .map(x -> x.getFilename())
+ .map(Artifact::getFilename)
.collect(ImmutableList.toImmutableList()))
.contains("libstarlark_lib.a");
}
@@ -5330,12 +5327,12 @@ public void testDoNotCreateStaticLibraries() throws Exception {
ConfiguredTarget target = getConfiguredTarget("//foo:starlark_lib");
assertThat(
getFilesToBuild(target).toList().stream()
- .map(x -> x.getFilename())
+ .map(Artifact::getFilename)
.collect(ImmutableList.toImmutableList()))
.doesNotContain("libstarlark_lib.a");
}
- private List getFilenamesToBuild(ConfiguredTarget target) {
+ private static ImmutableList getFilenamesToBuild(ConfiguredTarget target) {
return getFilesToBuild(target).toList().stream()
.map(Artifact::getFilename)
.collect(ImmutableList.toImmutableList());
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
index fef712a01e7f30..7739ef053744fa 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/BUILD
@@ -8,7 +8,7 @@ package(
filegroup(
name = "srcs",
testonly = 0,
- srcs = glob(["**"]) + ["//src/test/java/com/google/devtools/build/lib/skyframe/trimming:srcs"],
+ srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"],
)
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtilTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtilTest.java
index 1c588ac17573b4..085ba2ef206aab 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/PlatformLookupUtilTest.java
@@ -158,7 +158,7 @@ public static GetPlatformInfoKey create(ImmutableList