Skip to content

Commit

Permalink
Allow path to ct.sym to be specified via a system property
Browse files Browse the repository at this point in the history
When turbine is compiled into a native image, no JAVA_HOME will be available at runtime and the `java.home` system property won't be set. To still provide support for `--release` in that situation, the new `turbine.ctSymPath` system property can be set to give turbine the required access to `ct.sym`.

Work towards bazelbuild/stardoc#195 (comment)

Fixes #296

FUTURE_COPYBARA_INTEGRATE_REVIEW=#296 from fmeum:ctsym b74452b
PiperOrigin-RevId: 584409250
  • Loading branch information
fmeum authored and Javac Team committed Nov 21, 2023
1 parent 33ed406 commit 6813ae6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions java/com/google/turbine/binder/CtSymClassBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ public final class CtSymClassBinder {
private static final int FEATURE_VERSION = Runtime.version().feature();

public static @Nullable ClassPath bind(int version) throws IOException {
String javaHome = JAVA_HOME.value();
requireNonNull(javaHome, "attempted to use --release, but JAVA_HOME is not set");
Path ctSym = Paths.get(javaHome).resolve("lib/ct.sym");
if (!Files.exists(ctSym)) {
throw new IllegalStateException("lib/ct.sym does not exist in " + javaHome);
Path ctSym;
String explicitCtSymPath = System.getProperty("turbine.ctSymPath");
if (explicitCtSymPath == null) {
String javaHome = JAVA_HOME.value();
requireNonNull(javaHome, "attempted to use --release, but JAVA_HOME is not set");
ctSym = Paths.get(javaHome).resolve("lib/ct.sym");
if (!Files.exists(ctSym)) {
throw new IllegalStateException("lib/ct.sym does not exist in " + javaHome);
}
} else {
ctSym = Paths.get(explicitCtSymPath);
if (!Files.exists(ctSym)) {
throw new IllegalStateException("ct.sym does not exist at " + ctSym);
}
}
Map<ClassSymbol, BytecodeBoundClass> map = new HashMap<>();
Map<ModuleSymbol, ModuleInfo> modules = new HashMap<>();
Expand Down

0 comments on commit 6813ae6

Please sign in to comment.