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 a607b2fa5836a8..bd8bae6821b115 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 @@ -30,12 +30,7 @@ import java.util.Map; import java.util.Objects; import javax.annotation.Nullable; -import net.starlark.java.eval.Dict; -import net.starlark.java.eval.EvalException; import net.starlark.java.eval.Printer; -import net.starlark.java.eval.Sequence; -import net.starlark.java.eval.Starlark; -import net.starlark.java.eval.StarlarkThread; import net.starlark.java.syntax.Location; /** Provider for a platform, which is a group of constraints and values. */ @@ -66,49 +61,8 @@ public class PlatformInfo extends NativeInfo } /** Provider singleton constant. */ - public static final BuiltinProvider PROVIDER = new Provider(); - - /** Provider for {@link PlatformInfo} objects. */ - private static class Provider extends BuiltinProvider - implements PlatformInfoApi.Provider< - ConstraintSettingInfo, ConstraintValueInfo, PlatformInfo> { - private Provider() { - super(STARLARK_NAME, PlatformInfo.class); - } - - @Override - public PlatformInfo platformInfo( - Label label, - Object parentUnchecked, - Sequence constraintValuesUnchecked, - Object execPropertiesUnchecked, - StarlarkThread thread) - throws EvalException { - PlatformInfo.Builder builder = PlatformInfo.builder(); - builder.setLabel(label); - if (parentUnchecked != Starlark.NONE) { - builder.setParent((PlatformInfo) parentUnchecked); - } - if (!constraintValuesUnchecked.isEmpty()) { - builder.addConstraints( - Sequence.cast( - constraintValuesUnchecked, ConstraintValueInfo.class, "constraint_values")); - } - if (execPropertiesUnchecked != null) { - Dict execProperties = - Dict.noneableCast( - execPropertiesUnchecked, String.class, String.class, "exec_properties"); - builder.setExecProperties(ImmutableMap.copyOf(execProperties)); - } - builder.setLocation(thread.getCallerLocation()); - - try { - return builder.build(); - } catch (DuplicateConstraintException | ExecPropertiesException e) { - throw new EvalException(e); - } - } - } + public static final BuiltinProvider PROVIDER = + new BuiltinProvider(STARLARK_NAME, PlatformInfo.class) {}; private final Label label; private final ConstraintCollection constraints; @@ -147,12 +101,10 @@ public ConstraintCollection constraints() { return constraints; } - @Override public String remoteExecutionProperties() { return remoteExecutionProperties; } - @Override public ImmutableMap execProperties() { return execProperties; } diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform/PlatformInfoApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform/PlatformInfoApi.java index 8d25181ea97d00..b97fcb92fe75ca 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform/PlatformInfoApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/platform/PlatformInfoApi.java @@ -15,21 +15,11 @@ package com.google.devtools.build.lib.starlarkbuildapi.platform; import com.google.devtools.build.docgen.annot.DocCategory; -import com.google.devtools.build.docgen.annot.StarlarkConstructor; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions; -import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi; import com.google.devtools.build.lib.starlarkbuildapi.core.StructApi; -import java.util.Map; -import net.starlark.java.annot.Param; -import net.starlark.java.annot.ParamType; import net.starlark.java.annot.StarlarkBuiltin; import net.starlark.java.annot.StarlarkMethod; -import net.starlark.java.eval.Dict; -import net.starlark.java.eval.EvalException; -import net.starlark.java.eval.NoneType; -import net.starlark.java.eval.Sequence; -import net.starlark.java.eval.StarlarkThread; /** Info object representing data about a specific platform. */ @StarlarkBuiltin( @@ -64,79 +54,4 @@ public interface PlatformInfoApi< structField = true, enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_PLATFORMS_API) ConstraintCollectionApi constraints(); - - @StarlarkMethod( - name = "remoteExecutionProperties", - doc = "Properties that are available for the use of remote execution.", - structField = true, - enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_PLATFORMS_API) - String remoteExecutionProperties(); - - @StarlarkMethod( - name = "exec_properties", - doc = "Properties to configure a remote execution platform.", - structField = true, - enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_PLATFORMS_API) - Map execProperties(); - - /** Provider for {@link PlatformInfoApi} objects. */ - @StarlarkBuiltin(name = "Provider", documented = false, doc = "") - interface Provider< - ConstraintSettingInfoT extends ConstraintSettingInfoApi, - ConstraintValueInfoT extends ConstraintValueInfoApi, - PlatformInfoT extends PlatformInfoApi> - extends ProviderApi { - - @StarlarkMethod( - name = "PlatformInfo", - doc = "The PlatformInfo constructor.", - documented = false, - parameters = { - @Param( - name = "label", - named = true, - positional = false, - doc = "The label for this platform."), - @Param( - name = "parent", - allowedTypes = { - @ParamType(type = PlatformInfoApi.class), - @ParamType(type = NoneType.class), - }, - defaultValue = "None", - named = true, - positional = false, - doc = "The parent of this platform."), - @Param( - name = "constraint_values", - allowedTypes = { - @ParamType(type = Sequence.class, generic1 = ConstraintValueInfoApi.class), - }, - defaultValue = "[]", - named = true, - positional = false, - doc = "The constraint values for the platform"), - @Param( - name = "exec_properties", - allowedTypes = { - @ParamType(type = Dict.class), - @ParamType(type = NoneType.class), - }, - defaultValue = "None", - named = true, - positional = false, - doc = "The exec properties for the platform.") - }, - selfCall = true, - useStarlarkThread = true, - enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_PLATFORMS_API) - @StarlarkConstructor - PlatformInfoT platformInfo( - Label label, - Object parent, - Sequence constraintValues, - Object execProperties, - StarlarkThread thread) - throws EvalException; - } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java b/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java index cc6bd0f0c4a9b3..3b14896bafae72 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/platform/PlatformInfoTest.java @@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.testing.EqualsTester; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; import org.junit.Test; @@ -291,156 +290,6 @@ public void execProperties_parentPlatform_inheritance() throws Exception { assertThat(platformInfo.execProperties()).containsExactly("p1", "keep", "p3", "child"); } - @Test - public void starlark_constructor() throws Exception { - scratch.file( - "test/platform/my_platform.bzl", - "def _impl(ctx):", - " constraints = [val[platform_common.ConstraintValueInfo] " - + "for val in ctx.attr.constraints]", - " platform = platform_common.PlatformInfo(", - " label = ctx.label, constraint_values = constraints)", - " return [platform]", - "my_platform = rule(", - " implementation = _impl,", - " attrs = {", - " 'constraints': attr.label_list(providers = [platform_common.ConstraintValueInfo])", - " }", - ")"); - scratch.file( - "test/constraint/BUILD", - "constraint_setting(name = 'basic')", - "constraint_value(name = 'foo',", - " constraint_setting = ':basic',", - ")"); - scratch.file( - "test/platform/BUILD", - "load('//test/platform:my_platform.bzl', 'my_platform')", - "my_platform(name = 'custom',", - " constraints = [", - " '//test/constraint:foo',", - " ],", - ")"); - - setBuildLanguageOptions("--experimental_platforms_api"); - ConfiguredTarget platform = getConfiguredTarget("//test/platform:custom"); - assertThat(platform).isNotNull(); - - PlatformInfo provider = PlatformProviderUtils.platform(platform); - assertThat(provider).isNotNull(); - assertThat(provider.label()).isEqualTo(Label.parseCanonicalUnchecked("//test/platform:custom")); - ConstraintSettingInfo constraintSetting = - ConstraintSettingInfo.create(Label.parseCanonicalUnchecked("//test/constraint:basic")); - ConstraintValueInfo constraintValue = - ConstraintValueInfo.create( - constraintSetting, Label.parseCanonicalUnchecked("//test/constraint:foo")); - assertThat(provider.constraints().get(constraintSetting)).isEqualTo(constraintValue); - } - - @Test - public void starlark_constructor_parent() throws Exception { - scratch.file( - "test/platform/my_platform.bzl", - "def _impl(ctx):", - " constraints = [val[platform_common.ConstraintValueInfo] " - + "for val in ctx.attr.constraints]", - " platform = platform_common.PlatformInfo(", - " label = ctx.label, constraint_values = constraints)", - " return [platform]", - "my_platform = rule(", - " implementation = _impl,", - " attrs = {", - " 'constraints': attr.label_list(providers = [platform_common.ConstraintValueInfo])", - " }", - ")"); - scratch.file( - "test/constraint/BUILD", - "constraint_setting(name = 'basic')", - "constraint_setting(name = 'complex')", - "constraint_value(name = 'foo',", - " constraint_setting = ':basic',", - ")", - "constraint_value(name = 'bar',", - " constraint_setting = ':basic',", - ")", - "constraint_value(name = 'baz',", - " constraint_setting = ':complex',", - ")"); - scratch.file( - "test/platform/BUILD", - "load('//test/platform:my_platform.bzl', 'my_platform')", - "platform(", - " name='parent',", - " constraint_values = [", - " '//test/constraint:foo',", - " ],", - ")", - "my_platform(name = 'custom',", - " constraints = [", - " '//test/constraint:bar',", - " '//test/constraint:baz',", - " ],", - ")"); - - setBuildLanguageOptions("--experimental_platforms_api"); - ConfiguredTarget platform = getConfiguredTarget("//test/platform:custom"); - assertThat(platform).isNotNull(); - - PlatformInfo provider = PlatformProviderUtils.platform(platform); - assertThat(provider).isNotNull(); - assertThat(provider.label()).isEqualTo(Label.parseCanonicalUnchecked("//test/platform:custom")); - - // Check that overrides work. - ConstraintSettingInfo constraintSetting = - ConstraintSettingInfo.create(Label.parseCanonicalUnchecked("//test/constraint:basic")); - ConstraintValueInfo constraintValue = - ConstraintValueInfo.create( - constraintSetting, Label.parseCanonicalUnchecked("//test/constraint:bar")); - assertThat(provider.constraints().get(constraintSetting)).isEqualTo(constraintValue); - - // Check that inheritance works. - ConstraintSettingInfo constraintSetting2 = - ConstraintSettingInfo.create(Label.parseCanonicalUnchecked("//test/constraint:complex")); - ConstraintValueInfo constraintValue2 = - ConstraintValueInfo.create( - constraintSetting2, Label.parseCanonicalUnchecked("//test/constraint:baz")); - assertThat(provider.constraints().get(constraintSetting2)).isEqualTo(constraintValue2); - } - - @Test - public void starlark_constructor_error_duplicateConstraints() throws Exception { - scratch.file( - "test/platform/my_platform.bzl", - "def _impl(ctx):", - " platform = platform_common.PlatformInfo()", - " return [platform]", - "my_platform = rule(", - " implementation = _impl,", - " attrs = {", - " 'constraints': attr.label_list(providers = [platform_common.ConstraintValueInfo])", - " }", - ")"); - scratch.file( - "test/constraint/BUILD", - "constraint_setting(name = 'basic')", - "constraint_value(name = 'foo',", - " constraint_setting = ':basic',", - ")"); - setBuildLanguageOptions("--experimental_platforms_api"); - checkError( - "test/platform", - "custom", - "Label '//test/constraint:foo' is duplicated in the 'constraints' attribute of rule" - + " 'custom'", - "load('//test/platform:my_platform.bzl', 'my_platform')", - "my_platform(name = 'custom',", - " constraints = [", - " '//test/constraint:foo',", - " '//test/constraint:foo',", - " ],", - ")"); - } - @Test public void equalsTester() throws Exception { ConstraintSettingInfo setting1 = diff --git a/src/test/shell/bazel/platforms_test.sh b/src/test/shell/bazel/platforms_test.sh index 56b4b030424850..c5d02d5a757d55 100755 --- a/src/test/shell/bazel/platforms_test.sh +++ b/src/test/shell/bazel/platforms_test.sh @@ -77,8 +77,8 @@ function test_platform_accessor() { cat > rules.bzl <<'EOF' def _impl(ctx): platform = ctx.attr.platform[platform_common.PlatformInfo] - properties = platform.exec_properties - print("The properties are:", properties) + label = platform.label + print("The label is:", label) return [] print_props = rule( @@ -98,15 +98,11 @@ print_props( platform( name = "my_platform", - exec_properties = { - "key": "value", - "key2": "value2", - } ) EOF bazel build --experimental_platforms_api=true :a &> $TEST_log || fail "Build failed" - grep 'The properties are: {"key2": "value2", "key": "value"}' $TEST_log || fail "Did not find expected properties" + expect_log 'The label is: @//:my_platform' } run_suite "platform repo test"