Skip to content

Commit

Permalink
java_common.create_provider now takes depsets )
Browse files Browse the repository at this point in the history
rjars = java_common.create_provider(
    compile_time_jars = depset(),
    runtime_jars = merged_runtime.transitive_runtime_deps,
)

This avoids linearizing the runtime_deps (with the corresponding memory
issues). Must be a JavaProvider for proper interaction with native rules
but cannot just be a simple merge since runtime_deps should not
contribute to compile of the dependent rules.

Note, this will effect a change of the already-released API; however,
function marked as undocumented in an experimental object....

Change-Id: I54542a5d57c75e762b2276e0a1988816901a0def
PiperOrigin-RevId: 155384266
  • Loading branch information
Stephen Twigg authored and kchodorow committed May 9, 2017
1 parent f801f7c commit 05ea028
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public Builder addRuntimeJars(Iterable<Artifact> runtimeJars) {
return this;
}

public Builder addTransitiveRuntimeJars(NestedSet<Artifact> runtimeJars) {
this.runtimeJarsBuilder.addTransitive(runtimeJars);
return this;
}

public Builder addCompileTimeJar(Artifact compileTimeJar) {
this.compileTimeJarsBuilder.add(compileTimeJar);
return this;
Expand All @@ -127,6 +132,11 @@ public Builder addCompileTimeJars(Iterable<Artifact> compileTimeJars) {
return this;
}

public Builder addTransitiveCompileTimeJars(NestedSet<Artifact> compileTimeJars) {
this.compileTimeJarsBuilder.addTransitive(compileTimeJars);
return this;
}

public Builder addInstrumentationMetadata(Artifact instrumentationMetadata) {
this.instrumentationMetadataBuilder.add(instrumentationMetadata);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import java.util.List;

/** A module that contains Skylark utilities for Java support. */
Expand All @@ -55,41 +56,40 @@ public ClassObjectConstructor getJavaProvider() {
}

@SkylarkCallable(
name = "create_provider",
documented = false,
parameters = {
@Param(
name = "compile_time_jars",
positional = false,
named = true,
type = SkylarkList.class,
generic1 = Artifact.class,
defaultValue = "[]"
),
@Param(
name = "runtime_jars",
positional = false,
named = true,
type = SkylarkList.class,
generic1 = Artifact.class,
defaultValue = "[]"
)
}
name = "create_provider",
documented = false,
parameters = {
@Param(
name = "compile_time_jars",
positional = false,
named = true,
type = SkylarkNestedSet.class,
generic1 = Artifact.class,
defaultValue = "[]"
),
@Param(
name = "runtime_jars",
positional = false,
named = true,
type = SkylarkNestedSet.class,
generic1 = Artifact.class,
defaultValue = "[]"
)
}
)
public JavaProvider create(
SkylarkList<Artifact> compileTimeJars,
SkylarkList<Artifact> runtimeJars) {
JavaCompilationArgs javaCompilationArgs = JavaCompilationArgs.builder()
.addCompileTimeJars(compileTimeJars)
.addRuntimeJars(runtimeJars)
.build();
JavaCompilationArgs recursiveJavaCompilationArgs = JavaCompilationArgs.builder()
.addCompileTimeJars(compileTimeJars)
.addRuntimeJars(runtimeJars).build();
JavaProvider javaProvider = JavaProvider.Builder.create().addProvider(
JavaCompilationArgsProvider.class,
JavaCompilationArgsProvider.create(javaCompilationArgs, recursiveJavaCompilationArgs))
.build();
public JavaProvider create(SkylarkNestedSet compileTimeJars, SkylarkNestedSet runtimeJars) {
JavaCompilationArgs javaCompilationArgs =
JavaCompilationArgs.builder()
.addTransitiveRuntimeJars(runtimeJars.getSet(Artifact.class))
.addTransitiveCompileTimeJars(compileTimeJars.getSet(Artifact.class))
.build();

JavaProvider javaProvider =
JavaProvider.Builder.create()
.addProvider(
JavaCompilationArgsProvider.class,
JavaCompilationArgsProvider.create(javaCompilationArgs, javaCompilationArgs))
.build();
return javaProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public void constructJavaProvider() throws Exception {
"foo/extension.bzl",
"def _impl(ctx):",
" my_provider = java_common.create_provider(",
" compile_time_jars = ctx.files.compile_time_jars,",
" runtime_jars = ctx.files.runtime_jars)",
" compile_time_jars = depset(ctx.files.compile_time_jars),",
" runtime_jars = depset(ctx.files.runtime_jars))",
" return [my_provider]",
"my_rule = rule(_impl, ",
" attrs = { ",
Expand Down Expand Up @@ -196,8 +196,8 @@ public void constructJavaProviderWithAnotherJavaProvider() throws Exception {
" transitive_provider = java_common.merge(",
" [dep[java_common.provider] for dep in ctx.attr.deps])",
" my_provider = java_common.create_provider(",
" compile_time_jars = ctx.files.compile_time_jars,",
" runtime_jars = ctx.files.runtime_jars)",
" compile_time_jars = depset(ctx.files.compile_time_jars),",
" runtime_jars = depset(ctx.files.runtime_jars))",
" return [java_common.merge([my_provider, transitive_provider])]",
"my_rule = rule(_impl, ",
" attrs = { ",
Expand Down Expand Up @@ -236,8 +236,8 @@ public void constructJavaProviderJavaLibrary() throws Exception {
"foo/extension.bzl",
"def _impl(ctx):",
" my_provider = java_common.create_provider(",
" compile_time_jars = ctx.files.compile_time_jars,",
" runtime_jars = ctx.files.runtime_jars)",
" compile_time_jars = depset(ctx.files.compile_time_jars),",
" runtime_jars = depset(ctx.files.runtime_jars))",
" return [my_provider]",
"my_rule = rule(_impl, ",
" attrs = { ",
Expand Down

0 comments on commit 05ea028

Please sign in to comment.