Re-add way to fetch experimental platform providers from Starlark.
Change-Id: I201ec9a849cbc07a88eb417cea581ab1c81e40f1
Closes #6094.
Change-Id: I5c3e11c04e1afa77242ae36729da47e6ccc1ddaa
PiperOrigin-RevId: 211840802
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java
index 839acac..28cc522 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfo.java
@@ -32,7 +32,7 @@
public static final String SKYLARK_NAME = "ConstraintValueInfo";
/** Skylark constructor and identifier for this provider. */
- public static final NativeProvider<ConstraintValueInfo> SKYLARK_CONSTRUCTOR =
+ public static final NativeProvider<ConstraintValueInfo> PROVIDER =
new NativeProvider<ConstraintValueInfo>(ConstraintValueInfo.class, SKYLARK_NAME) {};
private final ConstraintSettingInfo constraint;
@@ -40,9 +40,7 @@
@VisibleForSerialization
ConstraintValueInfo(ConstraintSettingInfo constraint, Label label, Location location) {
- super(
- SKYLARK_CONSTRUCTOR,
- location);
+ super(PROVIDER, location);
this.constraint = constraint;
this.label = label;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformInfo.java
index 2f73f5a..a3b78b7 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformInfo.java
@@ -47,7 +47,7 @@
public static final String SKYLARK_NAME = "PlatformInfo";
/** Skylark constructor and identifier for this provider. */
- public static final NativeProvider<PlatformInfo> SKYLARK_CONSTRUCTOR =
+ public static final NativeProvider<PlatformInfo> PROVIDER =
new NativeProvider<PlatformInfo>(PlatformInfo.class, SKYLARK_NAME) {};
private final Label label;
@@ -61,9 +61,7 @@
ImmutableMap<ConstraintSettingInfo, ConstraintValueInfo> constraints,
String remoteExecutionProperties,
Location location) {
- super(
- SKYLARK_CONSTRUCTOR,
- location);
+ super(PROVIDER, location);
this.label = label;
this.constraints = constraints;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformProviderUtils.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformProviderUtils.java
index 51582d3..e2c39cc 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformProviderUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/PlatformProviderUtils.java
@@ -22,7 +22,7 @@
/** Retrieves and casts the {@link PlatformInfo} provider from the given target. */
public static PlatformInfo platform(SkylarkProviderCollection target) {
- return target.get(PlatformInfo.SKYLARK_CONSTRUCTOR);
+ return target.get(PlatformInfo.PROVIDER);
}
/** Retrieves and casts {@link PlatformInfo} providers from the given targets. */
@@ -44,7 +44,7 @@
/** Retrieves and casts the {@link ConstraintValueInfo} provider from the given target. */
public static ConstraintValueInfo constraintValue(SkylarkProviderCollection target) {
- return target.get(ConstraintValueInfo.SKYLARK_CONSTRUCTOR);
+ return target.get(ConstraintValueInfo.PROVIDER);
}
/** Retrieves and casts {@link ConstraintValueInfo} providers from the given targets. */
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
index b3aff82..3193c47 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformCommon.java
@@ -15,6 +15,9 @@
package com.google.devtools.build.lib.rules.platform;
import com.google.devtools.build.lib.analysis.TemplateVariableInfo;
+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.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.packages.Provider;
import com.google.devtools.build.lib.skylarkbuildapi.platform.PlatformCommonApi;
@@ -23,6 +26,21 @@
public class PlatformCommon implements PlatformCommonApi {
@Override
+ public Provider getPlatformInfoConstructor() {
+ return PlatformInfo.PROVIDER;
+ }
+
+ @Override
+ public Provider getConstraintSettingInfoConstructor() {
+ return ConstraintSettingInfo.PROVIDER;
+ }
+
+ @Override
+ public Provider getConstraintValueInfoConstructor() {
+ return ConstraintValueInfo.PROVIDER;
+ }
+
+ @Override
public Provider getMakeVariableProvider() {
return TemplateVariableInfo.PROVIDER;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java
index e3e69ad..323d551 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/PlatformRule.java
@@ -46,7 +46,7 @@
.add(
attr(CONSTRAINT_VALUES_ATTR, BuildType.LABEL_LIST)
.allowedFileTypes(FileTypeSet.NO_FILE)
- .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.SKYLARK_CONSTRUCTOR.id())))
+ .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.PROVIDER.id())))
/* <!-- #BLAZE_RULE(platform).ATTRIBUTE(remote_execution_properties) -->
A string used to configure a remote execution platform. Actual builds make no attempt to
@@ -71,14 +71,14 @@
.add(
attr(CPU_CONSTRAINTS_ATTR, BuildType.LABEL_LIST)
.allowedFileTypes(FileTypeSet.NO_FILE)
- .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.SKYLARK_CONSTRUCTOR.id()))
+ .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.PROVIDER.id()))
.undocumented("Should only be used by internal packages."))
// Undocumented. Indicates to the rule which constraint_values to use for automatic CPU
// mapping.
.add(
attr(OS_CONSTRAINTS_ATTR, BuildType.LABEL_LIST)
.allowedFileTypes(FileTypeSet.NO_FILE)
- .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.SKYLARK_CONSTRUCTOR.id()))
+ .mandatoryProviders(ImmutableList.of(ConstraintValueInfo.PROVIDER.id()))
.undocumented("Should only be used by internal packages."))
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/platform/ToolchainRule.java b/src/main/java/com/google/devtools/build/lib/rules/platform/ToolchainRule.java
index 58b5231..cf44b23 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/platform/ToolchainRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/platform/ToolchainRule.java
@@ -58,7 +58,7 @@
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr(EXEC_COMPATIBLE_WITH_ATTR, BuildType.LABEL_LIST)
- .mandatoryProviders(ConstraintValueInfo.SKYLARK_CONSTRUCTOR.id())
+ .mandatoryProviders(ConstraintValueInfo.PROVIDER.id())
.allowedFileTypes()
.nonconfigurable("part of toolchain configuration"))
/* <!-- #BLAZE_RULE(toolchain).ATTRIBUTE(target_compatible_with) -->
@@ -67,7 +67,7 @@
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr(TARGET_COMPATIBLE_WITH_ATTR, BuildType.LABEL_LIST)
- .mandatoryProviders(ConstraintValueInfo.SKYLARK_CONSTRUCTOR.id())
+ .mandatoryProviders(ConstraintValueInfo.PROVIDER.id())
.allowedFileTypes()
.nonconfigurable("part of toolchain configuration"))
/* <!-- #BLAZE_RULE(toolchain).ATTRIBUTE(toolchain) -->
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/PlatformCommonApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/PlatformCommonApi.java
index e8dfe9a..de7621c 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/PlatformCommonApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform/PlatformCommonApi.java
@@ -26,22 +26,48 @@
doc = "Functions for Skylark to interact with the platform APIs."
)
public interface PlatformCommonApi {
-
@SkylarkCallable(
name = "TemplateVariableInfo",
- doc = "The provider used to retrieve the provider that contains the template variables "
- + "defined by a particular toolchain, for example by calling "
- + "ctx.attr._cc_toolchain[platform_common.TemplateVariableInfo].make_variables[<name>]",
- structField = true
- )
- public ProviderApi getMakeVariableProvider();
+ doc =
+ "The provider used to retrieve the provider that contains the template variables "
+ + "defined by a particular toolchain, for example by calling "
+ + "ctx.attr._cc_toolchain[platform_common.TemplateVariableInfo].make_variables[<name>]",
+ structField = true)
+ ProviderApi getMakeVariableProvider();
@SkylarkCallable(
- name = "ToolchainInfo",
- doc =
- "The provider constructor for ToolchainInfo. The constructor takes the type of the "
- + "toolchain, and a map of the toolchain's data.",
- structField = true
- )
- public ProviderApi getToolchainInfoConstructor();
+ name = "ToolchainInfo",
+ doc =
+ "The provider constructor for ToolchainInfo. The constructor takes the type of the "
+ + "toolchain, and a map of the toolchain's data.",
+ structField = true)
+ ProviderApi getToolchainInfoConstructor();
+
+ @SkylarkCallable(
+ name = "PlatformInfo",
+ doc =
+ "The provider constructor for PlatformInfo. The constructor takes the list of "
+ + "ConstraintValueInfo providers that defines the platform. "
+ + PlatformInfoApi.EXPERIMENTAL_WARNING,
+ structField = true)
+ ProviderApi getPlatformInfoConstructor();
+
+ @SkylarkCallable(
+ name = "ConstraintSettingInfo",
+ doc =
+ "The provider constructor for ConstraintSettingInfo. The constructor takes the label "
+ + "that uniquely identifies the constraint (and which should always be ctx.label). "
+ + PlatformInfoApi.EXPERIMENTAL_WARNING,
+ structField = true)
+ ProviderApi getConstraintSettingInfoConstructor();
+
+ @SkylarkCallable(
+ name = "ConstraintValueInfo",
+ doc =
+ "The provider constructor for ConstraintValueInfo. The constructor takes the label that "
+ + "uniquely identifies the constraint value (and which should always be ctx.label), "
+ + "and the ConstraintSettingInfo which the value belongs to. "
+ + PlatformInfoApi.EXPERIMENTAL_WARNING,
+ structField = true)
+ ProviderApi getConstraintValueInfoConstructor();
}
diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/platform/FakePlatformCommon.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/platform/FakePlatformCommon.java
index 2126581..faaf369 100644
--- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/platform/FakePlatformCommon.java
+++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/platform/FakePlatformCommon.java
@@ -32,4 +32,19 @@
public ProviderApi getToolchainInfoConstructor() {
return new FakeProviderApi();
}
+
+ @Override
+ public ProviderApi getPlatformInfoConstructor() {
+ return new FakeProviderApi();
+ }
+
+ @Override
+ public ProviderApi getConstraintSettingInfoConstructor() {
+ return new FakeProviderApi();
+ }
+
+ @Override
+ public ProviderApi getConstraintValueInfoConstructor() {
+ return new FakeProviderApi();
+ }
}
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 fb33c02..7026749 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
@@ -64,9 +64,9 @@
private EvaluationResult<ToolchainResolutionValue> invokeToolchainResolution(SkyKey key)
throws InterruptedException {
ConfiguredTarget mockLinuxTarget = mock(ConfiguredTarget.class);
- when(mockLinuxTarget.get(PlatformInfo.SKYLARK_CONSTRUCTOR)).thenReturn(linuxPlatform);
+ when(mockLinuxTarget.get(PlatformInfo.PROVIDER)).thenReturn(linuxPlatform);
ConfiguredTarget mockMacTarget = mock(ConfiguredTarget.class);
- when(mockMacTarget.get(PlatformInfo.SKYLARK_CONSTRUCTOR)).thenReturn(macPlatform);
+ when(mockMacTarget.get(PlatformInfo.PROVIDER)).thenReturn(macPlatform);
getSkyframeExecutor()
.getDifferencerForTesting()
.inject(