From c7e122f21f8aa0d712ed183783da098443c7b668 Mon Sep 17 00:00:00 2001 From: "Gunther C. Wenda" Date: Tue, 16 Jul 2024 15:56:06 +0200 Subject: [PATCH] build succeeds, when reusing an artifact with enabled compression --- .../pkg/builditem/NativeImageBuildItem.java | 8 +++++++- .../pkg/steps/NativeImageBuildStep.java | 6 ++++-- .../pkg/steps/UpxCompressionBuildStep.java | 17 +++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/NativeImageBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/NativeImageBuildItem.java index 8a140099907ff5..24c78b3f2c2784 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/NativeImageBuildItem.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/builditem/NativeImageBuildItem.java @@ -10,10 +10,12 @@ public final class NativeImageBuildItem extends SimpleBuildItem { private final Path path; private final GraalVMVersion graalVMVersion; + private final boolean reused; - public NativeImageBuildItem(Path path, GraalVMVersion graalVMVersion) { + public NativeImageBuildItem(Path path, GraalVMVersion graalVMVersion, boolean reused) { this.path = path; this.graalVMVersion = graalVMVersion; + this.reused = reused; } public Path getPath() { @@ -24,6 +26,10 @@ public GraalVMVersion getGraalVMInfo() { return graalVMVersion; } + public boolean isReused() { + return reused; + } + public static class GraalVMVersion { private final String fullVersion; private final String version; 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 59cf46bf025ab0..ca691712a5d4e4 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 @@ -209,7 +209,8 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon if (nativeConfig.reuseExisting()) { if (Files.exists(finalExecutablePath)) { return new NativeImageBuildItem(finalExecutablePath, - NativeImageBuildItem.GraalVMVersion.unknown()); + NativeImageBuildItem.GraalVMVersion.unknown(), + true); } } @@ -297,7 +298,8 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, LocalesBuildTimeCon new NativeImageBuildItem.GraalVMVersion(graalVMVersion.fullVersion, graalVMVersion.getVersionAsString(), graalVMVersion.javaVersion.feature(), - graalVMVersion.distribution.name())); + graalVMVersion.distribution.name()), + false); } catch (ImageGenerationFailureException e) { throw e; } catch (Exception e) { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java index 18807695b95290..19c5bb43a8ea35 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java @@ -40,10 +40,15 @@ public void compress(NativeConfig nativeConfig, NativeImageRunnerBuildItem nativ NativeImageBuildItem image, BuildProducer upxCompressedProducer, BuildProducer artifactResultProducer) { + if (nativeConfig.compression().level().isEmpty()) { log.debug("UPX compression disabled"); return; } + if (image.isReused()) { + log.info("Native executable reused: skipping compression"); + return; + } String effectiveBuilderImage = nativeConfig.builderImage().getEffectiveImage(); Optional upxPathFromSystem = getUpxFromSystem(); @@ -53,16 +58,16 @@ public void compress(NativeConfig nativeConfig, NativeImageRunnerBuildItem nativ throw new IllegalStateException("Unable to compress the native executable"); } } else if (nativeConfig.remoteContainerBuild()) { - log.errorf("Compression of native executables is not yet implemented for remote container builds."); + log.error("Compression of native executables is not yet implemented for remote container builds."); throw new IllegalStateException( "Unable to compress the native executable: Compression of native executables is not yet supported for remote container builds"); } else if (nativeImageRunner.isContainerBuild()) { - log.infof("Running UPX from a container using the builder image: " + effectiveBuilderImage); + log.info("Running UPX from a container using the builder image: " + effectiveBuilderImage); if (!runUpxInContainer(image, nativeConfig, effectiveBuilderImage)) { throw new IllegalStateException("Unable to compress the native executable"); } } else { - log.errorf("Unable to compress the native executable. Either install `upx` from https://upx.github.io/" + + log.error("Unable to compress the native executable. Either install `upx` from https://upx.github.io/" + " on your machine, or enable in-container build using `-Dquarkus.native.container-build=true`."); throw new IllegalStateException("Unable to compress the native executable: `upx` not available"); } @@ -90,12 +95,12 @@ private boolean runUpxFromHost(File upx, File executable, NativeConfig nativeCon ProcessUtil.streamOutputToSysOut(process); final int exitCode = process.waitFor(); if (exitCode != 0) { - log.errorf("Command: " + String.join(" ", args) + " failed with exit code " + exitCode); + log.error("Command: " + String.join(" ", args) + " failed with exit code " + exitCode); return false; } return true; } catch (Exception e) { - log.errorf("Command: " + String.join(" ", args) + " failed", e); + log.error("Command: " + String.join(" ", args) + " failed", e); return false; } finally { if (process != null) { @@ -169,7 +174,7 @@ private boolean runUpxInContainer(NativeImageBuildItem nativeImage, NativeConfig } return true; } catch (Exception e) { - log.errorf("Command: " + String.join(" ", commandLine) + " failed", e); + log.error("Command: " + String.join(" ", commandLine) + " failed", e); return false; } finally { if (process != null) {