aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar elenairina <elenairina@google.com>2018-04-17 05:56:43 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-17 05:58:15 -0700
commitb1efe45a57e108e091ab632596c7a5e6162bb5a4 (patch)
treebb100b93f45edf735f479a92679c8fb088202845 /src/test/java/com/google/devtools/build
parent932b1f6c1429c5f6641ebd4850a6ed1854df98e5 (diff)
Add compilation_info in java_common.compile.
PiperOrigin-RevId: 193185628
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java60
1 files changed, 60 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 fecfad9e63..21eeaba08c 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
@@ -310,6 +310,66 @@ public class JavaSkylarkApiTest extends BuildViewTestCase {
}
@Test
+ public void testJavaCommonCompileCompilationInfo() throws Exception {
+ writeBuildFileForJavaToolchain();
+ scratch.file(
+ "java/test/BUILD",
+ "load(':custom_rule.bzl', 'java_custom_library')",
+ "java_custom_library(",
+ " name = 'custom',",
+ " srcs = ['Main.java'],",
+ " deps = [':dep']",
+ ")",
+ "java_library(",
+ " name = 'dep',",
+ " srcs = [ 'Dep.java'],",
+ ")");
+ scratch.file(
+ "java/test/custom_rule.bzl",
+ "def _impl(ctx):",
+ " output_jar = ctx.actions.declare_file('lib' + ctx.label.name + '.jar')",
+ " deps = [dep[java_common.provider] for dep in ctx.attr.deps]",
+ " compilation_provider = java_common.compile(",
+ " ctx,",
+ " source_files = ctx.files.srcs,",
+ " output = output_jar,",
+ " javac_opts = java_common.default_javac_opts(",
+ " ctx, java_toolchain_attr = '_java_toolchain'),",
+ " deps = deps,",
+ " java_toolchain = ctx.attr._java_toolchain,",
+ " host_javabase = ctx.attr._host_javabase",
+ " )",
+ " return struct(",
+ " files = depset([output_jar] + compilation_provider.source_jars),",
+ " providers = [compilation_provider]",
+ " )",
+ "java_custom_library = rule(",
+ " implementation = _impl,",
+ " outputs = {",
+ " 'my_output': 'lib%{name}.jar',",
+ " 'my_src_output': 'lib%{name}-src.jar'",
+ " },",
+ " attrs = {",
+ " 'srcs': attr.label_list(allow_files=['.java']),",
+ " 'deps': attr.label_list(),",
+ " '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
+ " '_host_javabase': attr.label(",
+ " default = Label('" + HOST_JAVA_RUNTIME_LABEL + "'))",
+ " },",
+ " fragments = ['java']",
+ ")");
+
+ ConfiguredTarget configuredTarget = getConfiguredTarget("//java/test:custom");
+ JavaInfo info = configuredTarget.get(JavaInfo.PROVIDER);
+ JavaCompilationInfoProvider compilationInfo = info.getCompilationInfoProvider();
+ assertThat(prettyArtifactNames(compilationInfo.getCompilationClasspath().toList())).
+ containsExactly("java/test/libdep-hjar.jar");
+
+ assertThat(prettyArtifactNames(compilationInfo.getRuntimeClasspath().toList())).
+ containsExactly("java/test/libdep.jar", "java/test/libcustom.jar");
+ }
+
+ @Test
public void testJavaCommonCompileTransitiveSourceJars() throws Exception {
writeBuildFileForJavaToolchain();
scratch.file(