From ecb4237d18e873cb8d66fcbc608c8a655cc09c7d Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Thu, 23 Nov 2023 12:35:26 +0200 Subject: [PATCH] WIP: Support custom mandrel versions passed through a property Not working! --- .../quarkus/deployment/pkg/NativeConfig.java | 6 +++++ .../pkg/steps/NativeImageBuildRunner.java | 26 ++++++++++++------- .../pkg/steps/NativeImageBuildStep.java | 2 +- .../deployment/pkg/TestNativeConfig.java | 5 ++++ .../deployment/FunctionZipProcessor.java | 6 +++-- .../quarkus/awt/deployment/AwtProcessor.java | 11 +++++--- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java index c973f8a449a91..ea58275e988a4 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java @@ -332,6 +332,12 @@ default String getEffectiveImage() { @WithDefault("false") boolean reuseExisting(); + /** + * Explicitly set GraalVM version. + * This is usefull when testing a Mandrel/Graal build that is not yet supported. + */ + Optional mandrelVersion(); + /** * Build time configuration options for resources inclusion in the native executable. */ diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildRunner.java index 899cf9c280a01..2a871a767d128 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildRunner.java @@ -15,6 +15,7 @@ import org.apache.commons.lang3.SystemUtils; import org.jboss.logging.Logger; +import io.quarkus.deployment.pkg.NativeConfig; import io.quarkus.deployment.util.ProcessUtil; public abstract class NativeImageBuildRunner { @@ -23,18 +24,23 @@ public abstract class NativeImageBuildRunner { private static GraalVM.Version graalVMVersion = null; - public GraalVM.Version getGraalVMVersion() { + public GraalVM.Version getGraalVMVersion(NativeConfig nativeConfig) { if (graalVMVersion == null) { try { - final String[] versionCommand = getGraalVMVersionCommand(Collections.singletonList("--version")); - log.debugf(String.join(" ", versionCommand).replace("$", "\\$")); - final Process versionProcess = new ProcessBuilder(versionCommand) - .redirectErrorStream(true) - .start(); - versionProcess.waitFor(); - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(versionProcess.getInputStream(), StandardCharsets.UTF_8))) { - graalVMVersion = GraalVM.Version.of(reader.lines()); + if (nativeConfig.mandrelVersion().isPresent()) { + String version = nativeConfig.mandrelVersion().get(); + graalVMVersion = new GraalVM.Version(version, version, GraalVM.Distribution.MANDREL); + } else { + final String[] versionCommand = getGraalVMVersionCommand(Collections.singletonList("--version")); + log.debugf(String.join(" ", versionCommand).replace("$", "\\$")); + final Process versionProcess = new ProcessBuilder(versionCommand) + .redirectErrorStream(true) + .start(); + versionProcess.waitFor(); + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(versionProcess.getInputStream(), StandardCharsets.UTF_8))) { + graalVMVersion = GraalVM.Version.of(reader.lines()); + } } } catch (Exception e) { throw new RuntimeException("Failed to get GraalVM version", e); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 33027514c089d..0f0d71b165037 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -214,7 +214,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon NativeImageBuildRunner buildRunner = nativeImageRunner.getBuildRunner(); buildRunner.setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent()); - final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion(); + final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion(nativeConfig); checkGraalVMVersion(graalVMVersion); try { diff --git a/core/deployment/src/test/java/io/quarkus/deployment/pkg/TestNativeConfig.java b/core/deployment/src/test/java/io/quarkus/deployment/pkg/TestNativeConfig.java index 900acdcef123c..8f6f97a4139b8 100644 --- a/core/deployment/src/test/java/io/quarkus/deployment/pkg/TestNativeConfig.java +++ b/core/deployment/src/test/java/io/quarkus/deployment/pkg/TestNativeConfig.java @@ -197,6 +197,11 @@ public boolean reuseExisting() { return false; } + @Override + public Optional mandrelVersion() { + return Optional.empty(); + } + @Override public ResourcesConfig resources() { return null; diff --git a/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java b/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java index 257aaa9e92c91..a7b4f94310ab4 100644 --- a/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java +++ b/extensions/amazon-lambda/common-deployment/src/main/java/io/quarkus/amazon/lambda/deployment/FunctionZipProcessor.java @@ -19,6 +19,7 @@ import io.quarkus.deployment.IsNormal; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.pkg.NativeConfig; import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; import io.quarkus.deployment.pkg.builditem.JarBuildItem; import io.quarkus.deployment.pkg.builditem.LegacyJarRequiredBuildItem; @@ -107,7 +108,8 @@ public void jvmZip(OutputTargetBuildItem target, * @throws Exception */ @BuildStep(onlyIf = { IsNormal.class, NativeBuild.class }) - public void nativeZip(OutputTargetBuildItem target, + public void nativeZip(NativeConfig nativeConfig, + OutputTargetBuildItem target, Optional upxCompressed, // used to ensure that we work with the compressed native binary if compression was enabled BuildProducer artifactResultProducer, NativeImageBuildItem nativeImage, @@ -143,7 +145,7 @@ public void nativeZip(OutputTargetBuildItem target, } addZipEntry(zip, nativeImage.getPath(), executableName, 0755); - final GraalVM.Version graalVMVersion = nativeImageRunner.getBuildRunner().getGraalVMVersion(); + final GraalVM.Version graalVMVersion = nativeImageRunner.getBuildRunner().getGraalVMVersion(nativeConfig); if (graalVMVersion.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) { // See https://github.com/oracle/graal/issues/4921 try (DirectoryStream sharedLibs = Files.newDirectoryStream(nativeImage.getPath().getParent(), diff --git a/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java b/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java index a3b4d06c21221..0c029f987fc85 100644 --- a/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java +++ b/extensions/awt/deployment/src/main/java/io/quarkus/awt/deployment/AwtProcessor.java @@ -21,6 +21,7 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem; import io.quarkus.deployment.builditem.nativeimage.UnsupportedOSBuildItem; +import io.quarkus.deployment.pkg.NativeConfig; import io.quarkus.deployment.pkg.builditem.NativeImageRunnerBuildItem; import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabled; import io.quarkus.deployment.pkg.builditem.ProcessInheritIODisabledBuildItem; @@ -95,7 +96,8 @@ ReflectiveClassBuildItem setupReflectionClassesWithMethods() { } @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) - void setupAWTInit(BuildProducer jc, + void setupAWTInit(NativeConfig nativeConfig, + BuildProducer jc, BuildProducer jm, BuildProducer jf, NativeImageRunnerBuildItem nativeImageRunnerBuildItem, @@ -103,7 +105,7 @@ void setupAWTInit(BuildProducer jc, Optional processInheritIODisabledBuildItem) { nativeImageRunnerBuildItem.getBuildRunner() .setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent()); - final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion(); + final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion(nativeConfig); // Dynamically loading shared objects instead // of baking in static libs: https://github.com/oracle/graal/issues/4921 if (v.compareTo(GraalVM.Version.VERSION_23_0_0) >= 0) { @@ -125,12 +127,13 @@ void setupAWTInit(BuildProducer jc, } @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) - JniRuntimeAccessBuildItem setupJava2DClasses(NativeImageRunnerBuildItem nativeImageRunnerBuildItem, + JniRuntimeAccessBuildItem setupJava2DClasses(NativeConfig nativeConfig, + NativeImageRunnerBuildItem nativeImageRunnerBuildItem, Optional processInheritIODisabled, Optional processInheritIODisabledBuildItem) { nativeImageRunnerBuildItem.getBuildRunner() .setup(processInheritIODisabled.isPresent() || processInheritIODisabledBuildItem.isPresent()); - final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion(); + final GraalVM.Version v = nativeImageRunnerBuildItem.getBuildRunner().getGraalVMVersion(nativeConfig); final List classes = new ArrayList<>(); classes.add("com.sun.imageio.plugins.jpeg.JPEGImageReader"); classes.add("com.sun.imageio.plugins.jpeg.JPEGImageWriter");