@@ -290,7 +290,6 @@ private static <T> String oR(OptionKey<T> option) {
290
290
final String oHCLibraryPath = oH (SubstrateOptions .CLibraryPath );
291
291
final String oHFallbackThreshold = oH (SubstrateOptions .FallbackThreshold );
292
292
final String oHFallbackExecutorJavaArg = oH (FallbackExecutor .Options .FallbackExecutorJavaArg );
293
- final String oHNativeImageOptionsEnvVar = oH (SubstrateOptions .BuildOutputNativeImageOptionsEnvVarValue , OptionOrigin .originDriver );
294
293
final String oRRuntimeJavaArg = oR (Options .FallbackExecutorRuntimeJavaArg );
295
294
final String oHTraceClassInitialization = oH (SubstrateOptions .TraceClassInitialization );
296
295
final String oHTraceObjectInstantiation = oH (SubstrateOptions .TraceObjectInstantiation );
@@ -948,29 +947,35 @@ protected void registerOptionHandler(OptionHandler<? extends NativeImage> handle
948
947
optionHandlers .add (handler );
949
948
}
950
949
950
+ private List <String > defaultNativeImageArgs = null ;
951
+
951
952
private List <String > getDefaultNativeImageArgs () {
952
- List <String > defaultNativeImageArgs = new ArrayList <>();
953
- String propertyOptions = userConfigProperties .get ("NativeImageArgs" );
954
- if (propertyOptions != null ) {
955
- Collections .addAll (defaultNativeImageArgs , propertyOptions .split (" +" ));
956
- }
957
- final String envVarName = SubstrateOptions .NATIVE_IMAGE_OPTIONS_ENV_VAR ;
958
- String nativeImageOptionsValue = System .getenv (envVarName );
959
- if (nativeImageOptionsValue != null ) {
960
- defaultNativeImageArgs .addAll (JDKArgsUtils .parseArgsFromEnvVar (nativeImageOptionsValue , envVarName , msg -> showError (msg )));
961
- }
962
- if (!defaultNativeImageArgs .isEmpty ()) {
963
- String buildApplyOptionName = BundleSupport .BundleOptionVariants .apply .optionName ();
964
- if (config .getBuildArgs ().stream ().noneMatch (arg -> arg .startsWith (buildApplyOptionName + "=" ))) {
965
- if (nativeImageOptionsValue != null ) {
966
- addPlainImageBuilderArg (oHNativeImageOptionsEnvVar + nativeImageOptionsValue );
953
+ if (defaultNativeImageArgs == null ) {
954
+ List <String > args = new ArrayList <>();
955
+ String propertyOptions = userConfigProperties .get ("NativeImageArgs" );
956
+ if (propertyOptions != null ) {
957
+ Collections .addAll (args , propertyOptions .split (" +" ));
958
+ }
959
+ final String envVarName = SubstrateOptions .NATIVE_IMAGE_OPTIONS_ENV_VAR ;
960
+ String nativeImageOptionsValue = System .getenv (envVarName );
961
+ if (nativeImageOptionsValue != null ) {
962
+ args .addAll (JDKArgsUtils .parseArgsFromEnvVar (nativeImageOptionsValue , envVarName , msg -> showError (msg )));
963
+ }
964
+ if (!args .isEmpty ()) {
965
+ String buildApplyOptionName = BundleSupport .BundleOptionVariants .apply .optionName ();
966
+ if (config .getBuildArgs ().stream ().noneMatch (arg -> arg .startsWith (buildApplyOptionName + "=" ))) {
967
+ if (nativeImageOptionsValue != null ) {
968
+ LogUtils .info ("Picked up " + envVarName , nativeImageOptionsValue );
969
+ }
970
+ defaultNativeImageArgs = List .copyOf (args );
971
+ } else {
972
+ LogUtils .warning ("Option '" + buildApplyOptionName + "' in use. Ignoring environment variables " + envVarName + " and " + NativeImage .CONFIG_FILE_ENV_VAR_KEY + "." );
967
973
}
968
- return List .copyOf (defaultNativeImageArgs );
969
974
} else {
970
- LogUtils . warning ( "Option '" + buildApplyOptionName + "' in use. Ignoring environment variables " + envVarName + " and " + NativeImage . CONFIG_FILE_ENV_VAR_KEY + "." );
975
+ defaultNativeImageArgs = List . of ( );
971
976
}
972
977
}
973
- return List . of () ;
978
+ return defaultNativeImageArgs ;
974
979
}
975
980
976
981
static void ensureDirectoryExists (Path dir ) {
0 commit comments