Skip to content

Commit 45547b6

Browse files
fangereransalond
authored andcommitted
Set 'sys.executable' on startup for AOT.
(cherry picked from commit ebf2d3c)
1 parent a3e5133 commit 45547b6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected void finalizeContext(PythonContext context) {
102102

103103
@Override
104104
protected boolean patchContext(PythonContext context, Env newEnv) {
105+
ensureSysExecutable(context);
105106
ensureHomeInOptions(newEnv);
106107
if (!optionsAllowPreInitializedContext(context, newEnv)) {
107108
// Incompatible options - cannot use pre-initialized context
@@ -114,6 +115,11 @@ protected boolean patchContext(PythonContext context, Env newEnv) {
114115
return true;
115116
}
116117

118+
private static void ensureSysExecutable(PythonContext context) {
119+
PythonModule sys = context.getCore().lookupBuiltinModule("sys");
120+
sys.setAttribute("executable", Compiler.command(new Object[]{"com.oracle.svm.core.posix.GetExecutableName"}));
121+
}
122+
117123
private static boolean optionsAllowPreInitializedContext(PythonContext context, Env newEnv) {
118124
// Verify that the option for using a shared core is the same as
119125
// at image building time

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public void initialize(PythonCore core) {
100100
builtinConstants.put("copyright", LICENSE);
101101
builtinConstants.put("dont_write_bytecode", true);
102102
if (TruffleOptions.AOT) {
103-
builtinConstants.put("executable", Compiler.command(new Object[]{"com.oracle.svm.core.posix.GetExecutableName"}));
103+
// cannot set the path at this time since the binary is not yet known; will be patched
104+
// in the context
105+
builtinConstants.put("executable", PNone.NONE);
104106
} else {
105107
StringBuilder sb = new StringBuilder();
106108
sb.append(System.getProperty("java.home")).append(PythonCore.FILE_SEPARATOR).append("bin").append(PythonCore.FILE_SEPARATOR).append("java ");

0 commit comments

Comments
 (0)