diff options
author | 2018-01-02 04:27:11 -0800 | |
---|---|---|
committer | 2018-01-02 04:28:38 -0800 | |
commit | 63a8e1a9c2eb887c45e4ec37c7a858b004acd979 (patch) | |
tree | aeae05dce570f57755e53f0e1037342abcd31c28 /src/test | |
parent | 61dffca579074213e7489798601a9923973abd26 (diff) |
Don't output duplicate srcs when jar and sourcejar are the same
When a source jar is used as maven_jar the filegroup in the generated BUILD.bazel contains duplicate entries. This results in an error when the jar is used as a dependency (... is duplicated in the 'srcs' attribute of rule 'file').
This change simply doesn't write the duplicate entry to the BUILD.bazel file when the filenames are equal.
Closes #4333.
PiperOrigin-RevId: 180534960
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java index 11dfdbbb2f..9077297e76 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/JarDecompressorTest.java @@ -91,6 +91,23 @@ public class JarDecompressorTest { } @Test + public void testTargetIsSource() throws Exception { + Path outputDir = + decompressor.decompressWithSrcjar( + srcjarDescriptorBuilder.build(), + Optional.fromNullable(srcjarDescriptorBuilder.build())); + assertThat(outputDir.exists()).isTrue(); + assertThat(outputDir.getRelative("jar/foo.jar").exists()).isFalse(); + assertThat(outputDir.getRelative("jar/foo-sources.jar").exists()).isTrue(); + String buildContent = + new String(FileSystemUtils.readContentAsLatin1(outputDir.getRelative("jar/BUILD.bazel"))); + assertThat(buildContent).contains("java_import"); + assertThat(buildContent).contains("srcjar = 'foo-sources.jar'"); + assertThat(buildContent).contains("filegroup"); + assertThat(buildContent).contains("srcs = [\n 'foo-sources.jar',\n ],"); + } + + @Test // Note: WORKSPACE gen is not affected by presence or absence of Optional arg to // decompressWithSrcjar public void testWorkspaceGen() throws Exception { |