Skip to content

Commit 6a2611b

Browse files
committed
[GR-23877] Always check for userdirectories in image heap
PullRequest: graalpython/1112
2 parents 5d246c1 + eb18562 commit 6a2611b

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public void postInitialize(PythonCore core) {
133133
if (!ImageInfo.inImageBuildtimeCode()) {
134134
mod.setAttribute("home", language.getHome());
135135
}
136+
mod.setAttribute("in_image_buildtime", ImageInfo.inImageBuildtimeCode());
137+
mod.setAttribute("in_image", ImageInfo.inImageCode());
136138
String coreHome = context.getCoreHome();
137139
String stdlibHome = context.getStdlibHome();
138140
String capiHome = context.getCAPIHome();

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,24 +534,27 @@ public void initializeHomeAndPrefixPaths(Env newEnv, String languageHome) {
534534
}
535535
} catch (SecurityException | IOException e) {
536536
}
537-
} else {
538-
TruffleFile f = newEnv.getInternalTruffleFile(stdLibHome);
539-
if (!f.isAbsolute()) {
540-
try {
541-
// we need to get absolute path due to the caching code, where the filepath
542-
// is the key for caching.
543-
stdLibHome = f.getCanonicalFile().getPath();
544-
} catch (IOException e) {
545-
// if the file does not exists, then it fails during reading.
546-
}
547-
}
548537
}
549538

550539
if (capiHome.isEmpty()) {
551540
capiHome = coreHome;
552541
}
553542
}
554543

544+
if (ImageInfo.inImageBuildtimeCode()) {
545+
// use relative paths at buildtime to avoid freezing buildsystem paths
546+
TruffleFile base = newEnv.getInternalTruffleFile(basePrefix).getAbsoluteFile();
547+
newEnv.setCurrentWorkingDirectory(base);
548+
basePrefix = ".";
549+
sysPrefix = base.relativize(newEnv.getInternalTruffleFile(sysPrefix)).getPath();
550+
if (sysPrefix.isEmpty()) {
551+
sysPrefix = ".";
552+
}
553+
coreHome = base.relativize(newEnv.getInternalTruffleFile(coreHome)).getPath();
554+
stdLibHome = base.relativize(newEnv.getInternalTruffleFile(stdLibHome)).getPath();
555+
capiHome = base.relativize(newEnv.getInternalTruffleFile(capiHome)).getPath();
556+
}
557+
555558
PythonCore.writeInfo(() -> MessageFormat.format("Updated locations:" +
556559
"\n\tLanguage home: {0}" +
557560
"\n\tSysPrefix: {1}" +

mx.graalpython/mx_graalpython.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,10 @@ def verify_ci(dest_suite, common_ci_dir="ci_common", args=None, ext=('.jsonnet',
13181318
jar_distributions=['graalpython:GRAALPYTHON-LAUNCHER'],
13191319
main_class='com.oracle.graal.python.shell.GraalPythonMain',
13201320
# build_args=['-H:+RemoveSaturatedTypeFlows'],
1321-
build_args=['-H:+TruffleCheckBlackListedMethods'],
1321+
build_args=[
1322+
'-H:+TruffleCheckBlackListedMethods',
1323+
'-H:+DetectUserDirectoriesInImageHeap',
1324+
],
13221325
language='python',
13231326
)
13241327
],

0 commit comments

Comments
 (0)