Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1.0] Preserve order of exec groups, toolchain types and exec constraints #25182

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
import com.google.errorprone.annotations.FormatMethod;
import com.google.errorprone.annotations.Keep;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -2040,7 +2040,7 @@ public StarlarkSubruleApi subrule(

private static ImmutableSet<ToolchainTypeRequirement> parseToolchainTypes(
Sequence<?> rawToolchains, LabelConverter labelConverter) throws EvalException {
Map<Label, ToolchainTypeRequirement> toolchainTypes = new HashMap<>();
Map<Label, ToolchainTypeRequirement> toolchainTypes = new LinkedHashMap<>();

for (Object rawToolchain : rawToolchains) {
ToolchainTypeRequirement toolchainType = parseToolchainType(rawToolchain, labelConverter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -749,11 +747,11 @@ public String toString() {
private boolean supportsConstraintChecking = true;

private final Map<String, Attribute> attributes = new LinkedHashMap<>();
private final Set<ToolchainTypeRequirement> toolchainTypes = new HashSet<>();
private final Set<ToolchainTypeRequirement> toolchainTypes = new LinkedHashSet<>();
private ToolchainResolutionMode toolchainResolutionMode = ToolchainResolutionMode.ENABLED;
private final Set<Label> executionPlatformConstraints = new HashSet<>();
private final Set<Label> executionPlatformConstraints = new LinkedHashSet<>();
private OutputFile.Kind outputFileKind = OutputFile.Kind.FILE;
private final Map<String, ExecGroup> execGroups = new HashMap<>();
private final Map<String, ExecGroup> execGroups = new LinkedHashMap<>();
private AutoExecGroupsMode autoExecGroupsMode = AutoExecGroupsMode.DYNAMIC;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,89 @@ public void testRuleAddExecGroup() throws Exception {
assertThat(execGroup).hasExecCompatibleWith("//constraint:cv2");
}

@Test
public void testRuleOrderedRequirements() throws Exception {
registerDummyStarlarkFunction();
evalAndExport(
ev,
"plum = rule(",
" implementation = impl,",
" exec_compatible_with = [",
" '//constraint:cv5',",
" '//constraint:cv4',",
" '//constraint:cv3',",
" '//constraint:cv2',",
" '//constraint:cv1',",
" ],",
" toolchains = [",
" '//test:my_toolchain_type5',",
" '//test:my_toolchain_type4',",
" '//test:my_toolchain_type3',",
" '//test:my_toolchain_type2',",
" '//test:my_toolchain_type1',",
" ],",
" exec_groups = {",
" 'group5': exec_group(",
" toolchains = [",
" '//test:my_toolchain_type5',",
" '//test:my_toolchain_type4',",
" '//test:my_toolchain_type3',",
" '//test:my_toolchain_type2',",
" '//test:my_toolchain_type1',",
" ],",
" ),",
" 'group4': exec_group(",
" exec_compatible_with = [",
" '//constraint:cv5',",
" '//constraint:cv4',",
" '//constraint:cv3',",
" '//constraint:cv2',",
" '//constraint:cv1',",
" ],",
" ),",
" 'group3': exec_group(),",
" 'group2': exec_group(),",
" 'group1': exec_group(),",
" },",
")");
RuleClass plum = ((StarlarkRuleFunction) ev.lookup("plum")).getRuleClass();
assertThat(plum.getToolchainTypes().stream().map(ToolchainTypeRequirement::toolchainType))
.containsExactly(
Label.parseCanonicalUnchecked("//test:my_toolchain_type5"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type4"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type3"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type2"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type1"))
.inOrder();
assertThat(plum.getExecutionPlatformConstraints())
.containsExactly(
Label.parseCanonicalUnchecked("//constraint:cv5"),
Label.parseCanonicalUnchecked("//constraint:cv4"),
Label.parseCanonicalUnchecked("//constraint:cv3"),
Label.parseCanonicalUnchecked("//constraint:cv2"),
Label.parseCanonicalUnchecked("//constraint:cv1"))
.inOrder();
assertThat(plum.getExecGroups().keySet())
.containsExactly("group5", "group4", "group3", "group2", "group1")
.inOrder();
assertThat(plum.getExecGroups().get("group5").toolchainTypesMap().keySet())
.containsExactly(
Label.parseCanonicalUnchecked("//test:my_toolchain_type5"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type4"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type3"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type2"),
Label.parseCanonicalUnchecked("//test:my_toolchain_type1"))
.inOrder();
assertThat(plum.getExecGroups().get("group4").execCompatibleWith())
.containsExactly(
Label.parseCanonicalUnchecked("//constraint:cv5"),
Label.parseCanonicalUnchecked("//constraint:cv4"),
Label.parseCanonicalUnchecked("//constraint:cv3"),
Label.parseCanonicalUnchecked("//constraint:cv2"),
Label.parseCanonicalUnchecked("//constraint:cv1"))
.inOrder();
}

@Test
public void testRuleFunctionReturnsNone() throws Exception {
scratch.file(
Expand Down
Loading