Skip to content

Commit

Permalink
Expose output source jars to JavaInfo.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 168345699
  • Loading branch information
iirina authored and philwo committed Sep 12, 2017
1 parent b0fd49b commit fc06a75
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import java.util.ArrayList;
import java.util.LinkedList;
Expand Down Expand Up @@ -222,6 +223,18 @@ public SkylarkNestedSet getCompileTimeJars() {
.getJavaCompilationArgs().getCompileTimeJars());
}

@SkylarkCallable(
name = "source_jars",
doc = "Returns a list of jar files containing all the uncompiled source files (including "
+ "those generated by annotations) from the target itself, i.e. NOT including the sources of "
+ "the transitive dependencies",
structField = true
)
public SkylarkList<Artifact> getSourceJars() {
return SkylarkList.createImmutable(
providers.getProvider(JavaSourceJarsProvider.class).getSourceJars());
}

@Override
public boolean equals(Object otherObject) {
if (this == otherObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,28 @@ public void skylarkJavaToJavaImportAttributes() throws Exception {
"foo/libjl_bottom_for_deps.jar", "foo/libjl_bottom_for_runtime_deps.jar");
}

@Test
public void javaInfoSourceJarsExposed() throws Exception {
scratch.file(
"foo/extension.bzl",
"result = provider()",
"def _impl(ctx):",
" return [result(source_jars = ctx.attr.dep[JavaInfo].source_jars)]",
"my_rule = rule(_impl, attrs = { 'dep' : attr.label() })");
scratch.file(
"foo/BUILD",
"load(':extension.bzl', 'my_rule')",
"java_library(name = 'my_java_lib', srcs = ['java/A.java'])",
"my_rule(name = 'my_skylark_rule', dep = ':my_java_lib')");
assertNoEvents();
ConfiguredTarget myRuleTarget = getConfiguredTarget("//foo:my_skylark_rule");
Info info = myRuleTarget.get(
new SkylarkKey(Label.parseAbsolute("//foo:extension.bzl"), "result"));
@SuppressWarnings("unchecked") SkylarkList<Artifact> sourceJars =
(SkylarkList<Artifact>) (info.getValue("source_jars"));
assertThat(prettyJarNames(sourceJars)).containsExactly("foo/libmy_java_lib-src.jar");
}

@Test
public void strictDepsEnabled() throws Exception {
scratch.file(
Expand Down

0 comments on commit fc06a75

Please sign in to comment.