From ff0088df8566617017feff68f90ef6c57db88766 Mon Sep 17 00:00:00 2001 From: John Cater Date: Thu, 3 Mar 2022 16:07:03 -0500 Subject: [PATCH] Add ToolchainTypeRequirement to ToolchainTestCase. Part of Optional Toolchains (#14726). --- .../ResolvedToolchainContextTest.java | 39 +++++++++++-------- .../devtools/build/lib/rules/platform/BUILD | 1 + .../lib/rules/platform/ToolchainTestCase.java | 7 +++- .../RegisteredToolchainsFunctionTest.java | 6 +-- ...SingleToolchainResolutionFunctionTest.java | 12 +++--- .../ToolchainResolutionFunctionTest.java | 20 +++++----- .../skyframe/ToolchainTypeLookupUtilTest.java | 6 +-- 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java b/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java index 77626e595097ac..c238600a0b701d 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/ResolvedToolchainContextTest.java @@ -50,7 +50,7 @@ public void load() throws Exception { ToolchainContextKey toolchainContextKey = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); // Create a static UnloadedToolchainContext. @@ -58,13 +58,13 @@ public void load() throws Exception { UnloadedToolchainContextImpl.builder(toolchainContextKey) .setExecutionPlatform(linuxPlatform) .setTargetPlatform(linuxPlatform) - .setRequiredToolchainTypes(ImmutableSet.of(testToolchainType)) + .setToolchainTypes(ImmutableSet.of(testToolchainType)) .setRequestedLabelToToolchainType( - ImmutableMap.of(testToolchainTypeLabel, testToolchainType)) + ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo)) .setToolchainTypeToResolved( ImmutableSetMultimap.builder() .put( - testToolchainType, + testToolchainTypeInfo, Label.parseAbsoluteUnchecked("//extra:extra_toolchain_linux_impl")) .build()) .build(); @@ -102,7 +102,7 @@ public void load_aliasedToolchain() throws Exception { ToolchainContextKey toolchainContextKey = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); // Create a static UnloadedToolchainContext. @@ -110,12 +110,12 @@ public void load_aliasedToolchain() throws Exception { UnloadedToolchainContextImpl.builder(toolchainContextKey) .setExecutionPlatform(linuxPlatform) .setTargetPlatform(linuxPlatform) - .setRequiredToolchainTypes(ImmutableSet.of(testToolchainType)) + .setToolchainTypes(ImmutableSet.of(testToolchainType)) .setRequestedLabelToToolchainType( - ImmutableMap.of(testToolchainTypeLabel, testToolchainType)) + ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo)) .setToolchainTypeToResolved( ImmutableSetMultimap.builder() - .put(testToolchainType, Label.parseAbsoluteUnchecked("//alias:toolchain")) + .put(testToolchainTypeInfo, Label.parseAbsoluteUnchecked("//alias:toolchain")) .build()) .build(); @@ -144,7 +144,7 @@ public void load_notToolchain() throws Exception { ToolchainContextKey toolchainContextKey = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); // Create a static UnloadedToolchainContext. @@ -152,12 +152,14 @@ public void load_notToolchain() throws Exception { UnloadedToolchainContextImpl.builder(toolchainContextKey) .setExecutionPlatform(linuxPlatform) .setTargetPlatform(linuxPlatform) - .setRequiredToolchainTypes(ImmutableSet.of(testToolchainType)) + .setToolchainTypes(ImmutableSet.of(testToolchainType)) .setRequestedLabelToToolchainType( - ImmutableMap.of(testToolchainTypeLabel, testToolchainType)) + ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo)) .setToolchainTypeToResolved( ImmutableSetMultimap.builder() - .put(testToolchainType, Label.parseAbsoluteUnchecked("//foo:not_a_toolchain")) + .put( + testToolchainTypeInfo, + Label.parseAbsoluteUnchecked("//foo:not_a_toolchain")) .build()) .build(); @@ -179,7 +181,10 @@ public void load_withTemplateVariables() throws Exception { // Add new toolchain rule that provides template variables. Label variableToolchainTypeLabel = Label.parseAbsoluteUnchecked("//variable:variable_toolchain_type"); - ToolchainTypeInfo variableToolchainType = ToolchainTypeInfo.create(variableToolchainTypeLabel); + ToolchainTypeRequirement variableToolchainType = + ToolchainTypeRequirement.create(variableToolchainTypeLabel); + ToolchainTypeInfo variableToolchainTypeInfo = + ToolchainTypeInfo.create(variableToolchainTypeLabel); scratch.file( "variable/variable_toolchain_def.bzl", "def _impl(ctx):", @@ -203,7 +208,7 @@ public void load_withTemplateVariables() throws Exception { ToolchainContextKey toolchainContextKey = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); // Create a static UnloadedToolchainContext. @@ -211,13 +216,13 @@ public void load_withTemplateVariables() throws Exception { UnloadedToolchainContextImpl.builder(toolchainContextKey) .setExecutionPlatform(linuxPlatform) .setTargetPlatform(linuxPlatform) - .setRequiredToolchainTypes(ImmutableSet.of(variableToolchainType)) + .setToolchainTypes(ImmutableSet.of(variableToolchainType)) .setRequestedLabelToToolchainType( - ImmutableMap.of(variableToolchainTypeLabel, variableToolchainType)) + ImmutableMap.of(variableToolchainTypeLabel, variableToolchainTypeInfo)) .setToolchainTypeToResolved( ImmutableSetMultimap.builder() .put( - variableToolchainType, + variableToolchainTypeInfo, Label.parseAbsoluteUnchecked("//variable:variable_toolchain_impl")) .build()) .build(); diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD b/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD index 8f8cffa83e0069..e084c8dc1c4037 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/BUILD @@ -40,6 +40,7 @@ java_library( name = "testutil", srcs = TESTUTIL_SRCS, deps = [ + "//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement", "//src/main/java/com/google/devtools/build/lib/analysis/platform", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/skyframe:skyframe_cluster", diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java index 2eaaf76f25589c..30cd5835995bbc 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/ToolchainTestCase.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.truth.IterableSubject; +import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement; import com.google.devtools.build.lib.analysis.platform.ConstraintSettingInfo; import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo; import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo; @@ -50,7 +51,8 @@ public abstract class ToolchainTestCase extends BuildViewTestCase { public ConstraintValueInfo defaultedConstraint; public Label testToolchainTypeLabel; - public ToolchainTypeInfo testToolchainType; + public ToolchainTypeRequirement testToolchainType; + public ToolchainTypeInfo testToolchainTypeInfo; protected static IterableSubject assertToolchainLabels( RegisteredToolchainsValue registeredToolchainsValue) { @@ -195,7 +197,8 @@ public void createToolchains() throws Exception { "bar"); testToolchainTypeLabel = Label.parseAbsoluteUnchecked("//toolchain:test_toolchain"); - testToolchainType = ToolchainTypeInfo.create(testToolchainTypeLabel); + testToolchainType = ToolchainTypeRequirement.create(testToolchainTypeLabel); + testToolchainTypeInfo = ToolchainTypeInfo.create(testToolchainTypeLabel); } protected EvaluationResult requestToolchainsFromSkyframe( diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java index 6734597d65fac5..3ca6970043f4a2 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java @@ -87,7 +87,7 @@ public void testRegisteredToolchains() throws Exception { // Check that the number of toolchains created for this test is correct. assertThat( value.registeredToolchains().stream() - .filter(toolchain -> toolchain.toolchainType().equals(testToolchainType)) + .filter(toolchain -> toolchain.toolchainType().equals(testToolchainTypeInfo)) .collect(Collectors.toList())) .hasSize(2); @@ -95,7 +95,7 @@ public void testRegisteredToolchains() throws Exception { value.registeredToolchains().stream() .anyMatch( toolchain -> - toolchain.toolchainType().equals(testToolchainType) + toolchain.toolchainType().equals(testToolchainTypeInfo) && toolchain.execConstraints().get(setting).equals(linuxConstraint) && toolchain.targetConstraints().get(setting).equals(macConstraint) && toolchain @@ -108,7 +108,7 @@ public void testRegisteredToolchains() throws Exception { value.registeredToolchains().stream() .anyMatch( toolchain -> - toolchain.toolchainType().equals(testToolchainType) + toolchain.toolchainType().equals(testToolchainTypeInfo) && toolchain.execConstraints().get(setting).equals(macConstraint) && toolchain.targetConstraints().get(setting).equals(linuxConstraint) && toolchain diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java index 511d6e5874ec53..78cb21ef11de1d 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SingleToolchainResolutionFunctionTest.java @@ -143,33 +143,33 @@ public void testToolchainResolutionValue_equalsAndHashCode() { new EqualsTester() .addEqualityGroup( SingleToolchainResolutionValue.create( - testToolchainType, + testToolchainTypeInfo, ImmutableMap.of( linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1"))), SingleToolchainResolutionValue.create( - testToolchainType, + testToolchainTypeInfo, ImmutableMap.of( linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1")))) // Different execution platform, same label. .addEqualityGroup( SingleToolchainResolutionValue.create( - testToolchainType, + testToolchainTypeInfo, ImmutableMap.of(macCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1")))) // Same execution platform, different label. .addEqualityGroup( SingleToolchainResolutionValue.create( - testToolchainType, + testToolchainTypeInfo, ImmutableMap.of( linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_2")))) // Different execution platform, different label. .addEqualityGroup( SingleToolchainResolutionValue.create( - testToolchainType, + testToolchainTypeInfo, ImmutableMap.of(macCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_2")))) // Multiple execution platforms. .addEqualityGroup( SingleToolchainResolutionValue.create( - testToolchainType, + testToolchainTypeInfo, ImmutableMap.builder() .put(linuxCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1")) .put(macCtkey, Label.parseAbsoluteUnchecked("//test:toolchain_impl_1")) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java index 1d4da43e2e2095..7cc35cd6ba7942 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainResolutionFunctionTest.java @@ -71,7 +71,7 @@ public void resolve() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); EvaluationResult result = invokeToolchainResolution(key); @@ -187,7 +187,7 @@ public void resolve_unavailableToolchainType_single() throws Exception { ToolchainContextKey.key() .configurationKey(targetConfigKey) .toolchainTypes( - ToolchainTypeRequirement.create(testToolchainTypeLabel), + testToolchainType, ToolchainTypeRequirement.create( Label.parseAbsoluteUnchecked("//fake/toolchain:type_1"))) .build(); @@ -210,7 +210,7 @@ public void resolve_unavailableToolchainType_multiple() throws Exception { ToolchainContextKey.key() .configurationKey(targetConfigKey) .toolchainTypes( - ToolchainTypeRequirement.create(testToolchainTypeLabel), + testToolchainType, ToolchainTypeRequirement.create( Label.parseAbsoluteUnchecked("//fake/toolchain:type_1")), ToolchainTypeRequirement.create( @@ -233,7 +233,7 @@ public void resolve_invalidTargetPlatform_badTarget() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); EvaluationResult result = invokeToolchainResolution(key); @@ -259,7 +259,7 @@ public void resolve_invalidTargetPlatform_badPackage() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); EvaluationResult result = invokeToolchainResolution(key); @@ -283,7 +283,7 @@ public void resolve_invalidHostPlatform() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); EvaluationResult result = invokeToolchainResolution(key); @@ -308,7 +308,7 @@ public void resolve_invalidExecutionPlatform() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .build(); EvaluationResult result = invokeToolchainResolution(key); @@ -349,7 +349,7 @@ public void resolve_execConstraints() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .execConstraintLabels(Label.parseAbsoluteUnchecked("//constraints:linux")) .build(); @@ -370,7 +370,7 @@ public void resolve_execConstraints_invalid() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .execConstraintLabels(Label.parseAbsoluteUnchecked("//platforms:linux")) .build(); @@ -461,7 +461,7 @@ public void resolve_forceExecutionPlatform() throws Exception { ToolchainContextKey key = ToolchainContextKey.key() .configurationKey(targetConfigKey) - .toolchainTypes(ToolchainTypeRequirement.create(testToolchainTypeLabel)) + .toolchainTypes(testToolchainType) .forceExecutionPlatform(Label.parseAbsoluteUnchecked("//platforms:linux")) .build(); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java index 6dfb6d63406d48..27b846dad1f2c4 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ToolchainTypeLookupUtilTest.java @@ -85,7 +85,7 @@ public void testToolchainTypeLookup() throws Exception { Map toolchainTypes = result.get(key).toolchainTypes(); assertThat(toolchainTypes) - .containsExactlyEntriesIn(ImmutableMap.of(testToolchainTypeLabel, testToolchainType)); + .containsExactlyEntriesIn(ImmutableMap.of(testToolchainTypeLabel, testToolchainTypeInfo)); } @Test @@ -111,9 +111,9 @@ public void testToolchainTypeLookup_toolchainAlias() throws Exception { .containsExactlyEntriesIn( ImmutableMap.of( testToolchainTypeLabel, - testToolchainType, + testToolchainTypeInfo, aliasToolchainTypeLabel, - testToolchainType)); + testToolchainTypeInfo)); } @Test