From c7d3bb2be55acbc65d7c28fd2ae74d51c3858430 Mon Sep 17 00:00:00 2001 From: Erik Kuefler Date: Tue, 9 Jun 2015 11:14:42 +0000 Subject: Make Java transitive runtime and compile time deps available to Skylark. This is necessary to add support for Java-based languages like GWT, Groovy, and Scala. With this change, I can construct a classpath for GWT as follows: all_deps = set(ctx.files.deps + ctx.files._implicitdeps) for this_dep in ctx.attr.deps: if hasattr(this_dep, 'java'): all_deps += this_dep.java.transitive_runtime_deps all_deps += this_dep.java.transitive_source_jars classpath = ":".join([dep.path for dep in all_deps]) -- Change-Id: If58ffd19a4cc19f69d5f98814c11391683804234 Reviewed-on: https://bazel-review.googlesource.com/#/c/1480 MOS_MIGRATED_REVID=95523130 --- .../lib/rules/java/JavaSkylarkApiProvider.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java index 4c2122314f..b13a128f2e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java @@ -14,9 +14,10 @@ package com.google.devtools.build.lib.rules.java; -import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.collect.nestedset.NestedSet; +import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; +import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.rules.SkylarkApiProvider; import com.google.devtools.build.lib.syntax.SkylarkCallable; import com.google.devtools.build.lib.syntax.SkylarkModule; @@ -35,9 +36,27 @@ public final class JavaSkylarkApiProvider extends SkylarkApiProvider { name = "source_jars", doc = "Returns the Jars containing Java source files for the target", structField = true) - public ImmutableList getSourceJars() { + public NestedSet getSourceJars() { JavaSourceJarsProvider sourceJars = getInfo().getProvider(JavaSourceJarsProvider.class); - return sourceJars.getSourceJars(); + return NestedSetBuilder.wrap(Order.STABLE_ORDER, sourceJars.getSourceJars()); + } + + @SkylarkCallable( + name = "transitive_deps", + doc = "Returns the transitive set of Jars required to build the target", + structField = true) + public NestedSet getTransitiveDeps() { + JavaCompilationArgsProvider args = getInfo().getProvider(JavaCompilationArgsProvider.class); + return args.getRecursiveJavaCompilationArgs().getCompileTimeJars(); + } + + @SkylarkCallable( + name = "transitive_runtime_deps", + doc = "Returns the transitive set of Jars required on the target's runtime classpath", + structField = true) + public NestedSet getTransitiveRuntimeDeps() { + JavaCompilationArgsProvider args = getInfo().getProvider(JavaCompilationArgsProvider.class); + return args.getRecursiveJavaCompilationArgs().getRuntimeJars(); } @SkylarkCallable( -- cgit v1.2.3