From e00a2b191a45e1efd24f2d491b8abd49235c9db1 Mon Sep 17 00:00:00 2001 From: John Cater Date: Tue, 6 Mar 2018 13:18:26 -0800 Subject: Do not expose platform-related providers to Skylark. This prevents both creation and access to platform providers from Skylark. This is needed so we can load platforms directly from platform-rule targets without needing a full configured target, and to effiently distinguish platform providers from non-platform providers. Change-Id: I6b61f9ee7518d5e9311232908a922596e18fe32f PiperOrigin-RevId: 188070457 --- .../platform/ConstraintSettingInfoTest.java | 27 --------- .../analysis/platform/ConstraintValueInfoTest.java | 36 ------------ .../lib/analysis/platform/PlatformInfoTest.java | 64 ---------------------- .../build/lib/rules/platform/ConstraintTest.java | 32 ----------- .../build/lib/rules/platform/PlatformTest.java | 37 ------------- 5 files changed, 196 deletions(-) (limited to 'src/test/java/com') diff --git a/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintSettingInfoTest.java b/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintSettingInfoTest.java index ca34b45f40..ed48aa7ba7 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintSettingInfoTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintSettingInfoTest.java @@ -14,12 +14,9 @@ package com.google.devtools.build.lib.analysis.platform; -import static com.google.common.truth.Truth.assertThat; 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; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -37,28 +34,4 @@ public class ConstraintSettingInfoTest extends BuildViewTestCase { .addEqualityGroup(ConstraintSettingInfo.create(makeLabel("//constraint:other"))) .testEquals(); } - - @Test - public void constraintSettingInfoConstructor() throws Exception { - scratch.file( - "test/platform/my_constraint_setting.bzl", - "def _impl(ctx):", - " constraint_setting = platform_common.ConstraintSettingInfo(label = ctx.label)", - " return [constraint_setting]", - "my_constraint_setting = rule(", - " implementation = _impl,", - " attrs = {", - " }", - ")"); - scratch.file( - "test/platform/BUILD", - "load('//test/platform:my_constraint_setting.bzl', 'my_constraint_setting')", - "my_constraint_setting(name = 'custom')"); - - ConfiguredTarget setting = getConfiguredTarget("//test/platform:custom"); - assertThat(setting).isNotNull(); - assertThat(PlatformProviderUtils.constraintSetting(setting)).isNotNull(); - assertThat(PlatformProviderUtils.constraintSetting(setting).label()) - .isEqualTo(Label.parseAbsolute("//test/platform:custom")); - } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfoTest.java b/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfoTest.java index 9684124862..df5178ab13 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfoTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/platform/ConstraintValueInfoTest.java @@ -14,12 +14,9 @@ package com.google.devtools.build.lib.analysis.platform; -import static com.google.common.truth.Truth.assertThat; 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; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -45,37 +42,4 @@ public class ConstraintValueInfoTest extends BuildViewTestCase { ConstraintValueInfo.create(setting2, makeLabel("//constraint:otherValue"))) .testEquals(); } - - @Test - public void constraintValueInfoConstructor() throws Exception { - scratch.file( - "test/platform/my_constraint_value.bzl", - "def _impl(ctx):", - " setting = ctx.attr.setting[platform_common.ConstraintSettingInfo]", - " constraint_value = platform_common.ConstraintValueInfo(", - " label = ctx.label, constraint_setting = setting)", - " return [constraint_value]", - "my_constraint_value = rule(", - " implementation = _impl,", - " attrs = {", - " 'setting': attr.label(providers = [platform_common.ConstraintSettingInfo]),", - " }", - ")"); - scratch.file( - "test/platform/BUILD", - "load('//test/platform:my_constraint_value.bzl', 'my_constraint_value')", - "constraint_setting(name = 'basic')", - "my_constraint_value(", - " name = 'custom',", - " setting = ':basic',", - ")"); - - ConfiguredTarget value = getConfiguredTarget("//test/platform:custom"); - assertThat(value).isNotNull(); - assertThat(PlatformProviderUtils.constraintValue(value)).isNotNull(); - assertThat(PlatformProviderUtils.constraintValue(value).constraint().label()) - .isEqualTo(Label.parseAbsolute("//test/platform:basic")); - assertThat(PlatformProviderUtils.constraintValue(value).label()) - .isEqualTo(Label.parseAbsolute("//test/platform:custom")); - } } 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 6c7c91bd4d..e0b5dde4fb 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 @@ -127,70 +127,6 @@ public class PlatformInfoTest extends BuildViewTestCase { .testEquals(); } - @Test - public void platformInfoConstructor() 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/platform/BUILD", - "load('//test/platform:my_platform.bzl', 'my_platform')", - "my_platform(name = 'custom',", - " constraints = [", - " '//constraint:foo',", - " ])"); - - ConfiguredTarget platform = getConfiguredTarget("//test/platform:custom"); - assertThat(platform).isNotNull(); - - PlatformInfo provider = PlatformProviderUtils.platform(platform); - assertThat(provider).isNotNull(); - assertThat(provider.label()).isEqualTo(makeLabel("//test/platform:custom")); - assertThat(provider.constraints()).hasSize(1); - ConstraintSettingInfo constraintSetting = - ConstraintSettingInfo.create(makeLabel("//constraint:basic")); - ConstraintValueInfo constraintValue = - ConstraintValueInfo.create(constraintSetting, makeLabel("//constraint:foo")); - assertThat(provider.constraints()).containsExactly(constraintValue); - assertThat(provider.remoteExecutionProperties()).isNull(); - } - - @Test - public void platformInfoConstructor_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])", - " }", - ")"); - checkError( - "test/platform", - "custom", - "Label '//constraint:foo' is duplicated in the 'constraints' attribute of rule 'custom'", - "load('//test/platform:my_platform.bzl', 'my_platform')", - "my_platform(name = 'custom',", - " constraints = [", - " '//constraint:foo',", - " '//constraint:foo',", - " ])"); - } - @Test public void proxyTemplateVariableInfo() throws Exception { scratch.file( diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintTest.java b/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintTest.java index 23ff526c18..200d9f7ebf 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/ConstraintTest.java @@ -64,36 +64,4 @@ public class ConstraintTest extends BuildViewTestCase { assertThat(PlatformProviderUtils.constraintValue(barValue).label()) .isEqualTo(Label.parseAbsolute("//constraint:bar")); } - - @Test - public void testConstraint_skylark() throws Exception { - - scratch.file( - "test/platform/constraints.bzl", - "def _impl(ctx):", - " constraint_value = ctx.attr.constraint[platform_common.ConstraintValueInfo]", - " return struct(", - " setting = constraint_value.constraint.label,", - " value = constraint_value.label)", - "my_rule = rule(", - " implementation = _impl,", - " attrs = { 'constraint': attr.label(providers = [platform_common.ConstraintValueInfo])},", - ")"); - - scratch.file( - "test/platform/BUILD", - "load('//test/platform:constraints.bzl', 'my_rule')", - "my_rule(name = 'r',", - " constraint = '//constraint:foo')"); - - ConfiguredTarget configuredTarget = getConfiguredTarget("//test/platform:r"); - assertThat(configuredTarget).isNotNull(); - - Label settingLabel = (Label) configuredTarget.get("setting"); - assertThat(settingLabel).isNotNull(); - assertThat(settingLabel).isEqualTo(makeLabel("//constraint:basic")); - Label valueLabel = (Label) configuredTarget.get("value"); - assertThat(valueLabel).isNotNull(); - assertThat(valueLabel).isEqualTo(makeLabel("//constraint:foo")); - } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformTest.java b/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformTest.java index bfbca10cea..cbe1edc135 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/platform/PlatformTest.java @@ -22,7 +22,6 @@ 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.PlatformProviderUtils; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; -import com.google.devtools.build.lib.cmdline.Label; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -156,40 +155,4 @@ public class PlatformTest extends BuildViewTestCase { assertThat(provider).isNotNull(); assertThat(provider.remoteExecutionProperties()).isEqualTo("foo: val1"); } - - @Test - public void testPlatform_skylark() throws Exception { - - scratch.file( - "test/platform/platform.bzl", - "def _impl(ctx):", - " platform = ctx.attr.platform[platform_common.PlatformInfo]", - " return struct(", - " count = len(platform.constraints),", - " first_setting = platform.constraints[0].constraint.label,", - " first_value = platform.constraints[0].label)", - "my_rule = rule(", - " implementation = _impl,", - " attrs = { 'platform': attr.label(providers = [platform_common.PlatformInfo])},", - ")"); - - scratch.file( - "test/platform/BUILD", - "load('//test/platform:platform.bzl', 'my_rule')", - "my_rule(name = 'r',", - " platform = '//constraint:plat1')"); - - ConfiguredTarget configuredTarget = getConfiguredTarget("//test/platform:r"); - assertThat(configuredTarget).isNotNull(); - - int count = (int) configuredTarget.get("count"); - assertThat(count).isEqualTo(1); - - Label settingLabel = (Label) configuredTarget.get("first_setting"); - assertThat(settingLabel).isNotNull(); - assertThat(settingLabel).isEqualTo(makeLabel("//constraint:basic")); - Label valueLabel = (Label) configuredTarget.get("first_value"); - assertThat(valueLabel).isNotNull(); - assertThat(valueLabel).isEqualTo(makeLabel("//constraint:foo")); - } } -- cgit v1.2.3