Skip to content

Commit

Permalink
Fix native-image arguments generation for native-sources package type
Browse files Browse the repository at this point in the history
* Ensures the NativeImageSecurityProvidersBuildItem is taken into
  account to add -H:AdditionalSecurityProviders as needed
* Gets the GraalVM version so that it can be taken in account when
  generating the arguments (e.g. to avoid adding parameters that are
  not present in some older version)
  • Loading branch information
zakkak committed Nov 30, 2021
1 parent ebd6d37 commit ffd1287
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig,
PackageConfig packageConfig,
List<NativeImageSystemPropertyBuildItem> nativeImageProperties,
List<ExcludeConfigBuildItem> excludeConfigs,
NativeImageAllowIncompleteClasspathAggregateBuildItem incompleteClassPathAllowed) {
NativeImageAllowIncompleteClasspathAggregateBuildItem incompleteClassPathAllowed,
List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders,
Optional<ProcessInheritIODisabled> processInheritIODisabled) {

Path outputDir;
try {
Expand All @@ -98,19 +100,42 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig,
}

Path runnerJar = outputDir.resolve(nativeImageSourceJarBuildItem.getPath().getFileName());
final String runnerJarName = runnerJar.getFileName().toString();

String noPIE = "";

boolean isContainerBuild = nativeConfig.isContainerBuild();
if (!isContainerBuild && SystemUtils.IS_OS_LINUX) {
noPIE = detectNoPIE();
}

String nativeImageName = getNativeImageName(outputTargetBuildItem, packageConfig);
String resultingExecutableName = getResultingExecutableName(nativeImageName, isContainerBuild);

NativeImageBuildRunner buildRunner = getNativeImageBuildRunner(nativeConfig, outputDir,
nativeImageName, resultingExecutableName);
buildRunner.setup(processInheritIODisabled.isPresent());
final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion();

if (graalVMVersion.isDetected()) {
checkGraalVMVersion(graalVMVersion);
} else {
log.error("Unable to get GraalVM version from the native-image binary.");
}

NativeImageInvokerInfo nativeImageArgs = new NativeImageInvokerInfo.Builder()
.setNativeConfig(nativeConfig)
.setOutputTargetBuildItem(outputTargetBuildItem)
.setNativeImageProperties(nativeImageProperties)
.setBrokenClasspath(incompleteClassPathAllowed.isAllow())
.setExcludeConfigs(excludeConfigs)
.setBrokenClasspath(incompleteClassPathAllowed.isAllow())
.setNativeImageSecurityProviders(nativeImageSecurityProviders)
.setOutputDir(outputDir)
.setRunnerJarName(runnerJar.getFileName().toString())
.setRunnerJarName(runnerJarName)
// the path to native-image is not known now, it is only known at the time the native-sources will be consumed
.setNativeImageName(nativeImageName)
.setNoPIE(noPIE)
.setGraalVMVersion(graalVMVersion)
.build();
List<String> command = nativeImageArgs.getArgs();
try (FileOutputStream commandFOS = new FileOutputStream(outputDir.resolve("native-image.args").toFile())) {
Expand Down

0 comments on commit ffd1287

Please sign in to comment.