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

Do not fail UPX if compression level is not given #39069

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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 @@ -7,6 +7,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -15,7 +16,6 @@
import org.jboss.logging.Logger;

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.NativeImageBuildItem;
Expand All @@ -34,7 +34,6 @@ public class UpxCompressionBuildStep {
*/
private static final String PATH = "PATH";

@BuildStep(onlyIf = NativeBuild.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmlloyd I assume this was removed by accident?

Asking because of #39699

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, #39702 brings it back

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I believe this must have been an error.

public void compress(NativeConfig nativeConfig, NativeImageRunnerBuildItem nativeImageRunner,
NativeImageBuildItem image,
BuildProducer<UpxCompressedBuildItem> upxCompressedProducer,
Expand Down Expand Up @@ -70,11 +69,13 @@ public void compress(NativeConfig nativeConfig, NativeImageRunnerBuildItem nativ
}

private boolean runUpxFromHost(File upx, File executable, NativeConfig nativeConfig) {
String level = getCompressionLevel(nativeConfig.compression().level().getAsInt());
List<String> extraArgs = nativeConfig.compression().additionalArgs().orElse(Collections.emptyList());
List<String> args = Stream.concat(
Stream.concat(Stream.of(upx.getAbsolutePath(), level), extraArgs.stream()),
List<String> args = Stream.of(
Stream.of(upx.getAbsolutePath()),
nativeConfig.compression().level().stream().mapToObj(this::getCompressionLevel),
extraArgs.stream(),
Stream.of(executable.getAbsolutePath()))
.flatMap(Function.identity())
.collect(Collectors.toList());
log.infof("Executing %s", String.join(" ", args));
final ProcessBuilder processBuilder = new ProcessBuilder(args)
Expand Down Expand Up @@ -104,7 +105,6 @@ private boolean runUpxFromHost(File upx, File executable, NativeConfig nativeCon

private boolean runUpxInContainer(NativeImageBuildItem nativeImage, NativeConfig nativeConfig,
String effectiveBuilderImage) {
String level = getCompressionLevel(nativeConfig.compression().level().getAsInt());
List<String> extraArgs = nativeConfig.compression().additionalArgs().orElse(Collections.emptyList());

List<String> commandLine = new ArrayList<>();
Expand Down Expand Up @@ -140,7 +140,9 @@ private boolean runUpxInContainer(NativeImageBuildItem nativeImage, NativeConfig
volumeOutputPath + ":" + NativeImageBuildStep.CONTAINER_BUILD_VOLUME_PATH + ":z");

commandLine.add(effectiveBuilderImage);
commandLine.add(level);
if (nativeConfig.compression().level().isPresent()) {
commandLine.add(getCompressionLevel(nativeConfig.compression().level().getAsInt()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know you could run without a compression level.

Copy link
Member Author

@dmlloyd dmlloyd Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, "The default compression level is -8 for files smaller than 512 KiB, and -7 otherwise". Since the property is an OptionalInt, I took that to mean that the property is optional, and if not given, the default should be used. So, my assumption is that this was expected to work this way, but I was not able to test it locally.

}
commandLine.addAll(extraArgs);

commandLine.add(nativeImage.getPath().toFile().getName());
Expand Down
Loading