Skip to content

Commit 7b3c2c6

Browse files
committed
Use org.graalvm.launcher.executablename in launcher if available
1 parent 039b87b commit 7b3c2c6

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public static void main(String[] args) {
6666
private static final String LANGUAGE_ID = "python";
6767
private static final String MIME_TYPE = "text/x-python";
6868

69+
// provided by GraalVM bash launchers, ignored in native image mode
70+
private static final String BASH_LAUNCHER_EXEC_NAME = System.getProperty("org.graalvm.launcher.executablename");
71+
6972
private ArrayList<String> programArgs = null;
7073
private String commandString = null;
7174
private String inputFile = null;
@@ -287,6 +290,17 @@ private void addRelaunchArg(String arg) {
287290
relaunchArgs.add(arg);
288291
}
289292

293+
private String[] execListWithRelaunchArgs(String executableName) {
294+
if (relaunchArgs == null) {
295+
return new String[]{executableName};
296+
} else {
297+
ArrayList<String> execList = new ArrayList<>(relaunchArgs.size() + 1);
298+
execList.add(executableName);
299+
execList.addAll(relaunchArgs);
300+
return execList.toArray(new String[execList.size()]);
301+
}
302+
}
303+
290304
private static void printShortHelp() {
291305
print("usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\n" +
292306
"Try `python -h' for more information.");
@@ -298,13 +312,11 @@ private static void print(String string) {
298312

299313
private String[] getExecutableList() {
300314
if (ImageInfo.inImageCode()) {
301-
ArrayList<String> exec_list = new ArrayList<>();
302-
exec_list.add(ProcessProperties.getExecutableName());
303-
if (relaunchArgs != null) {
304-
exec_list.addAll(relaunchArgs);
305-
}
306-
return exec_list.toArray(new String[exec_list.size()]);
315+
return execListWithRelaunchArgs(ProcessProperties.getExecutableName());
307316
} else {
317+
if (BASH_LAUNCHER_EXEC_NAME != null) {
318+
return execListWithRelaunchArgs(BASH_LAUNCHER_EXEC_NAME);
319+
}
308320
StringBuilder sb = new StringBuilder();
309321
ArrayList<String> exec_list = new ArrayList<>();
310322
sb.append(System.getProperty("java.home")).append(File.separator).append("bin").append(File.separator).append("java");
@@ -338,6 +350,9 @@ private String getExecutable() {
338350
if (ImageInfo.inImageBuildtimeCode()) {
339351
return "";
340352
} else {
353+
if (BASH_LAUNCHER_EXEC_NAME != null) {
354+
return BASH_LAUNCHER_EXEC_NAME;
355+
}
341356
String[] executableList = getExecutableList();
342357
for (int i = 0; i < executableList.length; i++) {
343358
if (executableList[i].matches("\\s")) {

0 commit comments

Comments
 (0)