Skip to content

Commit

Permalink
Add exports param to java_common.compile.
Browse files Browse the repository at this point in the history
This is a step forward to having the same semantics for java_library and custom Skylark rules that use java_common.compile, facilitating the migration from native Java rules to Skylark.

Progress on bazelbuild#2614

PiperOrigin-RevId: 160513771
  • Loading branch information
iirina authored and hlopko committed Jun 29, 2017
1 parent 61ecd28 commit 133a3a0
Show file tree
Hide file tree
Showing 3 changed files with 387 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class JavaLibraryHelper {
* Contains all the dependencies; these are treated as both compile-time and runtime dependencies.
*/
private final List<JavaCompilationArgsProvider> deps = new ArrayList<>();
private final List<JavaCompilationArgsProvider> exports = new ArrayList<>();
private ImmutableList<String> javacOpts = ImmutableList.of();
private ImmutableList<Artifact> sourcePathEntries = ImmutableList.of();
private StrictDepsMode strictDepsMode = StrictDepsMode.OFF;
Expand Down Expand Up @@ -113,6 +114,11 @@ public JavaLibraryHelper addAllDeps(
return this;
}

public JavaLibraryHelper addAllExports(Iterable<JavaCompilationArgsProvider> providers) {
Iterables.addAll(exports, providers);
return this;
}

/**
* Sets the compiler options.
*/
Expand Down Expand Up @@ -200,7 +206,10 @@ public JavaCompilationArtifacts build(
*/
public JavaCompilationArgsProvider buildCompilationArgsProvider(
JavaCompilationArtifacts artifacts, boolean isReportedAsStrict) {
JavaCompilationArgs directArgs = JavaCompilationArgs.builder().merge(artifacts).build();
JavaCompilationArgs directArgs = JavaCompilationArgs.builder()
.merge(artifacts)
.addTransitiveDependencies(exports, true /* recursive */)
.build();
JavaCompilationArgs transitiveArgs =
JavaCompilationArgs.builder()
.addTransitiveArgs(directArgs, BOTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ private static NestedSet<Artifact> asArtifactNestedSet(Object o) throws EvalExce
defaultValue = "[]",
doc = "A list of dependencies. Optional."
),
@Param(
name = "exports",
positional = false,
named = true,
type = SkylarkList.class,
generic1 = JavaProvider.class,
defaultValue = "[]",
doc = "A list of exports. Optional."
),
@Param(
name = "strict_deps",
defaultValue = "'ERROR'",
Expand Down Expand Up @@ -231,6 +240,7 @@ public JavaProvider createJavaCompileAction(
Artifact outputJar,
SkylarkList<String> javacOpts,
SkylarkList<JavaProvider> deps,
SkylarkList<JavaProvider> exports,
String strictDepsMode,
ConfiguredTarget javaToolchain,
ConfiguredTarget hostJavabase,
Expand All @@ -246,9 +256,12 @@ public JavaProvider createJavaCompileAction(
.setSourcePathEntries(sourcepathEntries)
.setJavacOpts(javacOpts);

List<JavaCompilationArgsProvider> compilationArgsProviders =
List<JavaCompilationArgsProvider> depsCompilationArgsProviders =
JavaProvider.fetchProvidersFromList(deps, JavaCompilationArgsProvider.class);
helper.addAllDeps(compilationArgsProviders);
List<JavaCompilationArgsProvider> exportsCompilationArgsProviders =
JavaProvider.fetchProvidersFromList(exports, JavaCompilationArgsProvider.class);
helper.addAllDeps(depsCompilationArgsProviders);
helper.addAllExports(exportsCompilationArgsProviders);
helper.setCompilationStrictDepsMode(getStrictDepsMode(strictDepsMode));
MiddlemanProvider hostJavabaseProvider = hostJavabase.getProvider(MiddlemanProvider.class);

Expand Down
Loading

0 comments on commit 133a3a0

Please sign in to comment.