Skip to content

Commit

Permalink
build succeeds, when reusing an artifact with enabled compression
Browse files Browse the repository at this point in the history
  • Loading branch information
gcw-it committed Jul 16, 2024
1 parent 0109749 commit c7e122f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
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.info("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

0 comments on commit c7e122f

Please sign in to comment.