Skip to content

Commit f5a8d43

Browse files
committed
use supplier to write info about context locations
1 parent 9e8d90d commit f5a8d43

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -464,28 +464,34 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
464464
stdLibHome = newEnv.getOptions().get(PythonOptions.StdLibHome);
465465
capiHome = newEnv.getOptions().get(PythonOptions.CAPI);
466466

467-
PythonCore.writeInfo((MessageFormat.format("Initial locations:" +
467+
PythonCore.writeInfo(() -> MessageFormat.format("Initial locations:" +
468468
"\n\tLanguage home: {0}" +
469469
"\n\tSysPrefix: {1}" +
470470
"\n\tBaseSysPrefix: {2}" +
471471
"\n\tCoreHome: {3}" +
472472
"\n\tStdLibHome: {4}" +
473-
"\n\tCAPI: {5}", languageHome, sysPrefix, basePrefix, coreHome, stdLibHome, capiHome)));
473+
"\n\tCAPI: {5}", languageHome, sysPrefix, basePrefix, coreHome, stdLibHome, capiHome));
474474

475-
TruffleFile home = null;
476-
if (languageHome != null) {
477-
home = newEnv.getInternalTruffleFile(languageHome);
475+
String envHome = null;
476+
try {
477+
envHome = System.getenv("GRAAL_PYTHONHOME");
478+
} catch (SecurityException e) {
478479
}
479480

480-
try {
481-
String envHome = System.getenv("GRAAL_PYTHONHOME");
482-
if (envHome != null) {
483-
TruffleFile envHomeFile = newEnv.getInternalTruffleFile(envHome);
484-
if (envHomeFile.isDirectory()) {
485-
home = envHomeFile;
486-
}
481+
final TruffleFile home;
482+
if (languageHome != null && envHome == null) {
483+
home = newEnv.getInternalTruffleFile(languageHome);
484+
} else if (envHome != null) {
485+
boolean envHomeIsDirectory = false;
486+
TruffleFile envHomeFile = null;
487+
try {
488+
envHomeFile = newEnv.getInternalTruffleFile(envHome);
489+
envHomeIsDirectory = envHomeFile.isDirectory();
490+
} catch (SecurityException e) {
487491
}
488-
} catch (SecurityException e) {
492+
home = envHomeIsDirectory ? envHomeFile : null;
493+
} else {
494+
home = null;
489495
}
490496

491497
if (home != null) {
@@ -540,13 +546,14 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
540546
capiHome = base.relativize(newEnv.getInternalTruffleFile(capiHome)).getPath();
541547
}
542548

543-
PythonCore.writeInfo((MessageFormat.format("Updated locations:" +
549+
PythonCore.writeInfo(() -> MessageFormat.format("Updated locations:" +
544550
"\n\tLanguage home: {0}" +
545551
"\n\tSysPrefix: {1}" +
546-
"\n\tSysBasePrefix: {2}" +
552+
"\n\tBaseSysPrefix: {2}" +
547553
"\n\tCoreHome: {3}" +
548554
"\n\tStdLibHome: {4}" +
549-
"\n\tExecutable: {6}", home.getPath(), sysPrefix, basePrefix, coreHome, stdLibHome, newEnv.getOptions().get(PythonOptions.Executable))));
555+
"\n\tExecutable: {5}" +
556+
"\n\tCAPI: {6}", home != null ? home.getPath() : "", sysPrefix, basePrefix, coreHome, stdLibHome, newEnv.getOptions().get(PythonOptions.Executable), capiHome));
550557
}
551558

552559
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonCore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
package com.oracle.graal.python.runtime;
2727

28+
import java.util.function.Supplier;
29+
2830
import com.oracle.graal.python.PythonLanguage;
2931
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3032
import com.oracle.graal.python.builtins.objects.floats.PFloat;
@@ -90,4 +92,7 @@ static void writeInfo(String message) {
9092
PythonLanguage.getLogger().fine(message);
9193
}
9294

95+
static void writeInfo(Supplier<String> messageSupplier) {
96+
PythonLanguage.getLogger().fine(messageSupplier);
97+
}
9398
}

0 commit comments

Comments
 (0)