Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Succeeds, when Reusing an Artifact with Enabled Compression #41930

Merged
merged 1 commit into from
Jul 17, 2024
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 @@ -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() {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ public void compress(NativeConfig nativeConfig, NativeImageRunnerBuildItem nativ
NativeImageBuildItem image,
BuildProducer<UpxCompressedBuildItem> upxCompressedProducer,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {

if (nativeConfig.compression().level().isEmpty()) {
log.debug("UPX compression disabled");
return;
}
if (image.isReused()) {
log.debug("Native executable reused: skipping compression");
return;
}

String effectiveBuilderImage = nativeConfig.builderImage().getEffectiveImage();
Optional<File> upxPathFromSystem = getUpxFromSystem();
Expand All @@ -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");
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading