aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Erik Kuefler <ekuefler@gmail.com>2015-06-03 15:59:32 +0000
committerGravatar Florian Weikert <fwe@google.com>2015-06-05 09:37:29 +0000
commitad993f7fbd219e8cdbb3b048ebcdac72d2c4eae5 (patch)
tree00e57fe2a672bd3382f397a415c53aa2a0719818 /src/main/java/com/google
parent21f2a492f24914f80ffbb6e46ce050760b2bdc96 (diff)
Make source jars from java_library available to Skylark.
This is necessary to implement GWT support in Bazel, which requires source jars on the classpath. With this change, I can build a GWT classpath as follows: all_deps = ctx.files.deps for this_dep in ctx.attr.deps: if this_dep.java: all_deps += this_dep.java.source_jars classpath = ":".join([dep.path for dep in all_deps]) -- Change-Id: I1983cb57f15eb48e49b81b250bb18bb51b7d9391 Reviewed-on: https://bazel-review.googlesource.com/1441 MOS_MIGRATED_REVID=95111144
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java53
2 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
index 68f5ccd942..c2ced5912a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java
@@ -223,6 +223,7 @@ public class JavaLibrary implements RuleConfiguredTargetFactory {
new JavaRuntimeJarProvider(common.getJavaCompilationArtifacts().getRuntimeJars()))
.add(RunfilesProvider.class, RunfilesProvider.simple(runfiles))
.setFilesToBuild(filesToBuild)
+ .addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, new JavaSkylarkApiProvider())
.add(JavaNeverlinkInfoProvider.class, new JavaNeverlinkInfoProvider(neverLink))
.add(CppCompilationContext.class, transitiveCppDeps)
.add(JavaCompilationArgsProvider.class, new JavaCompilationArgsProvider(
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
new file mode 100644
index 0000000000..4c2122314f
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiProvider.java
@@ -0,0 +1,53 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+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.rules.SkylarkApiProvider;
+import com.google.devtools.build.lib.syntax.SkylarkCallable;
+import com.google.devtools.build.lib.syntax.SkylarkModule;
+
+/**
+ * A class that exposes the Java providers to Skylark. It is intended to provide a
+ * simple and stable interface for Skylark users.
+ */
+@SkylarkModule(
+ name = "JavaSkylarkApiProvider", doc = "Provides access to information about Java rules")
+public final class JavaSkylarkApiProvider extends SkylarkApiProvider {
+ /** The name of the field in Skylark used to access this class. */
+ static final String NAME = "java";
+
+ @SkylarkCallable(
+ name = "source_jars",
+ doc = "Returns the Jars containing Java source files for the target",
+ structField = true)
+ public ImmutableList<Artifact> getSourceJars() {
+ JavaSourceJarsProvider sourceJars = getInfo().getProvider(JavaSourceJarsProvider.class);
+ return sourceJars.getSourceJars();
+ }
+
+ @SkylarkCallable(
+ name = "transitive_source_jars",
+ doc =
+ "Returns the Jars containing Java source files for the target and all of its transitive "
+ + "dependencies",
+ structField = true)
+ public NestedSet<Artifact> getTransitiveSourceJars() {
+ JavaSourceJarsProvider sourceJars = getInfo().getProvider(JavaSourceJarsProvider.class);
+ return sourceJars.getTransitiveSourceJars();
+ }
+}