Skip to content

Commit

Permalink
Added new RuleClass flag to turn off platform support, to stop depend…
Browse files Browse the repository at this point in the history
…ency cycles when loading platforms.

Part of bazelbuild#4128.

Change-Id: Ie55a91aaaec15d8eb537f59131fc2e69a8f9c251
PiperOrigin-RevId: 176509311
  • Loading branch information
katre authored and Copybara-Service committed Nov 21, 2017
1 parent 2ed3261 commit 856b4dd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@ public final ConfiguredTarget createConfiguredTarget(
@Nullable ToolchainContext toolchainContext)
throws InterruptedException {
if (target instanceof Rule) {
Preconditions.checkArgument(
toolchainContext != null,
"ToolchainContext should never be null when creating a ConfiguredTarget for a Rule");
try {
CurrentRuleTracker.beginConfiguredTarget(((Rule) target).getRuleClassObject());
return createRule(
Expand Down Expand Up @@ -302,11 +299,13 @@ private ConfiguredTarget createRule(
BuildConfiguration hostConfiguration,
OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap,
ImmutableMap<Label, ConfigMatchingProvider> configConditions,
ToolchainContext toolchainContext)
@Nullable ToolchainContext toolchainContext)
throws InterruptedException {

// Load the requested toolchains into the ToolchainContext.
toolchainContext.resolveToolchains(prerequisiteMap);
if (toolchainContext != null) {
toolchainContext.resolveToolchains(prerequisiteMap);
}

// Visibility computation and checking is done for every rule.
RuleContext ruleContext =
Expand Down Expand Up @@ -409,13 +408,15 @@ public ConfiguredAspect createAspect(
Aspect aspect,
OrderedSetMultimap<Attribute, ConfiguredTarget> prerequisiteMap,
ImmutableMap<Label, ConfigMatchingProvider> configConditions,
ToolchainContext toolchainContext,
@Nullable ToolchainContext toolchainContext,
BuildConfiguration aspectConfiguration,
BuildConfiguration hostConfiguration)
throws InterruptedException {

// Load the requested toolchains into the ToolchainContext.
toolchainContext.resolveToolchains(prerequisiteMap);
if (toolchainContext != null) {
toolchainContext.resolveToolchains(prerequisiteMap);
}

RuleContext.Builder builder = new RuleContext.Builder(
env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
attr("path", STRING)
.undocumented(
"only used to expose FilegroupPathProvider, which is not currently used"))
.supportsPlatforms(false)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public Transition buildTransitionFor(Rule rule) {

private final Map<String, Attribute> attributes = new LinkedHashMap<>();
private final Set<Label> requiredToolchains = new HashSet<>();
private boolean supportsPlatforms = true;

/**
* Constructs a new {@code RuleClassBuilder} using all attributes from all
Expand Down Expand Up @@ -517,6 +518,7 @@ public Builder(String name, RuleClassType type, boolean skylark, RuleClass... pa
supportsConstraintChecking = parent.supportsConstraintChecking;

addRequiredToolchains(parent.getRequiredToolchains());
supportsPlatforms = parent.supportsPlatforms;

for (Attribute attribute : parent.getAttributes()) {
String attrName = attribute.getName();
Expand Down Expand Up @@ -599,6 +601,7 @@ public RuleClass build(String name, String key) {
configurationFragmentPolicy.build(),
supportsConstraintChecking,
requiredToolchains,
supportsPlatforms,
attributes.values().toArray(new Attribute[0]));
}

Expand Down Expand Up @@ -1010,6 +1013,11 @@ public Builder addRequiredToolchains(Label... toolchainLabels) {
return this;
}

public Builder supportsPlatforms(boolean flag) {
this.supportsPlatforms = flag;
return this;
}

/**
* Returns an Attribute.Builder object which contains a replica of the
* same attribute in the parent rule if exists.
Expand Down Expand Up @@ -1132,6 +1140,7 @@ public Attribute.Builder<?> copy(String name) {
private final boolean supportsConstraintChecking;

private final ImmutableSet<Label> requiredToolchains;
private final boolean supportsPlatforms;

/**
* Constructs an instance of RuleClass whose name is 'name', attributes are 'attributes'. The
Expand Down Expand Up @@ -1181,6 +1190,7 @@ public Attribute.Builder<?> copy(String name) {
ConfigurationFragmentPolicy configurationFragmentPolicy,
boolean supportsConstraintChecking,
Set<Label> requiredToolchains,
boolean supportsPlatforms,
Attribute... attributes) {
this.name = name;
this.key = key;
Expand Down Expand Up @@ -1211,6 +1221,7 @@ public Attribute.Builder<?> copy(String name) {
this.configurationFragmentPolicy = configurationFragmentPolicy;
this.supportsConstraintChecking = supportsConstraintChecking;
this.requiredToolchains = ImmutableSet.copyOf(requiredToolchains);
this.supportsPlatforms = supportsPlatforms;

// Create the index and collect non-configurable attributes.
int index = 0;
Expand Down Expand Up @@ -2031,6 +2042,10 @@ public ImmutableSet<Label> getRequiredToolchains() {
return requiredToolchains;
}

public boolean supportsPlatforms() {
return supportsPlatforms;
}

public static boolean isThirdPartyPackage(PackageIdentifier packageIdentifier) {
if (!packageIdentifier.getRepository().isMain()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.value(ImmutableList.of("manual"))
.nonconfigurable("low-level attribute, used in platform configuration"))
.exemptFromConstraintChecking("this rule helps *define* a constraint")
.supportsPlatforms(false)
.removeAttribute("deps")
.removeAttribute("data")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,15 @@ public SkyValue compute(SkyKey key, Environment env) throws ConfiguredTargetFunc
// Determine what toolchains are needed by this target.
if (target instanceof Rule) {
Rule rule = ((Rule) target);
ImmutableSet<Label> requiredToolchains = rule.getRuleClassObject().getRequiredToolchains();
toolchainContext =
ToolchainUtil.createToolchainContext(
env, rule.toString(), requiredToolchains, configuration);
if (env.valuesMissing()) {
return null;
if (rule.getRuleClassObject().supportsPlatforms()) {
ImmutableSet<Label> requiredToolchains =
rule.getRuleClassObject().getRequiredToolchains();
toolchainContext =
ToolchainUtil.createToolchainContext(
env, rule.toString(), requiredToolchains, configuration);
if (env.valuesMissing()) {
return null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ private static PlatformDescriptors loadPlatformDescriptors(
throws InterruptedException, ToolchainContextException {
PlatformConfiguration platformConfiguration =
configuration.getFragment(PlatformConfiguration.class);
if (platformConfiguration == null) {
return null;
}
Label executionPlatformLabel = platformConfiguration.getExecutionPlatform();
Label targetPlatformLabel = platformConfiguration.getTargetPlatforms().get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ private static RuleClass newRuleClass(
.build(),
supportsConstraintChecking,
/*requiredToolchains=*/ ImmutableSet.<Label>of(),
/*supportsPlatforms=*/ true,
attributes);
}

Expand Down

0 comments on commit 856b4dd

Please sign in to comment.