Skip to content

Commit

Permalink
Merge pull request #19806 from Sanne/GraalExclusions2Cleanup
Browse files Browse the repository at this point in the history
Add the ability for extensions to exclude GraalVM config from jars [Revisited]
  • Loading branch information
Sanne authored Aug 31, 2021
2 parents 650761a + 58e48e0 commit 236dc6b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.quarkus.deployment.builditem.nativeimage;

import io.quarkus.builder.item.MultiBuildItem;

/**
* A build item that allows extension to configure the native-image compiler to effectively
* ignore certain configuration files in specific jars.
*
* The {@code jarFile} property specifies the name of the jar file or a regular expression that can be used to
* match multiple jar files.
* Matching jar files using regular expressions should be done as a last resort.
*
* The {@code resourceName} property specifies the name of the resource file or a regular expression that can be used to
* match multiple resource files.
* For the match to work, the resources need to be part of the matched jar file(s) (see {@code jarFile}).
* Matching resource files using regular expressions should be done as a last resort.
*
* See https://github.com/oracle/graal/pull/3179 for more details.
*/
public final class ExcludeConfigBuildItem extends MultiBuildItem {

private final String jarFile;
private final String resourceName;

public ExcludeConfigBuildItem(String jarFile, String resourceName) {
this.jarFile = jarFile;
this.resourceName = resourceName;
}

public ExcludeConfigBuildItem(String jarFile) {
this(jarFile, "/META-INF/native-image/native-image\\.properties");
}

public String getJarFile() {
return jarFile;
}

public String getResourceName() {
return resourceName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.quarkus.bootstrap.model.AppDependency;
import io.quarkus.bootstrap.util.IoUtils;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSecurityProviderBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.pkg.NativeConfig;
Expand Down Expand Up @@ -81,7 +82,8 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig,
NativeImageSourceJarBuildItem nativeImageSourceJarBuildItem,
OutputTargetBuildItem outputTargetBuildItem,
PackageConfig packageConfig,
List<NativeImageSystemPropertyBuildItem> nativeImageProperties) {
List<NativeImageSystemPropertyBuildItem> nativeImageProperties,
List<ExcludeConfigBuildItem> excludeConfigs) {

Path outputDir;
try {
Expand All @@ -100,6 +102,7 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig,
.setNativeConfig(nativeConfig)
.setOutputTargetBuildItem(outputTargetBuildItem)
.setNativeImageProperties(nativeImageProperties)
.setExcludeConfigs(excludeConfigs)
.setOutputDir(outputDir)
.setRunnerJarName(runnerJar.getFileName().toString())
// the path to native-image is not known now, it is only known at the time the native-sources will be consumed
Expand Down Expand Up @@ -130,6 +133,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
PackageConfig packageConfig,
CurateOutcomeBuildItem curateOutcomeBuildItem,
List<NativeImageSystemPropertyBuildItem> nativeImageProperties,
List<ExcludeConfigBuildItem> excludeConfigs,
List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders,
Optional<ProcessInheritIODisabled> processInheritIODisabled) {
if (nativeConfig.debug.enabled) {
Expand Down Expand Up @@ -187,6 +191,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
.setNativeConfig(nativeConfig)
.setOutputTargetBuildItem(outputTargetBuildItem)
.setNativeImageProperties(nativeImageProperties)
.setExcludeConfigs(excludeConfigs)
.setNativeImageSecurityProviders(nativeImageSecurityProviders)
.setOutputDir(outputDir)
.setRunnerJarName(runnerJarName)
Expand Down Expand Up @@ -477,6 +482,7 @@ static class Builder {
private NativeConfig nativeConfig;
private OutputTargetBuildItem outputTargetBuildItem;
private List<NativeImageSystemPropertyBuildItem> nativeImageProperties;
private List<ExcludeConfigBuildItem> excludeConfigs;
private List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders;
private Path outputDir;
private String runnerJarName;
Expand All @@ -500,6 +506,11 @@ public Builder setNativeImageProperties(List<NativeImageSystemPropertyBuildItem>
return this;
}

public Builder setExcludeConfigs(List<ExcludeConfigBuildItem> excludeConfigs) {
this.excludeConfigs = excludeConfigs;
return this;
}

public Builder setNativeImageSecurityProviders(
List<NativeImageSecurityProviderBuildItem> nativeImageSecurityProviders) {
this.nativeImageSecurityProviders = nativeImageSecurityProviders;
Expand Down Expand Up @@ -584,8 +595,6 @@ public NativeImageInvokerInfo build() {
"-H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime"); //the default collection policy results in full GC's 50% of the time
nativeImageArgs.add("-H:+JNI");
nativeImageArgs.add("-H:+AllowFoldMethods");
nativeImageArgs.add("-jar");
nativeImageArgs.add(runnerJarName);

if (nativeConfig.enableFallbackImages) {
nativeImageArgs.add("-H:FallbackThreshold=5");
Expand Down Expand Up @@ -700,10 +709,21 @@ public NativeImageInvokerInfo build() {
.collect(Collectors.joining(","));
nativeImageArgs.add("-H:AdditionalSecurityProviders=" + additionalSecurityProviders);
}

// --exclude-config options
for (ExcludeConfigBuildItem excludeConfig : excludeConfigs) {
nativeImageArgs.add("--exclude-config");
nativeImageArgs.add(excludeConfig.getJarFile());
nativeImageArgs.add(excludeConfig.getResourceName());
}
}

nativeImageArgs.add(nativeImageName);

//Make sure to have the -jar as last one, as it otherwise breaks "--exclude-config"
nativeImageArgs.add("-jar");
nativeImageArgs.add(runnerJarName);

return new NativeImageInvokerInfo(nativeImageArgs);
}

Expand Down

0 comments on commit 236dc6b

Please sign in to comment.