Skip to content

Commit 3f293ac

Browse files
committed
Add NATIVE_IMAGE_SLOPPY_BUILDER_SANITATION fallback
1 parent f1be22c commit 3f293ac

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,20 @@ protected int buildImage(List<String> javaArgs, LinkedHashSet<Path> cp, LinkedHa
14501450
ProcessBuilder pb = new ProcessBuilder();
14511451
pb.command(command);
14521452
Map<String, String> environment = pb.environment();
1453-
sanitizeJVMEnvironment(environment, imageBuilderEnvironment);
1453+
String sloppySanitationKey = "NATIVE_IMAGE_SLOPPY_BUILDER_SANITATION";
1454+
String sloppySanitationValue = System.getenv().getOrDefault(sloppySanitationKey, "false");
1455+
if (Boolean.parseBoolean(sloppySanitationValue)) {
1456+
if (useBundle()) {
1457+
bundleSupport = null;
1458+
throw showError("Bundle support is not compatible with environment variable %s=%s.".formatted(sloppySanitationKey, sloppySanitationValue));
1459+
}
1460+
if (!imageBuilderEnvironment.isEmpty()) {
1461+
throw showError("Option -E<env-var-key>[=<env-var-value>] is not compatible with environment variable %s=%s.".formatted(sloppySanitationKey, sloppySanitationValue));
1462+
}
1463+
sloppySanitizeJVMEnvironment(environment);
1464+
} else {
1465+
sanitizeJVMEnvironment(environment, imageBuilderEnvironment);
1466+
}
14541467
if (OS.WINDOWS.isCurrent()) {
14551468
WindowsBuildEnvironmentUtil.propagateEnv(environment);
14561469
}
@@ -1493,6 +1506,14 @@ boolean useBundle() {
14931506
return bundleSupport != null;
14941507
}
14951508

1509+
@Deprecated
1510+
private static void sloppySanitizeJVMEnvironment(Map<String, String> environment) {
1511+
String[] jvmAffectingEnvironmentVariables = {"JAVA_COMPILER", "_JAVA_OPTIONS", "JAVA_TOOL_OPTIONS", "JDK_JAVA_OPTIONS", "CLASSPATH"};
1512+
for (String affectingEnvironmentVariable : jvmAffectingEnvironmentVariables) {
1513+
environment.remove(affectingEnvironmentVariable);
1514+
}
1515+
}
1516+
14961517
private static void sanitizeJVMEnvironment(Map<String, String> environment, Map<String, String> imageBuilderEnvironment) {
14971518
Map<String, String> restrictedEnvironment = new HashMap<>();
14981519
List<String> jvmRequiredEnvironmentVariables = new ArrayList<>(List.of("PATH", "PWD", "HOME", "LANG", "LC_ALL"));

0 commit comments

Comments
 (0)