aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2018-04-30 09:50:08 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-30 09:52:05 -0700
commita77afc4c85bf5dc345de1422a3081eb840154a8f (patch)
tree8d4fc0c72b635e32674a1beb4d83e8d11b04969d /src/test/java/com/google/devtools/build
parentd7fde0ea4580e58beb6801929daf0c183c3affba (diff)
Allow JavaInfo providers without sources or exports
PiperOrigin-RevId: 194799276
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
index 78514f2be3..da39f19f8e 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
@@ -599,7 +599,47 @@ public class JavaSkylarkApiTest extends BuildViewTestCase {
assertThat(e.getMessage())
.contains("source_jars, sources and exports cannot be simultaneous empty");
}
+ }
+ @Test
+ public void testJavaInfoWithNoSources() throws Exception {
+ writeBuildFileForJavaToolchain();
+ scratch.file("java/test/lib.jar");
+ scratch.file(
+ "java/test/BUILD",
+ "load(':custom_rule.bzl', 'java_custom_library')",
+ "java_custom_library(",
+ " name = 'custom',",
+ " jar = 'lib.jar',",
+ ")");
+ scratch.file(
+ "java/test/custom_rule.bzl",
+ "def _impl(ctx):",
+ " jar = ctx.file.jar",
+ " new = JavaInfo(output_jar = jar, use_ijar = False)",
+ " old = java_common.create_provider(",
+ " compile_time_jars = [jar],",
+ " transitive_compile_time_jars = [jar],",
+ " runtime_jars = [jar],",
+ " use_ijar = False,",
+ " )",
+ " java_info = java_common.merge([old, new])",
+ " return struct(providers = [java_info])",
+ "java_custom_library = rule(",
+ " implementation = _impl,",
+ " attrs = {",
+ " 'jar': attr.label(allow_files = True, single_file = True),",
+ " '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
+ " '_host_javabase': attr.label(",
+ " default = Label('" + HOST_JAVA_RUNTIME_LABEL + "'))",
+ " },",
+ " fragments = ['java']",
+ ")");
+ JavaCompilationArgsProvider provider =
+ JavaInfo.getProvider(
+ JavaCompilationArgsProvider.class, getConfiguredTarget("//java/test:custom"));
+ assertThat(prettyArtifactNames(provider.getDirectCompileTimeJars()))
+ .containsExactly("java/test/lib.jar");
}
@Test