diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
4 files changed, 150 insertions, 38 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java index 934308992a..8531dec5e0 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/WorkspaceFactoryTest.java @@ -16,7 +16,6 @@ package com.google.devtools.build.lib.packages; import static com.google.common.truth.Truth.assertThat; -import com.google.devtools.build.lib.cmdline.Label; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -73,17 +72,16 @@ public class WorkspaceFactoryTest { @Test public void testRegisterExecutionPlatforms() throws Exception { WorkspaceFactoryTestHelper helper = parse("register_execution_platforms('//platform:ep1')"); - assertThat(helper.getPackage().getRegisteredExecutionPlatformLabels()) - .containsExactly(Label.parseAbsolute("//platform:ep1")); + assertThat(helper.getPackage().getRegisteredExecutionPlatforms()) + .containsExactly("//platform:ep1"); } @Test public void testRegisterExecutionPlatforms_multipleLabels() throws Exception { WorkspaceFactoryTestHelper helper = parse("register_execution_platforms(", " '//platform:ep1',", " '//platform:ep2')"); - assertThat(helper.getPackage().getRegisteredExecutionPlatformLabels()) - .containsExactly( - Label.parseAbsolute("//platform:ep1"), Label.parseAbsolute("//platform:ep2")); + assertThat(helper.getPackage().getRegisteredExecutionPlatforms()) + .containsExactly("//platform:ep1", "//platform:ep2"); } @Test @@ -91,35 +89,35 @@ public class WorkspaceFactoryTest { WorkspaceFactoryTestHelper helper = parse( "register_execution_platforms('//platform:ep1')", - "register_execution_platforms('//platform:ep2')"); - assertThat(helper.getPackage().getRegisteredExecutionPlatformLabels()) - .containsExactly( - Label.parseAbsolute("//platform:ep1"), Label.parseAbsolute("//platform:ep2")); + "register_execution_platforms('//platform:ep2')", + "register_execution_platforms('//platform/...')"); + assertThat(helper.getPackage().getRegisteredExecutionPlatforms()) + .containsExactly("//platform:ep1", "//platform:ep2", "//platform/..."); } @Test public void testRegisterToolchains() throws Exception { WorkspaceFactoryTestHelper helper = parse("register_toolchains('//toolchain:tc1')"); - assertThat(helper.getPackage().getRegisteredToolchainLabels()) - .containsExactly(Label.parseAbsolute("//toolchain:tc1")); + assertThat(helper.getPackage().getRegisteredToolchains()).containsExactly("//toolchain:tc1"); } @Test public void testRegisterToolchains_multipleLabels() throws Exception { WorkspaceFactoryTestHelper helper = parse("register_toolchains(", " '//toolchain:tc1',", " '//toolchain:tc2')"); - assertThat(helper.getPackage().getRegisteredToolchainLabels()) - .containsExactly( - Label.parseAbsolute("//toolchain:tc1"), Label.parseAbsolute("//toolchain:tc2")); + assertThat(helper.getPackage().getRegisteredToolchains()) + .containsExactly("//toolchain:tc1", "//toolchain:tc2"); } @Test public void testRegisterToolchains_multipleCalls() throws Exception { WorkspaceFactoryTestHelper helper = - parse("register_toolchains('//toolchain:tc1')", "register_toolchains('//toolchain:tc2')"); - assertThat(helper.getPackage().getRegisteredToolchainLabels()) - .containsExactly( - Label.parseAbsolute("//toolchain:tc1"), Label.parseAbsolute("//toolchain:tc2")); + parse( + "register_toolchains('//toolchain:tc1')", + "register_toolchains('//toolchain:tc2')", + "register_toolchains('//toolchain/...')"); + assertThat(helper.getPackage().getRegisteredToolchains()) + .containsExactly("//toolchain:tc1", "//toolchain:tc2", "//toolchain/..."); } private WorkspaceFactoryTestHelper parse(String... args) { diff --git a/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java b/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java index 8d07983cd5..fefefea50e 100644 --- a/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java +++ b/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java @@ -24,7 +24,6 @@ import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.ServerDirectories; import com.google.devtools.build.lib.analysis.util.AnalysisMock; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; -import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.packages.PackageFactory; @@ -189,9 +188,9 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { assertThatEvaluationResult(result).hasNoError(); - assertThat(result.get(key).registeredToolchainLabels()) + assertThat(result.get(key).registeredToolchains()) // There are default toolchains that are always registered, so just check for the ones added - .containsAllOf(makeLabel("//toolchain:tc1"), makeLabel("//toolchain:tc2")) + .containsAllOf("//toolchain:tc1", "//toolchain:tc2") .inOrder(); } @@ -206,8 +205,8 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { assertThatEvaluationResult(result).hasNoError(); - assertThat(result.get(key).registeredExecutionPlatformLabels()) - .containsExactly(makeLabel("//platform:ep1"), makeLabel("//platform:ep2")) + assertThat(result.get(key).registeredExecutionPlatforms()) + .containsExactly("//platform:ep1", "//platform:ep2") .inOrder(); } @@ -279,11 +278,11 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { @AutoValue abstract static class GetRegisteredToolchainsValue implements SkyValue { - abstract ImmutableList<Label> registeredToolchainLabels(); + abstract ImmutableList<String> registeredToolchains(); - static GetRegisteredToolchainsValue create(Iterable<Label> registeredToolchainLabels) { + static GetRegisteredToolchainsValue create(Iterable<String> registeredToolchains) { return new AutoValue_ExternalPackageUtilTest_GetRegisteredToolchainsValue( - ImmutableList.copyOf(registeredToolchainLabels)); + ImmutableList.copyOf(registeredToolchains)); } } @@ -293,12 +292,11 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { @Override public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException { - List<Label> registeredToolchainLabels = - RegisteredToolchainsFunction.getRegisteredToolchainLabels(env); - if (registeredToolchainLabels == null) { + List<String> registeredToolchains = RegisteredToolchainsFunction.getRegisteredToolchains(env); + if (registeredToolchains == null) { return null; } - return GetRegisteredToolchainsValue.create(registeredToolchainLabels); + return GetRegisteredToolchainsValue.create(registeredToolchains); } @Nullable @@ -327,12 +325,12 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { @AutoValue abstract static class GetRegisteredExecutionPlatformsValue implements SkyValue { - abstract ImmutableList<Label> registeredExecutionPlatformLabels(); + abstract ImmutableList<String> registeredExecutionPlatforms(); static GetRegisteredExecutionPlatformsValue create( - Iterable<Label> registeredExecutionPlatformLabels) { + Iterable<String> registeredExecutionPlatforms) { return new AutoValue_ExternalPackageUtilTest_GetRegisteredExecutionPlatformsValue( - ImmutableList.copyOf(registeredExecutionPlatformLabels)); + ImmutableList.copyOf(registeredExecutionPlatforms)); } } @@ -342,12 +340,12 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { @Override public SkyValue compute(SkyKey skyKey, Environment env) throws SkyFunctionException, InterruptedException { - List<Label> registeredExecutionPlatformLabels = + List<String> registeredExecutionPlatforms = RegisteredExecutionPlatformsFunction.getWorkspaceExecutionPlatforms(env); - if (registeredExecutionPlatformLabels == null) { + if (registeredExecutionPlatforms == null) { return null; } - return GetRegisteredExecutionPlatformsValue.create(registeredExecutionPlatformLabels); + return GetRegisteredExecutionPlatformsValue.create(registeredExecutionPlatforms); } @Nullable diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java index c00261969c..21d1229436 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsFunctionTest.java @@ -108,6 +108,54 @@ public class RegisteredExecutionPlatformsFunctionTest extends ToolchainTestCase } @Test + public void testRegisteredExecutionPlatforms_targetPattern_workspace() throws Exception { + + // Add an extra execution platform. + scratch.file( + "extra/BUILD", + "platform(name = 'execution_platform_1')", + "platform(name = 'execution_platform_2')"); + + rewriteWorkspace("register_execution_platforms('//extra/...')"); + + SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); + EvaluationResult<RegisteredExecutionPlatformsValue> result = + requestExecutionPlatformsFromSkyframe(executionPlatformsKey); + assertThatEvaluationResult(result).hasNoError(); + + // Verify that the target registered with the extra_execution_platforms flag is first in the + // list. + assertExecutionPlatformLabels(result.get(executionPlatformsKey)) + .containsAllOf( + makeLabel("//extra:execution_platform_1"), makeLabel("//extra:execution_platform_2")) + .inOrder(); + } + + @Test + public void testRegisteredExecutionPlatforms_targetPattern_flagOverride() throws Exception { + + // Add an extra execution platform. + scratch.file( + "extra/BUILD", + "platform(name = 'execution_platform_1')", + "platform(name = 'execution_platform_2')"); + + useConfiguration("--extra_execution_platforms=//extra/..."); + + SkyKey executionPlatformsKey = RegisteredExecutionPlatformsValue.key(targetConfigKey); + EvaluationResult<RegisteredExecutionPlatformsValue> result = + requestExecutionPlatformsFromSkyframe(executionPlatformsKey); + assertThatEvaluationResult(result).hasNoError(); + + // Verify that the target registered with the extra_execution_platforms flag is first in the + // list. + assertExecutionPlatformLabels(result.get(executionPlatformsKey)) + .containsAllOf( + makeLabel("//extra:execution_platform_1"), makeLabel("//extra:execution_platform_2")) + .inOrder(); + } + + @Test public void testRegisteredExecutionPlatforms_notExecutionPlatform() throws Exception { rewriteWorkspace("register_execution_platforms(", " '//error:not_an_execution_platform')"); scratch.file("error/BUILD", "filegroup(name = 'not_an_execution_platform')"); 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 d405ef8186..311cd5ad0a 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 @@ -41,7 +41,7 @@ public class RegisteredToolchainsFunctionTest extends ToolchainTestCase { assertThatEvaluationResult(result).hasEntryThat(toolchainsKey).isNotNull(); RegisteredToolchainsValue value = result.get(toolchainsKey); - // We have two registered toolchains, and a default for c++ + // We have two registered toolchains, and a default toolchain for C++. assertThat(value.registeredToolchains()).hasSize(3); assertThat( @@ -124,6 +124,74 @@ public class RegisteredToolchainsFunctionTest extends ToolchainTestCase { } @Test + public void testRegisteredToolchains_targetPattern_workspace() throws Exception { + scratch.appendFile("extra/BUILD", "filegroup(name = 'not_a_platform')"); + addToolchain( + "extra", + "extra_toolchain1", + ImmutableList.of("//constraints:linux"), + ImmutableList.of("//constraints:linux"), + "foo"); + addToolchain( + "extra", + "extra_toolchain2", + ImmutableList.of("//constraints:linux"), + ImmutableList.of("//constraints:mac"), + "bar"); + addToolchain( + "extra/more", + "more_toolchain", + ImmutableList.of("//constraints:mac"), + ImmutableList.of("//constraints:linux"), + "baz"); + rewriteWorkspace("register_toolchains('//extra/...')"); + + SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey); + EvaluationResult<RegisteredToolchainsValue> result = + requestToolchainsFromSkyframe(toolchainsKey); + assertThatEvaluationResult(result).hasNoError(); + assertToolchainLabels(result.get(toolchainsKey)) + .containsAllOf( + makeLabel("//extra:extra_toolchain1_impl"), + makeLabel("//extra:extra_toolchain2_impl"), + makeLabel("//extra/more:more_toolchain_impl")); + } + + @Test + public void testRegisteredToolchains_targetPattern_flagOverride() throws Exception { + scratch.appendFile("extra/BUILD", "filegroup(name = 'not_a_platform')"); + addToolchain( + "extra", + "extra_toolchain1", + ImmutableList.of("//constraints:linux"), + ImmutableList.of("//constraints:linux"), + "foo"); + addToolchain( + "extra", + "extra_toolchain2", + ImmutableList.of("//constraints:linux"), + ImmutableList.of("//constraints:mac"), + "bar"); + addToolchain( + "extra/more", + "more_toolchain", + ImmutableList.of("//constraints:mac"), + ImmutableList.of("//constraints:linux"), + "baz"); + useConfiguration("--extra_toolchains=//extra/..."); + + SkyKey toolchainsKey = RegisteredToolchainsValue.key(targetConfigKey); + EvaluationResult<RegisteredToolchainsValue> result = + requestToolchainsFromSkyframe(toolchainsKey); + assertThatEvaluationResult(result).hasNoError(); + assertToolchainLabels(result.get(toolchainsKey)) + .containsAllOf( + makeLabel("//extra:extra_toolchain1_impl"), + makeLabel("//extra:extra_toolchain2_impl"), + makeLabel("//extra/more:more_toolchain_impl")); + } + + @Test public void testRegisteredToolchains_reload() throws Exception { rewriteWorkspace("register_toolchains('//toolchain:toolchain_1')"); |