Skip to content

Commit

Permalink
Use @arguments file for running java as part of native-image on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
quintesse committed May 8, 2020
1 parent 7965307 commit 0b18550
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class NativeImage {
private static final String DEFAULT_GENERATOR_9PLUS_SUFFIX = "$JDK9Plus";
private static final String CUSTOM_SYSTEM_CLASS_LOADER = NativeImageSystemClassLoader.class.getCanonicalName();

private static final int WINDOWS_MAX_COMMAND_LENGTH = 8192;

static final boolean IS_AOT = Boolean.getBoolean("com.oracle.graalvm.isaot");

static final String platform = getPlatform();
Expand Down Expand Up @@ -1175,8 +1177,7 @@ protected static List<String> createImageBuilderArgs(LinkedHashSet<String> image

protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> bcp, LinkedHashSet<Path> cp, LinkedHashSet<String> imageArgs, LinkedHashSet<Path> imagecp) {
/* Construct ProcessBuilder command from final arguments */
ProcessBuilder pb = new ProcessBuilder();
List<String> command = pb.command();
List<String> command = new ArrayList<>();
command.add(canonicalize(config.getJavaExecutable()).toString());
command.addAll(javaArgs);
if (!bcp.isEmpty()) {
Expand All @@ -1203,11 +1204,30 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> bcp, LinkedH
}

int exitStatus = 1;
File argsFile = null;
try {
if (OS.getCurrent() == OS.WINDOWS) {
int totalLength = command.stream().mapToInt(s -> s.length() + 1).sum();
if (totalLength >= WINDOWS_MAX_COMMAND_LENGTH) {
argsFile = File.createTempFile("native-image", "args");
argsFile.deleteOnExit();
Files.write(argsFile.toPath(), (Iterable<String>)command.stream().skip(1)::iterator);
List<String> atCommand = new ArrayList<>();
atCommand.add(command.get(0));
atCommand.add("@" + argsFile);
command = atCommand;
}
}
ProcessBuilder pb = new ProcessBuilder();
pb.command(command);
Process p = pb.inheritIO().start();
exitStatus = p.waitFor();
} catch (IOException | InterruptedException e) {
throw showError(e.getMessage());
} finally {
if (argsFile != null) {
argsFile.delete();
}
}
return exitStatus;
}
Expand Down

0 comments on commit 0b18550

Please sign in to comment.