Skip to content

Commit 1fec2b4

Browse files
committed
make sure we do not leak buildsystem paths into the image
1 parent 78f9b00 commit 1fec2b4

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
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: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,24 +534,23 @@ 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("").getAbsoluteFile();
547+
sysPrefix = base.relativize(newEnv.getInternalTruffleFile(sysPrefix)).getPath();
548+
basePrefix = base.relativize(newEnv.getInternalTruffleFile(basePrefix)).getPath();
549+
coreHome = base.relativize(newEnv.getInternalTruffleFile(coreHome)).getPath();
550+
stdLibHome = base.relativize(newEnv.getInternalTruffleFile(stdLibHome)).getPath();
551+
capiHome = base.relativize(newEnv.getInternalTruffleFile(capiHome)).getPath();
552+
}
553+
555554
PythonCore.writeInfo(() -> MessageFormat.format("Updated locations:" +
556555
"\n\tLanguage home: {0}" +
557556
"\n\tSysPrefix: {1}" +

graalpython/lib-python/3/importlib/_bootstrap_external.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,8 @@ def get_code(self, fullname):
863863
hash_based = False
864864
check_source = True
865865
try:
866+
if __graalpython__.in_image_buildtime:
867+
raise NotImplementedError
866868
bytecode_path = cache_from_source(source_path)
867869
except NotImplementedError:
868870
bytecode_path = None

0 commit comments

Comments
 (0)