Skip to content

Commit

Permalink
Hoist up the useToolchainTransitionParameter to the caller.
Browse files Browse the repository at this point in the history
This will allow Aspects to use the toolchain transition.

Part of work on toolchain transition, #10523.

PiperOrigin-RevId: 316751670
  • Loading branch information
katre authored and Copybara-Service committed Jun 16, 2020
1 parent feffb17 commit 81db8a5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@
*/
public abstract class DependencyResolver {

/**
* Returns whether or not to use the new toolchain transition. Checks the global incompatible
* change flag and the rule's toolchain transition readiness attribute.
*/
// TODO(#10523): Remove this when the migration period for toolchain transitions has ended.
public static boolean shouldUseToolchainTransition(
@Nullable BuildConfiguration configuration, Target target) {
// Check whether the global incompatible change flag is set.
if (configuration != null) {
PlatformOptions platformOptions = configuration.getOptions().get(PlatformOptions.class);
if (platformOptions != null && platformOptions.overrideToolchainTransition) {
return true;
}
}

// Check the rule definition to see if it is ready.
if (target instanceof Rule && ((Rule) target).getRuleClassObject().useToolchainTransition()) {
return true;
}

// Default to false.
return false;
}

/**
* What we know about a dependency edge after factoring in the properties of the configured target
* that the edge originates from, but not the properties of target it points to.
Expand Down Expand Up @@ -148,16 +172,18 @@ public final OrderedSetMultimap<DependencyKind, DependencyKey> dependentNodeMap(
@Nullable Aspect aspect,
ImmutableMap<Label, ConfigMatchingProvider> configConditions,
@Nullable ToolchainCollection<ToolchainContext> toolchainContexts,
boolean useToolchainTransition,
@Nullable TransitionFactory<Rule> trimmingTransitionFactory)
throws EvalException, InterruptedException, InconsistentAspectOrderException {
NestedSetBuilder<Cause> rootCauses = NestedSetBuilder.stableOrder();
OrderedSetMultimap<DependencyKind, DependencyKey> outgoingEdges =
dependentNodeMap(
node,
hostConfig,
aspect != null ? ImmutableList.of(aspect) : ImmutableList.<Aspect>of(),
aspect != null ? ImmutableList.of(aspect) : ImmutableList.of(),
configConditions,
toolchainContexts,
useToolchainTransition,
rootCauses,
trimmingTransitionFactory);
if (!rootCauses.isEmpty()) {
Expand Down Expand Up @@ -203,6 +229,7 @@ public final OrderedSetMultimap<DependencyKind, DependencyKey> dependentNodeMap(
Iterable<Aspect> aspects,
ImmutableMap<Label, ConfigMatchingProvider> configConditions,
@Nullable ToolchainCollection<ToolchainContext> toolchainContexts,
boolean useToolchainTransition,
NestedSetBuilder<Cause> rootCauses,
@Nullable TransitionFactory<Rule> trimmingTransitionFactory)
throws EvalException, InterruptedException, InconsistentAspectOrderException {
Expand Down Expand Up @@ -239,9 +266,6 @@ public final OrderedSetMultimap<DependencyKind, DependencyKey> dependentNodeMap(
return OrderedSetMultimap.create();
}

// TODO(#10523): Remove this when the migration period for toolchain transitions has ended.
boolean useToolchainTransition =
shouldUseToolchainTransition(node.getConfiguration(), fromRule);
OrderedSetMultimap<DependencyKind, PartiallyResolvedDependency> partiallyResolvedDeps =
partiallyResolveDependencies(
outgoingLabels,
Expand All @@ -258,29 +282,6 @@ public final OrderedSetMultimap<DependencyKind, DependencyKey> dependentNodeMap(
return outgoingEdges;
}

/**
* Returns whether or not to use the new toolchain transition. Checks the global incompatible
* change flag and the rule's toolchain transition readiness attribute.
*/
private static boolean shouldUseToolchainTransition(
@Nullable BuildConfiguration configuration, @Nullable Rule fromRule) {
// Check whether the global incompatible change flag is set.
if (configuration != null) {
PlatformOptions platformOptions = configuration.getOptions().get(PlatformOptions.class);
if (platformOptions != null && platformOptions.overrideToolchainTransition) {
return true;
}
}

// Check the rule definition to see if it is ready.
if (fromRule != null && fromRule.getRuleClassObject().useToolchainTransition()) {
return true;
}

// Default to false.
return false;
}

/**
* Factor in the properties of the current rule into the dependency edge calculation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void processOutput(Iterable<ConfiguredTarget> partialResult) throws Inter
/*aspect=*/ null,
configConditions,
toolchainContexts,
DependencyResolver.shouldUseToolchainTransition(config, target),
trimmingTransitionFactory);
} catch (EvalException | InconsistentAspectOrderException e) {
throw new InterruptedException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
: ToolchainCollection.builder()
.addDefaultContext(unloadedToolchainContext)
.build(),
/* useToolchainTransition= */ false,
ruleClassProvider,
view.getHostConfiguration(originalTargetAndAspectConfiguration.getConfiguration()),
transitivePackagesForPackageRootResolution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.devtools.build.lib.analysis.Dependency;
import com.google.devtools.build.lib.analysis.DependencyKey;
import com.google.devtools.build.lib.analysis.DependencyKind;
import com.google.devtools.build.lib.analysis.DependencyResolver;
import com.google.devtools.build.lib.analysis.DuplicateException;
import com.google.devtools.build.lib.analysis.EmptyConfiguredTarget;
import com.google.devtools.build.lib.analysis.InconsistentAspectOrderException;
Expand Down Expand Up @@ -314,6 +315,7 @@ public SkyValue compute(SkyKey key, Environment env) throws ConfiguredTargetFunc
unloadedToolchainContexts == null
? null
: unloadedToolchainContexts.asToolchainContexts(),
DependencyResolver.shouldUseToolchainTransition(configuration, ctgValue.getTarget()),
ruleClassProvider,
view.getHostConfiguration(configuration),
transitivePackagesForPackageRootResolution,
Expand Down Expand Up @@ -615,6 +617,7 @@ static OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> computeDepend
Iterable<Aspect> aspects,
ImmutableMap<Label, ConfigMatchingProvider> configConditions,
@Nullable ToolchainCollection<ToolchainContext> toolchainContexts,
boolean useToolchainTransition,
RuleClassProvider ruleClassProvider,
BuildConfiguration hostConfiguration,
@Nullable NestedSetBuilder<Package> transitivePackagesForPackageRootResolution,
Expand All @@ -634,6 +637,7 @@ static OrderedSetMultimap<DependencyKind, ConfiguredTargetAndData> computeDepend
aspects,
configConditions,
toolchainContexts,
useToolchainTransition,
transitiveRootCauses,
((ConfiguredRuleClassProvider) ruleClassProvider).getTrimmingTransitionFactory());
} catch (EvalException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private OrderedSetMultimap<DependencyKind, DependencyKey> dependentNodeMap(
aspect != null ? Aspect.forNative(aspect) : null,
ImmutableMap.of(),
/*toolchainContext=*/ null,
/*useToolchainTransition=*/ false,
/*trimmingTransitionFactory=*/ null);

return prerequisiteMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,16 @@ protected Map<Label, Target> getTargets(
}

DependencyResolver dependencyResolver = new SilentDependencyResolver();
TargetAndConfiguration ctgNode =
new TargetAndConfiguration(
target, skyframeExecutor.getConfiguration(eventHandler, ct.getConfigurationKey()));
BuildConfiguration configuration =
skyframeExecutor.getConfiguration(eventHandler, ct.getConfigurationKey());
TargetAndConfiguration ctgNode = new TargetAndConfiguration(target, configuration);
return dependencyResolver.dependentNodeMap(
ctgNode,
configurations.getHostConfiguration(),
/*aspect=*/ null,
getConfigurableAttributeKeysForTesting(eventHandler, ctgNode),
toolchainContexts,
DependencyResolver.shouldUseToolchainTransition(configuration, target),
ruleClassProvider.getTrimmingTransitionFactory());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
ImmutableList.<Aspect>of(),
ImmutableMap.<Label, ConfigMatchingProvider>of(),
/*toolchainContext=*/ null,
/* useToolchainTransition= */ false,
stateProvider.lateBoundRuleClassProvider(),
stateProvider.lateBoundHostConfig(),
NestedSetBuilder.<Package>stableOrder(),
Expand Down

0 comments on commit 81db8a5

Please sign in to comment.