diff options
author | 2017-06-06 11:25:38 -0400 | |
---|---|---|
committer | 2017-06-06 12:36:59 -0400 | |
commit | d9223e00c18466bd286a5e400007acb78ddeb9de (patch) | |
tree | c0924b724f3ba80223a1c52c9633f4a2e4c7ddc2 /src/test/java/com/google/devtools/build/lib/rules/platform | |
parent | b16a7e10a025e7862ecfb3cdb3a38de412122f46 (diff) |
Fix automatic host platform detection to check the --host_cpu flag.
Also adds a new target_platform attribute that checks the --cpu flag.
Part of #2219.
Change-Id: Icc732917db127ac8377a7722adc70b1a722d538a
PiperOrigin-RevId: 158143095
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/platform')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/platform/PlatformTest.java | 57 |
1 files changed, 38 insertions, 19 deletions
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 152aca3f8f..8c71ae324b 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 @@ -24,8 +24,6 @@ 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 com.google.devtools.build.lib.util.CPU; -import com.google.devtools.build.lib.util.OS; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -70,36 +68,57 @@ public class PlatformTest extends BuildViewTestCase { } @Test - public void testPlatform_host() throws Exception { - String currentCpu = CPU.getCurrent().getCanonicalName(); - String currentOs = OS.getCurrent().getCanonicalName(); + public void testPlatform_autoconfig() throws Exception { + useConfiguration("--host_cpu=piii", "--cpu=k8"); + scratch.file( - "host/BUILD", + "autoconfig/BUILD", "constraint_setting(name = 'cpu')", - "constraint_value(name = '" + currentCpu + "', constraint_setting = ':cpu')", + "constraint_value(name = 'x86_32', constraint_setting = ':cpu')", + "constraint_value(name = 'x86_64', constraint_setting = ':cpu')", "constraint_value(name = 'another_cpu', constraint_setting = ':cpu')", "constraint_setting(name = 'os')", - "constraint_value(name = '" + currentOs + "', constraint_setting = ':os')", + "constraint_value(name = 'linux', constraint_setting = ':os')", "constraint_value(name = 'another_os', constraint_setting = ':os')", "platform(name = 'host_platform',", " host_platform = True,", - " host_cpu_constraints = [':" + currentCpu + "', ':another_cpu'],", - " host_os_constraints = [':" + currentOs + "', ':another_os'],", + " cpu_constraints = [':x86_32', 'x86_64', ':another_cpu'],", + " os_constraints = [':linux', ':another_os'],", + ")", + "platform(name = 'target_platform',", + " target_platform = True,", + " cpu_constraints = [':x86_32', 'x86_64', ':another_cpu'],", + " os_constraints = [':linux', ':another_os'],", ")"); - ConfiguredTarget platform = getConfiguredTarget("//host:host_platform"); - assertThat(platform).isNotNull(); + // Check the host platform. + ConfiguredTarget hostPlatform = getConfiguredTarget("//autoconfig:host_platform"); + assertThat(hostPlatform).isNotNull(); - PlatformInfo provider = PlatformProviderUtils.platform(platform); - assertThat(provider).isNotNull(); + PlatformInfo hostPlatformProvider = PlatformProviderUtils.platform(hostPlatform); + assertThat(hostPlatformProvider).isNotNull(); + + // Check the CPU and OS. + ConstraintSettingInfo cpuConstraint = + ConstraintSettingInfo.create(makeLabel("//autoconfig:cpu")); + ConstraintSettingInfo osConstraint = ConstraintSettingInfo.create(makeLabel("//autoconfig:os")); + assertThat(hostPlatformProvider.constraints()) + .containsExactly( + ConstraintValueInfo.create(cpuConstraint, makeLabel("//autoconfig:x86_32")), + ConstraintValueInfo.create(osConstraint, makeLabel("//autoconfig:linux"))); + + // Check the target platform. + ConfiguredTarget targetPlatform = getConfiguredTarget("//autoconfig:target_platform"); + assertThat(targetPlatform).isNotNull(); + + PlatformInfo targetPlatformProvider = PlatformProviderUtils.platform(targetPlatform); + assertThat(targetPlatformProvider).isNotNull(); // Check the CPU and OS. - ConstraintSettingInfo cpuConstraint = ConstraintSettingInfo.create(makeLabel("//host:cpu")); - ConstraintSettingInfo osConstraint = ConstraintSettingInfo.create(makeLabel("//host:os")); - assertThat(provider.constraints()) + assertThat(targetPlatformProvider.constraints()) .containsExactly( - ConstraintValueInfo.create(cpuConstraint, makeLabel("//host:" + currentCpu)), - ConstraintValueInfo.create(osConstraint, makeLabel("//host:" + currentOs))); + ConstraintValueInfo.create(cpuConstraint, makeLabel("//autoconfig:x86_64")), + ConstraintValueInfo.create(osConstraint, makeLabel("//autoconfig:linux"))); } @Test |