Skip to content

Commit

Permalink
Minimal support for compiling module-infos
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 182461095
  • Loading branch information
cushon authored and Copybara-Service committed Jan 19, 2018
1 parent 80edfd3 commit 3ac310e
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.google.devtools.build.buildjar.javac;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -170,14 +172,35 @@ static List<String> processPluginArgs(
private static void setLocations(JavacFileManager fileManager, BlazeJavacArguments arguments) {
try {
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, arguments.classPath());
// modular dependencies must be on the module path, not the classpath
fileManager.setLocationFromPaths(
StandardLocation.locationFor("MODULE_PATH"), arguments.classPath());

fileManager.setLocationFromPaths(
StandardLocation.CLASS_OUTPUT, ImmutableList.of(arguments.classOutput()));
if (arguments.nativeHeaderOutput() != null) {
fileManager.setLocationFromPaths(
StandardLocation.NATIVE_HEADER_OUTPUT,
ImmutableList.of(arguments.nativeHeaderOutput()));
}
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, arguments.sourcePath());

ImmutableList<Path> sourcePath = arguments.sourcePath();
if (sourcePath.isEmpty()) {
// javac expects a module-info-relative source path to be set when compiling modules,
// otherwise it reports an error:
// "file should be on source path, or on patch path for module"
ImmutableList<Path> moduleInfos =
arguments
.sourceFiles()
.stream()
.filter(f -> f.getFileName().toString().equals("module-info.java"))
.collect(toImmutableList());
if (moduleInfos.size() == 1) {
sourcePath = ImmutableList.of(getOnlyElement(moduleInfos).getParent());
}
}
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcePath);

// TODO(cushon): require an explicit bootclasspath
Collection<Path> bootClassPath = arguments.bootClassPath();
if (!bootClassPath.isEmpty()) {
Expand Down

0 comments on commit 3ac310e

Please sign in to comment.