Skip to content

Commit 372da08

Browse files
committed
do not query language resources from a native image
1 parent c0a126a commit 372da08

File tree

2 files changed

+24
-48
lines changed

2 files changed

+24
-48
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,7 @@ private void initializeJavaCore() {
851851
}
852852

853853
private void initializeImportlib() {
854-
PythonModule bootstrap = null;
855-
if (!ImageInfo.inImageBuildtimeCode()) {
856-
bootstrap = ImpModuleBuiltins.importFrozenModuleObject(this, T__FROZEN_IMPORTLIB, false);
857-
}
854+
PythonModule bootstrap = ImpModuleBuiltins.importFrozenModuleObject(this, T__FROZEN_IMPORTLIB, false);
858855
PythonModule bootstrapExternal;
859856

860857
PyObjectCallMethodObjArgs callNode = PyObjectCallMethodObjArgs.getUncached();
@@ -898,10 +895,7 @@ private void initializeImportlib() {
898895
} else {
899896
LOGGER.log(Level.FINE, () -> "# installing zipimport hook");
900897
TruffleString t_zipimport = toTruffleStringUncached("zipimport");
901-
PythonModule zipimport = null;
902-
if (!ImageInfo.inImageBuildtimeCode()) {
903-
zipimport = ImpModuleBuiltins.importFrozenModuleObject(this, t_zipimport, false);
904-
}
898+
PythonModule zipimport = ImpModuleBuiltins.importFrozenModuleObject(this, t_zipimport, false);
905899
if (zipimport == null) {
906900
// true when the frozen module is not available
907901
zipimport = createModule(t_zipimport);

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

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,21 +1681,11 @@ private void initializePosixSupport() {
16811681
private TruffleString langHome, sysPrefix, basePrefix, coreHome, capiHome, jniHome, stdLibHome;
16821682

16831683
public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
1684-
sysPrefix = newEnv.getOptions().get(PythonOptions.SysPrefix);
1685-
basePrefix = newEnv.getOptions().get(PythonOptions.SysBasePrefix);
1686-
coreHome = newEnv.getOptions().get(PythonOptions.CoreHome);
1687-
stdLibHome = newEnv.getOptions().get(PythonOptions.StdLibHome);
1688-
capiHome = newEnv.getOptions().get(PythonOptions.CAPI);
1689-
jniHome = newEnv.getOptions().get(PythonOptions.JNIHome);
1690-
1691-
Python3Core.writeInfo(() -> MessageFormat.format("Initial locations:" +
1692-
"\n\tLanguage home: {0}" +
1693-
"\n\tSysPrefix: {1}" +
1694-
"\n\tBaseSysPrefix: {2}" +
1695-
"\n\tCoreHome: {3}" +
1696-
"\n\tStdLibHome: {4}" +
1697-
"\n\tCAPI: {5}" +
1698-
"\n\tJNI library: {6}", languageHome, sysPrefix, basePrefix, coreHome, stdLibHome, capiHome, jniHome));
1684+
if (ImageInfo.inImageBuildtimeCode()) {
1685+
// at buildtime we do not need these paths to be valid, since all boot files are frozen
1686+
basePrefix = sysPrefix = langHome = coreHome = stdLibHome = capiHome = jniHome = T_DOT;
1687+
return;
1688+
}
16991689

17001690
String pythonHome = newEnv.getOptions().get(PythonOptions.PythonHome);
17011691
if (pythonHome.isEmpty()) {
@@ -1726,7 +1716,7 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
17261716
return home;
17271717
},
17281718
() -> {
1729-
if (PythonLanguage.PYTHON_RESOURCE_CLASS != null) {
1719+
if (PythonLanguage.PYTHON_RESOURCE_CLASS != null && !ImageInfo.inImageCode()) {
17301720
try {
17311721
return newEnv.getInternalResource(PythonLanguage.PYTHON_RESOURCE_CLASS).getAbsoluteFile();
17321722
} catch (IOException e) {
@@ -1741,8 +1731,24 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
17411731
if (homeCandidate == null) {
17421732
continue;
17431733
}
1734+
sysPrefix = newEnv.getOptions().get(PythonOptions.SysPrefix);
1735+
basePrefix = newEnv.getOptions().get(PythonOptions.SysBasePrefix);
1736+
coreHome = newEnv.getOptions().get(PythonOptions.CoreHome);
1737+
stdLibHome = newEnv.getOptions().get(PythonOptions.StdLibHome);
1738+
capiHome = newEnv.getOptions().get(PythonOptions.CAPI);
1739+
jniHome = newEnv.getOptions().get(PythonOptions.JNIHome);
17441740
boolean homeSeemsValid = !coreHome.isEmpty() && !stdLibHome.isEmpty();
17451741

1742+
Python3Core.writeInfo(() -> MessageFormat.format("Initial locations:" +
1743+
"\n\tLanguage home: {0}" +
1744+
"\n\tSysPrefix: {1}" +
1745+
"\n\tBaseSysPrefix: {2}" +
1746+
"\n\tCoreHome: {3}" +
1747+
"\n\tStdLibHome: {4}" +
1748+
"\n\tCAPI: {5}" +
1749+
"\n\tJNI library: {6}" +
1750+
"\n\tHome candidate: {7}", languageHome, sysPrefix, basePrefix, coreHome, stdLibHome, capiHome, jniHome, homeCandidate.toString()));
1751+
17461752
langHome = toTruffleStringUncached(homeCandidate.toString());
17471753
if (sysPrefix.isEmpty()) {
17481754
sysPrefix = toTruffleStringUncached(homeCandidate.getAbsoluteFile().getPath());
@@ -1814,31 +1820,7 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
18141820

18151821
if (homeSeemsValid) {
18161822
break;
1817-
} else {
1818-
// reset values
1819-
sysPrefix = newEnv.getOptions().get(PythonOptions.SysPrefix);
1820-
basePrefix = newEnv.getOptions().get(PythonOptions.SysBasePrefix);
1821-
coreHome = newEnv.getOptions().get(PythonOptions.CoreHome);
1822-
stdLibHome = newEnv.getOptions().get(PythonOptions.StdLibHome);
1823-
capiHome = newEnv.getOptions().get(PythonOptions.CAPI);
1824-
jniHome = newEnv.getOptions().get(PythonOptions.JNIHome);
1825-
}
1826-
}
1827-
1828-
if (ImageInfo.inImageBuildtimeCode()) {
1829-
// use relative paths at buildtime to avoid freezing buildsystem paths
1830-
TruffleFile base = newEnv.getInternalTruffleFile(basePrefix.toJavaStringUncached()).getAbsoluteFile();
1831-
newEnv.setCurrentWorkingDirectory(base);
1832-
basePrefix = T_DOT;
1833-
sysPrefix = toTruffleStringUncached(base.relativize(newEnv.getInternalTruffleFile(sysPrefix.toJavaStringUncached())).getPath());
1834-
if (sysPrefix.isEmpty()) {
1835-
sysPrefix = T_DOT;
18361823
}
1837-
langHome = toTruffleStringUncached(base.relativize(newEnv.getInternalTruffleFile(langHome.toJavaStringUncached())).getPath());
1838-
coreHome = toTruffleStringUncached(base.relativize(newEnv.getInternalTruffleFile(coreHome.toJavaStringUncached())).getPath());
1839-
stdLibHome = toTruffleStringUncached(base.relativize(newEnv.getInternalTruffleFile(stdLibHome.toJavaStringUncached())).getPath());
1840-
capiHome = toTruffleStringUncached(base.relativize(newEnv.getInternalTruffleFile(capiHome.toJavaStringUncached())).getPath());
1841-
jniHome = toTruffleStringUncached(base.relativize(newEnv.getInternalTruffleFile(jniHome.toJavaStringUncached())).getPath());
18421824
}
18431825

18441826
Python3Core.writeInfo(() -> MessageFormat.format("Updated locations:" +

0 commit comments

Comments
 (0)