Skip to content

Commit 5a8ecb7

Browse files
committed
[GR-69533] Also replace bundle-input paths in output of bundle-builds.
PullRequest: graal/22117
2 parents 019e2ef + 7afba1e commit 5a8ecb7

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.util.function.Function;
4343
import java.util.stream.Collectors;
4444

45-
import jdk.graal.compiler.options.OptionsContainer;
4645
import org.graalvm.collections.EconomicMap;
4746
import org.graalvm.nativeimage.ImageSingletons;
4847
import org.graalvm.nativeimage.hosted.Feature;
@@ -74,6 +73,7 @@
7473
import jdk.graal.compiler.options.OptionDescriptor;
7574
import jdk.graal.compiler.options.OptionDescriptors;
7675
import jdk.graal.compiler.options.OptionStability;
76+
import jdk.graal.compiler.options.OptionsContainer;
7777
import jdk.graal.compiler.options.OptionsParser;
7878

7979
class APIOptionHandler extends NativeImage.OptionHandler<NativeImage> {
@@ -410,7 +410,10 @@ String translateOption(ArgumentQueue argQueue) {
410410
OptionInfo option = null;
411411
boolean whitespaceSeparated = false;
412412
String[] optionNameAndOptionValue = null;
413-
OptionOrigin argumentOrigin = OptionOrigin.from(argQueue.argumentOrigin);
413+
String argumentOriginString = OptionOrigin.from(argQueue.argumentOrigin).toString();
414+
if (nativeImage.useBundle()) {
415+
argumentOriginString = nativeImage.bundleSupport.cleanupBuilderOutput(argumentOriginString);
416+
}
414417
found: for (OptionInfo optionInfo : apiOptions.values()) {
415418
for (String variant : optionInfo.variants) {
416419
String optionName;
@@ -437,7 +440,7 @@ String translateOption(ArgumentQueue argQueue) {
437440
argQueue.poll();
438441
String optionValue = argQueue.peek();
439442
if (optionValue == null) {
440-
NativeImage.showError(headArg + " from " + argumentOrigin + " requires option argument");
443+
NativeImage.showError(headArg + " from " + argumentOriginString + " requires option argument");
441444
}
442445
option = optionInfo;
443446
optionNameAndOptionValue = new String[]{headArg, optionValue};
@@ -457,14 +460,14 @@ String translateOption(ArgumentQueue argQueue) {
457460
}
458461
if (option != null) {
459462
if (!option.deprecationWarning.isEmpty()) {
460-
LogUtils.warning("Using a deprecated option " + optionNameAndOptionValue[0] + " from " + argumentOrigin + ". " + option.deprecationWarning);
463+
LogUtils.warning("Using a deprecated option " + optionNameAndOptionValue[0] + " from " + argumentOriginString + ". " + option.deprecationWarning);
461464
}
462465
String builderOption = option.builderOption;
463466
/* If option is in group, defaultValue has different use */
464467
String optionValue = option.group != null ? null : option.defaultValue;
465468
if (optionNameAndOptionValue.length == 2) {
466469
if (option.defaultFinal) {
467-
NativeImage.showError("Passing values to option " + optionNameAndOptionValue[0] + " from " + argumentOrigin + " is not supported.");
470+
NativeImage.showError("Passing values to option " + optionNameAndOptionValue[0] + " from " + argumentOriginString + " is not supported.");
468471
}
469472
optionValue = optionNameAndOptionValue[1];
470473
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ final class BundleSupport {
113113
private static final String CONTAINER_OPTION = "container";
114114
private static final String DOCKERFILE_OPTION = "dockerfile";
115115
static final String BUNDLE_FILE_EXTENSION = ".nib";
116+
static final String BUNDLE_ALIAS = "<BUNDLE>";
116117

117118
ContainerSupport containerSupport;
118119
boolean useContainer;
@@ -604,6 +605,15 @@ Path getExternalOutputDir() {
604605
return bundlePath.resolve(bundleName + '.' + outputDir.getFileName());
605606
}
606607

608+
String cleanupBuilderOutput(String output) {
609+
var transformedOutput = output;
610+
if (bundlePath != null) {
611+
transformedOutput = transformedOutput.replace(outputDir.toString(), getExternalOutputDir().toString());
612+
}
613+
transformedOutput = transformedOutput.replace(rootDir.toString(), BUNDLE_ALIAS);
614+
return transformedOutput;
615+
}
616+
607617
void updateBundleLocation(Path bundleFile, boolean redefine) {
608618
if (redefine) {
609619
bundlePath = null;
@@ -877,7 +887,7 @@ private void loadAndVerify() {
877887
String currentPlatform = bundlePlatform.equals(NativeImage.platform) ? "" : " != '" + NativeImage.platform + "'";
878888
String bundleCreationTimestamp = properties.getOrDefault(PROPERTY_KEY_BUNDLE_FILE_CREATION_TIMESTAMP, "");
879889
nativeImage.showNewline();
880-
nativeImage.showMessage("%sLoaded Bundle from %s", BUNDLE_INFO_MESSAGE_PREFIX, bundleFileName);
890+
nativeImage.showMessage("%sLoaded Bundle from %s referred to as %s from here on.", BUNDLE_INFO_MESSAGE_PREFIX, bundleFileName, BUNDLE_ALIAS);
881891
nativeImage.showMessage("%sBundle created at '%s'", BUNDLE_INFO_MESSAGE_PREFIX, ArchiveSupport.parseTimestamp(bundleCreationTimestamp));
882892
nativeImage.showMessage("%sUsing version: '%s'%s (vendor '%s'%s) on platform: '%s'%s", BUNDLE_INFO_MESSAGE_PREFIX,
883893
bundleVersion, currentVersion,

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,11 +1910,8 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
19101910
}
19111911
p = pb.start();
19121912
if (useBundle()) {
1913-
var internalOutputDir = bundleSupport.outputDir.toString();
1914-
var externalOutputDir = bundleSupport.getExternalOutputDir().toString();
1915-
Function<String, String> filter = line -> line.replace(internalOutputDir, externalOutputDir);
1916-
ProcessOutputTransformer.attach(p.getInputStream(), filter, System.out);
1917-
ProcessOutputTransformer.attach(p.getErrorStream(), filter, System.err);
1913+
ProcessOutputTransformer.attach(p.getInputStream(), bundleSupport::cleanupBuilderOutput, System.out);
1914+
ProcessOutputTransformer.attach(p.getErrorStream(), bundleSupport::cleanupBuilderOutput, System.err);
19181915
}
19191916
imageBuilderPid = p.pid();
19201917
return p.waitFor();
@@ -1927,16 +1924,16 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
19271924
}
19281925
}
19291926

1930-
private record ProcessOutputTransformer(InputStream in, Function<String, String> filter, PrintStream out) implements Runnable {
1927+
private record ProcessOutputTransformer(InputStream in, Function<String, String> mapper, PrintStream out) implements Runnable {
19311928

1932-
static void attach(InputStream in, Function<String, String> filter, PrintStream out) {
1933-
Thread.ofVirtual().start(new ProcessOutputTransformer(in, filter, out));
1929+
static void attach(InputStream in, Function<String, String> mapper, PrintStream out) {
1930+
Thread.ofVirtual().start(new ProcessOutputTransformer(in, mapper, out));
19341931
}
19351932

19361933
@Override
19371934
public void run() {
19381935
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
1939-
reader.lines().map(filter).forEach(out::println);
1936+
reader.lines().map(mapper).forEach(out::println);
19401937
} catch (IOException e) {
19411938
throw showError("Unable to process stdout/stderr of image builder process", e);
19421939
}

0 commit comments

Comments
 (0)