diff options
author | Carmi Grushko <carmi@google.com> | 2016-11-22 20:26:32 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2016-11-23 08:50:59 +0000 |
commit | c944c4d9fc5cbad830b69383a76ffff463088c7e (patch) | |
tree | f82e66e9b269272e53bd8ade0f75f3f19ec7db16 /src/test/java/com | |
parent | 0aac8f7d4f2cea1834df4aaf4cad35d3425d874b (diff) |
Alias proto_library's produce a descriptor set that contains all srcs of its dependencies.
(alias proto_library's are those with a deps attribute but no srcs attribute)
RELNOTES: Alias proto_library's produce a descriptor set that contains all srcs of its dependencies.
--
MOS_MIGRATED_REVID=139940475
Diffstat (limited to 'src/test/java/com')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java | 45 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java | 20 |
2 files changed, 57 insertions, 8 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java index ada3e125d1..f672649a00 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java @@ -20,19 +20,58 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.util.ActionsTestUtil; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class BazelProtoLibraryTest extends BuildViewTestCase { + + @Before + public void setUp() throws Exception { + scratch.file("third_party/protobuf/BUILD", "licenses(['notice'])", "exports_files(['protoc'])"); + } + @Test public void testDescriptorSetOutput() throws Exception { - scratch.file("third_party/protobuf/BUILD", "licenses(['notice'])", "exports_files(['protoc'])"); ConfiguredTarget target = - scratchConfiguredTarget("foo", "foo", "proto_library(name='foo', srcs=['foo.proto'])"); + scratchConfiguredTarget("x", "foo", "proto_library(name='foo', srcs=['foo.proto'])"); + Artifact file = + ActionsTestUtil.getFirstArtifactEndingWith(getFilesToBuild(target), ".proto.bin"); + assertThat(file.getRootRelativePathString()).isEqualTo("x/foo-descriptor-set.proto.bin"); + + assertThat(getGeneratingSpawnAction(file).getRemainingArguments()) + .containsAllOf( + "-Ix/foo.proto=x/foo.proto", + "--descriptor_set_out=" + file.getExecPathString(), + "x/foo.proto"); + } + + @Test + public void testDescriptorSetOutput_aliasLibrary() throws Exception { + ConfiguredTarget target = + scratchConfiguredTarget( + "x", + "alias", + "proto_library(name='alias', deps = [':second_alias'])", + "proto_library(name='second_alias', deps = [':foo'])", + "proto_library(name='foo', srcs=['foo.proto'])"); Artifact file = ActionsTestUtil.getFirstArtifactEndingWith(getFilesToBuild(target), ".proto.bin"); - assertThat(file.getRootRelativePathString()).isEqualTo("foo/foo-descriptor-set.proto.bin"); + assertThat(file.getRootRelativePathString()).isEqualTo("x/alias-descriptor-set.proto.bin"); + + assertThat(getGeneratingSpawnAction(file).getRemainingArguments()) + .containsAllOf( + "-Ix/foo.proto=x/foo.proto", + "--descriptor_set_out=" + file.getExecPathString(), + "x/foo.proto"); + } + + @Test + public void testDescriptorSetOutput_noSrcs() throws Exception { + ConfiguredTarget target = scratchConfiguredTarget("x", "foo", "proto_library(name='foo')"); + assertThat(ActionsTestUtil.getFirstArtifactEndingWith(getFilesToBuild(target), ".proto.bin")) + .isNull(); } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java index abbdac5d2c..d9f7a13bad 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java @@ -82,7 +82,9 @@ public class ProtoCompileActionBuilderTest { new ToolchainInvocation( "dontcare_because_no_plugin", toolchainNoPlugin, "foo.srcjar"), new ToolchainInvocation("pluginName", toolchainWithPlugin, "bar.srcjar")), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), true /* allowServices */, ImmutableList.<String>of() /* protocOpts */); @@ -118,7 +120,9 @@ public class ProtoCompileActionBuilderTest { CustomCommandLine cmdLine = createCommandLineFromToolchains( ImmutableList.of(new ToolchainInvocation("dontcare", toolchain, "foo.srcjar")), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), true /* allowServices */, ImmutableList.<String>of() /* protocOpts */); @@ -145,7 +149,9 @@ public class ProtoCompileActionBuilderTest { CustomCommandLine cmdLine = createCommandLineFromToolchains( ImmutableList.<ToolchainInvocation>of(), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), false /* allowServices */, ImmutableList.of("--foo", "--bar") /* protocOpts */); @@ -184,7 +190,9 @@ public class ProtoCompileActionBuilderTest { CustomCommandLine cmdLine = createCommandLineFromToolchains( ImmutableList.of(new ToolchainInvocation("pluginName", toolchain, outReplacement)), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), true /* allowServices */, ImmutableList.<String>of() /* protocOpts */); @@ -226,7 +234,9 @@ public class ProtoCompileActionBuilderTest { ImmutableList.of( new ToolchainInvocation("pluginName", toolchain1, "outReplacement"), new ToolchainInvocation("pluginName", toolchain2, "outReplacement")), - supportData, + supportData.getDirectProtoSources(), + supportData.getTransitiveImports(), + supportData.getProtosInDirectDeps(), true /* allowServices */, ImmutableList.<String>of() /* protocOpts */); fail("Expected an exception"); |