Skip to content

Commit 23a7a80

Browse files
committed
Ensure users see final bundle output directories in build-output
1 parent 312c2b4 commit 23a7a80

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/BundleSupport.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ void complete() {
583583
}
584584

585585
if (writeOutput) {
586-
Path externalOutputDir = bundlePath.resolve(bundleName + "." + outputDir.getFileName());
586+
Path externalOutputDir = getExternalOutputDir();
587587
copyFiles(outputDir, externalOutputDir, true);
588588
nativeImage.showMessage(BUNDLE_INFO_MESSAGE_PREFIX + "Bundle build output written to " + externalOutputDir);
589589
}
@@ -598,6 +598,12 @@ void complete() {
598598
}
599599
}
600600

601+
Path getExternalOutputDir() {
602+
Objects.requireNonNull(bundlePath);
603+
Objects.requireNonNull(bundleName);
604+
return bundlePath.resolve(bundleName + '.' + outputDir.getFileName());
605+
}
606+
601607
void updateBundleLocation(Path bundleFile, boolean redefine) {
602608
if (redefine) {
603609
bundlePath = null;

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.IOException;
3232
import java.io.InputStream;
3333
import java.io.InputStreamReader;
34+
import java.io.PrintStream;
3435
import java.lang.module.FindException;
3536
import java.lang.module.ModuleDescriptor;
3637
import java.lang.module.ModuleFinder;
@@ -83,6 +84,7 @@
8384
import com.oracle.svm.common.option.CommonOptions;
8485
import com.oracle.svm.core.FallbackExecutor;
8586
import com.oracle.svm.core.FallbackExecutor.Options;
87+
import com.oracle.svm.core.JavaVersionUtil;
8688
import com.oracle.svm.core.NativeImageClassLoaderOptions;
8789
import com.oracle.svm.core.OS;
8890
import com.oracle.svm.core.SharedConstants;
@@ -111,7 +113,6 @@
111113
import com.oracle.svm.util.StringUtil;
112114

113115
import jdk.graal.compiler.options.OptionKey;
114-
import com.oracle.svm.core.JavaVersionUtil;
115116
import jdk.internal.jimage.ImageReader;
116117

117118
public class NativeImage {
@@ -1865,7 +1866,17 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
18651866

18661867
Process p = null;
18671868
try {
1868-
p = pb.inheritIO().start();
1869+
if (!useBundle()) {
1870+
pb.inheritIO();
1871+
}
1872+
p = pb.start();
1873+
if (useBundle()) {
1874+
var internalOutputDir = bundleSupport.outputDir.toString();
1875+
var externalOutputDir = bundleSupport.getExternalOutputDir().toString();
1876+
Function<String, String> filter = line -> line.replace(internalOutputDir, externalOutputDir);
1877+
ProcessOutputTransformer.attach(p.getInputStream(), filter, System.out);
1878+
ProcessOutputTransformer.attach(p.getErrorStream(), filter, System.err);
1879+
}
18691880
imageBuilderPid = p.pid();
18701881
return p.waitFor();
18711882
} catch (IOException | InterruptedException e) {
@@ -1877,6 +1888,22 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
18771888
}
18781889
}
18791890

1891+
private record ProcessOutputTransformer(InputStream in, Function<String, String> filter, PrintStream out) implements Runnable {
1892+
1893+
static void attach(InputStream in, Function<String, String> filter, PrintStream out) {
1894+
Thread.ofVirtual().start(new ProcessOutputTransformer(in, filter, out));
1895+
}
1896+
1897+
@Override
1898+
public void run() {
1899+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
1900+
reader.lines().map(filter).forEach(out::println);
1901+
} catch (IOException e) {
1902+
throw showError("Unable to process stdout/stderr of image builder process", e);
1903+
}
1904+
}
1905+
}
1906+
18801907
/**
18811908
* Creates a file with name 'fileName' in the {@link NativeImage#driverTempDir temporary
18821909
* directory} and returns the path to the newly created file. Note: the file will be deleted if

0 commit comments

Comments
 (0)