aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2018-01-18 16:59:20 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-18 17:01:26 -0800
commit3ac310e3c870cd70cef26354ee34b3708584db84 (patch)
tree576866fc747112891ae131aaed2dcc5be35020b2
parent80edfd343ba993961c29bc49a60cbc06bb79e8c2 (diff)
Minimal support for compiling module-infos
PiperOrigin-RevId: 182461095
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
index 74059d2e4e..dd2a14105d 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
@@ -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;
@@ -170,6 +172,10 @@ public class BlazeJavacMain {
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) {
@@ -177,7 +183,24 @@ public class BlazeJavacMain {
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()) {