Skip to content

Commit

Permalink
Fix toolchain_java9 on --host_javabase=<jdk9> after 7eb9ea1
Browse files Browse the repository at this point in the history
See bazelbuild#6127

PiperOrigin-RevId: 212600423
  • Loading branch information
cushon authored and aehlig committed Oct 15, 2018
1 parent 35a2493 commit 047adaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions tools/jdk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ RELEASES = (8, 9)
set -eu
TMPDIR=$$(mktemp -d -t tmp.XXXXXXXX)
$(JAVABASE)/bin/javac -source 8 -target 8 \
-Xlint:-options \
-cp $(JAVABASE)/lib/tools.jar \
-d $$TMPDIR $<
$(JAVA) -XX:+IgnoreUnrecognizedVMOptions \
Expand Down
24 changes: 19 additions & 5 deletions tools/jdk/DumpPlatformClassPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ public static void main(String[] args) throws Exception {
StandardJavaFileManager fileManager =
(StandardJavaFileManager) context.get(JavaFileManager.class);

if (isJdk9OrEarlier()) {
int majorVersion = majorVersion();
if (majorVersion == 9 && release == 8) {
// Work-around: when running on a JDK 9 host_javabase with --release 8, the ct.sym
// handling isn't compatible with the FileManager#list code path in the branch below.
for (Path path : getLocationAsPaths(fileManager)) {
Files.walkFileTree(
path,
Expand Down Expand Up @@ -190,6 +193,12 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
});
}

if (!entries.containsKey("java/lang/Object.class")) {
throw new AssertionError(
"\nCould not find java.lang.Object on bootclasspath; something has gone terribly wrong.\n"
+ "Please file a bug: https://github.com/bazelbuild/bazel/issues");
}

try (OutputStream os = Files.newOutputStream(output);
BufferedOutputStream bos = new BufferedOutputStream(os, 65536);
JarOutputStream jos = new JarOutputStream(bos)) {
Expand Down Expand Up @@ -247,14 +256,19 @@ private static Iterable<Path> getLocationAsPaths(StandardJavaFileManager fileMan
}
}

static boolean isJdk9OrEarlier() {
static int majorVersion() {
try {
Method versionMethod = Runtime.class.getMethod("version");
Object version = versionMethod.invoke(null);
int majorVersion = (int) version.getClass().getMethod("major").invoke(version);
return majorVersion <= 9;
return (int) version.getClass().getMethod("major").invoke(version);
} catch (ReflectiveOperationException e) {
return true;
// Runtime.version() isn't available on JDK 8; continue below
}
int version = (int) Double.parseDouble(System.getProperty("java.class.version"));
if (49 <= version && version <= 52) {
return version - (49 - 5);
}
throw new IllegalStateException(
"Unknown Java version: " + System.getProperty("java.specification.version"));
}
}

0 comments on commit 047adaf

Please sign in to comment.