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 dfd679c6338f9..93ff637d66473 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 @@ -45,8 +45,8 @@ public void setup(boolean processInheritIODisabled) { public void addShutdownHook(Process buildNativeProcess) { } - public int build(List args, String nativeImageName, String resultingExecutableName, Path outputDir, - boolean debugEnabled, boolean processInheritIODisabled) + public Result build(List args, String nativeImageName, String resultingExecutableName, Path outputDir, + boolean debugSymbolsEnabled, boolean processInheritIODisabled) throws InterruptedException, IOException { preBuild(args); try { @@ -63,22 +63,26 @@ public int build(List args, String nativeImageName, String resultingExec executor.shutdown(); errorReportLatch.await(); int exitCode = process.waitFor(); + boolean objcopyExists = objcopyExists(); if (exitCode != 0) { - return exitCode; + return new Result(exitCode, objcopyExists); } - if (objcopyExists()) { - if (debugEnabled) { + if (objcopyExists) { + if (debugSymbolsEnabled) { splitDebugSymbols(nativeImageName, resultingExecutableName); } else { // Strip debug symbols regardless, because the underlying JDK might contain them objcopy("--strip-debug", resultingExecutableName); } } else { - log.warn("objcopy executable not found in PATH. Debug symbols will not be separated from executable."); - log.warn("That will result in a larger native image with debug symbols embedded in it."); + if (!debugSymbolsEnabled) { + log.warn( + "objcopy executable not found in PATH. Debug symbols will therefore not be separated from executable."); + log.warn("That also means that resulting native image is larger as it embeds the debug symbols."); + } } - return 0; + return new Result(0, objcopyExists); } finally { postBuild(); } @@ -143,4 +147,22 @@ static void runCommand(String[] command, String errorMsg, File workingDirectory) } } } + + static class Result { + private final int exitCode; + private final boolean objcopyExists; + + public Result(int exitCode, boolean objcopyExists) { + this.exitCode = exitCode; + this.objcopyExists = objcopyExists; + } + + public int getExitCode() { + return exitCode; + } + + public boolean isObjcopyExists() { + return objcopyExists; + } + } } 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 3472a0305fafd..1b72ae784b360 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 @@ -198,24 +198,32 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa List nativeImageArgs = commandAndExecutable.args; - int exitCode = buildRunner.build(nativeImageArgs, nativeImageName, resultingExecutableName, outputDir, + NativeImageBuildRunner.Result buildNativeResult = buildRunner.build(nativeImageArgs, nativeImageName, + resultingExecutableName, outputDir, nativeConfig.debug.enabled, processInheritIODisabled.isPresent()); - if (exitCode != 0) { - throw imageGenerationFailed(exitCode, nativeImageArgs); + if (buildNativeResult.getExitCode() != 0) { + throw imageGenerationFailed(buildNativeResult.getExitCode(), nativeImageArgs); } IoUtils.copy(generatedExecutablePath, finalExecutablePath); Files.delete(generatedExecutablePath); if (nativeConfig.debug.enabled) { - final String symbolsName = String.format("%s.debug", nativeImageName); - Path generatedSymbols = outputDir.resolve(symbolsName); - Path finalSymbolsPath = outputTargetBuildItem.getOutputDirectory().resolve(symbolsName); - IoUtils.copy(generatedSymbols, finalSymbolsPath); - Files.delete(generatedSymbols); - final String sources = "sources"; - final Path generatedSources = outputDir.resolve(sources); - final Path finalSources = outputTargetBuildItem.getOutputDirectory().resolve(sources); - IoUtils.copy(generatedSources, finalSources); - IoUtils.recursiveDelete(generatedSources); + if (buildNativeResult.isObjcopyExists()) { + final String symbolsName = String.format("%s.debug", nativeImageName); + Path generatedSymbols = outputDir.resolve(symbolsName); + Path finalSymbolsPath = outputTargetBuildItem.getOutputDirectory().resolve(symbolsName); + IoUtils.copy(generatedSymbols, finalSymbolsPath); + Files.delete(generatedSymbols); + final String sources = "sources"; + final Path generatedSources = outputDir.resolve(sources); + final Path finalSources = outputTargetBuildItem.getOutputDirectory().resolve(sources); + IoUtils.copy(generatedSources, finalSources); + IoUtils.recursiveDelete(generatedSources); + } else { + log.warn( + "objcopy executable not found in PATH. Debug symbols therefore cannot be placed into the dedicated directory."); + log.warn("That also means that resulting native image is larger as it embeds the debug symbols."); + } + } System.setProperty("native.image.path", finalExecutablePath.toAbsolutePath().toString());