Skip to content

Commit 108c178

Browse files
Googlercopybara-github
authored andcommitted
Roll forward to allow select() specialization resolution to work with constraint_values.
PiperOrigin-RevId: 444550390
1 parent ff6ac53 commit 108c178

5 files changed

Lines changed: 277 additions & 16 deletions

File tree

src/main/java/com/google/devtools/build/docgen/templates/be/functions.vm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,10 @@ sh_binary(
616616
</li>
617617
<li>If multiple conditions match and one is a specialization of the others,
618618
the specialization takes precedence. Condition B is considered a
619-
specialization of condition A if B has all the same flags as A plus some
620-
additional flags. However, the number of constraint values that A and B have
621-
are not considered in this comparison -- one condition cannot match a
622-
platform <i>more than</i> another condition does.
619+
specialization of condition A if B has all the same flags and constraint
620+
values as A plus some additional flags or constraint values. This also
621+
means that specialization resolution is not designed to create an ordering as
622+
demonstrated in Example 2 below.
623623
</li>
624624
<li>If multiple conditions match and one is not a specialization of all the
625625
others, Bazel fails with an error.

src/main/java/com/google/devtools/build/lib/analysis/config/ConfigMatchingProvider.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ public static ConfigMatchingProvider create(
5050
ImmutableMultimap<String, String> settingsMap,
5151
ImmutableMap<Label, String> flagSettingsMap,
5252
RequiredConfigFragmentsProvider requiredFragmentOptions,
53+
ImmutableSet<Label> constraintValueSettings,
5354
boolean matches) {
5455
return new AutoValue_ConfigMatchingProvider(
55-
label, settingsMap, flagSettingsMap, requiredFragmentOptions, matches);
56+
label,
57+
settingsMap,
58+
flagSettingsMap,
59+
requiredFragmentOptions,
60+
constraintValueSettings,
61+
matches);
5662
}
5763

5864
/** The target's label. */
@@ -64,6 +70,8 @@ public static ConfigMatchingProvider create(
6470

6571
public abstract RequiredConfigFragmentsProvider requiredFragmentOptions();
6672

73+
abstract ImmutableSet<Label> constraintValuesSetting();
74+
6775
/**
6876
* Whether or not the configuration criteria defined by this target match its actual
6977
* configuration.
@@ -81,11 +89,18 @@ public boolean refines(ConfigMatchingProvider other) {
8189
ImmutableSet<Map.Entry<Label, String>> flagSettings = flagSettingsMap().entrySet();
8290
ImmutableSet<Map.Entry<Label, String>> otherFlagSettings = other.flagSettingsMap().entrySet();
8391

84-
if (!settings.containsAll(otherSettings) || !flagSettings.containsAll(otherFlagSettings)) {
92+
ImmutableSet<Label> constraintValueSettings = constraintValuesSetting();
93+
ImmutableSet<Label> otherConstraintValueSettings = other.constraintValuesSetting();
94+
95+
if (!settings.containsAll(otherSettings)
96+
|| !flagSettings.containsAll(otherFlagSettings)
97+
|| !constraintValueSettings.containsAll(otherConstraintValueSettings)) {
8598
return false; // Not a superset.
8699
}
87100

88-
return settings.size() > otherSettings.size() || flagSettings.size() > otherFlagSettings.size();
101+
return settings.size() > otherSettings.size()
102+
|| flagSettings.size() > otherFlagSettings.size()
103+
|| constraintValueSettings.size() > otherConstraintValueSettings.size();
89104
}
90105

91106
/** Format this provider as its label. */

src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.common.collect.ImmutableMap;
1818
import com.google.common.collect.ImmutableMultimap;
19+
import com.google.common.collect.ImmutableSet;
1920
import com.google.devtools.build.lib.analysis.RequiredConfigFragmentsProvider;
2021
import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
2122
import com.google.devtools.build.lib.cmdline.Label;
@@ -82,6 +83,7 @@ public ConfigMatchingProvider configMatchingProvider(PlatformInfo platformInfo)
8283
// the owning target already depends on PlatformConfiguration. And we can't reference
8384
// PlatformConfiguration.class here without a build dependency cycle.
8485
RequiredConfigFragmentsProvider.EMPTY,
86+
ImmutableSet.of(),
8587
platformInfo.constraints().hasConstraintValue(this));
8688
}
8789

src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.common.collect.ImmutableListMultimap;
2424
import com.google.common.collect.ImmutableMap;
2525
import com.google.common.collect.ImmutableMultimap;
26+
import com.google.common.collect.ImmutableSet;
2627
import com.google.common.collect.Iterables;
2728
import com.google.common.collect.ListMultimap;
2829
import com.google.common.collect.Lists;
@@ -132,6 +133,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
132133
ruleContext.shouldIncludeRequiredConfigFragmentsProvider()
133134
? ruleContext.getRequiredConfigFragments()
134135
: RequiredConfigFragmentsProvider.EMPTY,
136+
ImmutableSet.copyOf(constraintValueSettings),
135137
nativeFlagsMatch && userDefinedFlags.matches() && constraintValuesMatch);
136138

137139
return new RuleConfiguredTargetBuilder(ruleContext)

0 commit comments

Comments
 (0)