Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import jdk.graal.compiler.options.OptionsContainer;
import org.graalvm.collections.EconomicMap;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;
Expand Down Expand Up @@ -74,6 +73,7 @@
import jdk.graal.compiler.options.OptionDescriptor;
import jdk.graal.compiler.options.OptionDescriptors;
import jdk.graal.compiler.options.OptionStability;
import jdk.graal.compiler.options.OptionsContainer;
import jdk.graal.compiler.options.OptionsParser;

class APIOptionHandler extends NativeImage.OptionHandler<NativeImage> {
Expand Down Expand Up @@ -410,7 +410,10 @@ String translateOption(ArgumentQueue argQueue) {
OptionInfo option = null;
boolean whitespaceSeparated = false;
String[] optionNameAndOptionValue = null;
OptionOrigin argumentOrigin = OptionOrigin.from(argQueue.argumentOrigin);
String argumentOriginString = OptionOrigin.from(argQueue.argumentOrigin).toString();
if (nativeImage.useBundle()) {
argumentOriginString = nativeImage.bundleSupport.cleanupBuilderOutput(argumentOriginString);
}
found: for (OptionInfo optionInfo : apiOptions.values()) {
for (String variant : optionInfo.variants) {
String optionName;
Expand All @@ -437,7 +440,7 @@ String translateOption(ArgumentQueue argQueue) {
argQueue.poll();
String optionValue = argQueue.peek();
if (optionValue == null) {
NativeImage.showError(headArg + " from " + argumentOrigin + " requires option argument");
NativeImage.showError(headArg + " from " + argumentOriginString + " requires option argument");
}
option = optionInfo;
optionNameAndOptionValue = new String[]{headArg, optionValue};
Expand All @@ -457,14 +460,14 @@ String translateOption(ArgumentQueue argQueue) {
}
if (option != null) {
if (!option.deprecationWarning.isEmpty()) {
LogUtils.warning("Using a deprecated option " + optionNameAndOptionValue[0] + " from " + argumentOrigin + ". " + option.deprecationWarning);
LogUtils.warning("Using a deprecated option " + optionNameAndOptionValue[0] + " from " + argumentOriginString + ". " + option.deprecationWarning);
}
String builderOption = option.builderOption;
/* If option is in group, defaultValue has different use */
String optionValue = option.group != null ? null : option.defaultValue;
if (optionNameAndOptionValue.length == 2) {
if (option.defaultFinal) {
NativeImage.showError("Passing values to option " + optionNameAndOptionValue[0] + " from " + argumentOrigin + " is not supported.");
NativeImage.showError("Passing values to option " + optionNameAndOptionValue[0] + " from " + argumentOriginString + " is not supported.");
}
optionValue = optionNameAndOptionValue[1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ final class BundleSupport {
private static final String CONTAINER_OPTION = "container";
private static final String DOCKERFILE_OPTION = "dockerfile";
static final String BUNDLE_FILE_EXTENSION = ".nib";
static final String BUNDLE_ALIAS = "<BUNDLE>";

ContainerSupport containerSupport;
boolean useContainer;
Expand Down Expand Up @@ -604,6 +605,15 @@ Path getExternalOutputDir() {
return bundlePath.resolve(bundleName + '.' + outputDir.getFileName());
}

String cleanupBuilderOutput(String output) {
var transformedOutput = output;
if (bundlePath != null) {
transformedOutput = transformedOutput.replace(outputDir.toString(), getExternalOutputDir().toString());
}
transformedOutput = transformedOutput.replace(rootDir.toString(), BUNDLE_ALIAS);
return transformedOutput;
}

void updateBundleLocation(Path bundleFile, boolean redefine) {
if (redefine) {
bundlePath = null;
Expand Down Expand Up @@ -877,7 +887,7 @@ private void loadAndVerify() {
String currentPlatform = bundlePlatform.equals(NativeImage.platform) ? "" : " != '" + NativeImage.platform + "'";
String bundleCreationTimestamp = properties.getOrDefault(PROPERTY_KEY_BUNDLE_FILE_CREATION_TIMESTAMP, "");
nativeImage.showNewline();
nativeImage.showMessage("%sLoaded Bundle from %s", BUNDLE_INFO_MESSAGE_PREFIX, bundleFileName);
nativeImage.showMessage("%sLoaded Bundle from %s referred to as %s from here on.", BUNDLE_INFO_MESSAGE_PREFIX, bundleFileName, BUNDLE_ALIAS);
nativeImage.showMessage("%sBundle created at '%s'", BUNDLE_INFO_MESSAGE_PREFIX, ArchiveSupport.parseTimestamp(bundleCreationTimestamp));
nativeImage.showMessage("%sUsing version: '%s'%s (vendor '%s'%s) on platform: '%s'%s", BUNDLE_INFO_MESSAGE_PREFIX,
bundleVersion, currentVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1908,11 +1908,8 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
}
p = pb.start();
if (useBundle()) {
var internalOutputDir = bundleSupport.outputDir.toString();
var externalOutputDir = bundleSupport.getExternalOutputDir().toString();
Function<String, String> filter = line -> line.replace(internalOutputDir, externalOutputDir);
ProcessOutputTransformer.attach(p.getInputStream(), filter, System.out);
ProcessOutputTransformer.attach(p.getErrorStream(), filter, System.err);
ProcessOutputTransformer.attach(p.getInputStream(), bundleSupport::cleanupBuilderOutput, System.out);
ProcessOutputTransformer.attach(p.getErrorStream(), bundleSupport::cleanupBuilderOutput, System.err);
}
imageBuilderPid = p.pid();
return p.waitFor();
Expand All @@ -1925,16 +1922,16 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
}
}

private record ProcessOutputTransformer(InputStream in, Function<String, String> filter, PrintStream out) implements Runnable {
private record ProcessOutputTransformer(InputStream in, Function<String, String> mapper, PrintStream out) implements Runnable {

static void attach(InputStream in, Function<String, String> filter, PrintStream out) {
Thread.ofVirtual().start(new ProcessOutputTransformer(in, filter, out));
static void attach(InputStream in, Function<String, String> mapper, PrintStream out) {
Thread.ofVirtual().start(new ProcessOutputTransformer(in, mapper, out));
}

@Override
public void run() {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
reader.lines().map(filter).forEach(out::println);
reader.lines().map(mapper).forEach(out::println);
} catch (IOException e) {
throw showError("Unable to process stdout/stderr of image builder process", e);
}
Expand Down