|
52 | 52 | import argparse
|
53 | 53 | import os
|
54 | 54 | import shutil
|
| 55 | +import stat |
55 | 56 | import subprocess
|
56 | 57 | import sys
|
57 | 58 | import tempfile
|
|
118 | 119 | MVN_CODE_PREFIX = "src/main/java"
|
119 | 120 | MVN_RESOURCE_PREFIX = "src/main/resources"
|
120 | 121 |
|
| 122 | +POSIX_LAUNCHER_SCRIPT = r""" |
| 123 | +#!/usr/bin/env bash |
| 124 | +
|
| 125 | +source="${BASH_SOURCE[0]}" |
| 126 | +while [ -h "$source" ] ; do |
| 127 | + prev_source="$source" |
| 128 | + source="$(readlink "$source")"; |
| 129 | + if [[ "$source" != /* ]]; then |
| 130 | + # if the link was relative, it was relative to where it came from |
| 131 | + dir="$( cd -P "$( dirname "$prev_source" )" && pwd )" |
| 132 | + source="$dir/$source" |
| 133 | + fi |
| 134 | +done |
| 135 | +location="$( cd -P "$( dirname "$source" )" && pwd )" |
| 136 | +
|
| 137 | +if [ -z "$JAVA_HOME" ]; then |
| 138 | + JAVA=java |
| 139 | +else |
| 140 | + JAVA="${JAVA_HOME}/bin/java" |
| 141 | +fi |
| 142 | +
|
| 143 | +for var in "$@"; do |
| 144 | + args="${args}$(printf "\v")${var}" |
| 145 | +done |
| 146 | +
|
| 147 | +curdir=`pwd` |
| 148 | +export GRAAL_PYTHON_ARGS="${args}$(printf "\v")" |
| 149 | +mvn -f "${location}/pom.xml" exec:exec -Dexec.executable="${JAVA}" -Dexec.workingdir="${curdir}" -Dexec.args="--module-path %classpath '-Dorg.graalvm.launcher.executablename=$0' --module org.graalvm.py.launcher/com.oracle.graal.python.shell.GraalPythonMain" |
| 150 | +""" |
| 151 | + |
| 152 | +WIN32_LAUNCHER_SCRIPT = r""" |
| 153 | +@echo off |
| 154 | +REM Invoke the GraalPy launcher through Maven, passing any arguments passed to |
| 155 | +REM this script via GRAAL_PYTHON_ARGS. To avoid having to deal with multiple |
| 156 | +REM layers of escaping, we store the arguments into GRAAL_PYTHON_ARGS delimited |
| 157 | +REM with vertical tabs. |
| 158 | +
|
| 159 | +REM Since BAT files cannot easily generate vertical tabs, we create a helper |
| 160 | +REM script to do it for us. We're calling Maven soon anyway, so Java must be |
| 161 | +REM available. |
| 162 | +set JAVA="%JAVA_HOME%/bin/java" |
| 163 | +if not defined JAVA_HOME set JAVA=java |
| 164 | +echo class VTabCreator { public static void main(String[] args) { System.out.print('\013'); } } > VTabCreator.java |
| 165 | +for /f "delims=" %%i in ('%JAVA% VTabCreator.java') do set VTAB=%%i |
| 166 | +del VTabCreator.java |
| 167 | +
|
| 168 | +REM Store each argument separated by vtab |
| 169 | +set GRAAL_PYTHON_ARGS= |
| 170 | +:loop |
| 171 | +set GRAAL_PYTHON_ARGS=%GRAAL_PYTHON_ARGS%%VTAB%%~1 |
| 172 | +shift /1 |
| 173 | +if not "%~1"=="" goto loop |
| 174 | +
|
| 175 | +mvn -f "%~dp0pom.xml" exec:exec -Dexec.executable=java -Dexec.args="--module-path %%classpath -Dorg.graalvm.launcher.executablename=%~0 --module org.graalvm.py.launcher/com.oracle.graal.python.shell.GraalPythonMain" |
| 176 | +""" |
| 177 | + |
121 | 178 | def get_file(*paths):
|
122 | 179 | return os.path.join(os.path.dirname(__file__), *paths)
|
123 | 180 |
|
@@ -209,6 +266,14 @@ def create(self):
|
209 | 266 | # java sources
|
210 | 267 | shutil.copytree(os.path.join(os.path.dirname(__file__), "app"), os.path.join(target_dir))
|
211 | 268 |
|
| 269 | + # create launcher scripts to run graalpy |
| 270 | + posix_launcher = os.path.join(target_dir, "graalpy.sh") |
| 271 | + with open(posix_launcher, "w") as f: |
| 272 | + f.write(POSIX_LAUNCHER_SCRIPT) |
| 273 | + os.chmod(posix_launcher, os.stat(posix_launcher).st_mode | stat.S_IEXEC) |
| 274 | + with open(os.path.join(target_dir, "graalpy.cmd"), "w") as f: |
| 275 | + f.write(WIN32_LAUNCHER_SCRIPT) |
| 276 | + |
212 | 277 | virtual_filesystem_java_file = os.path.join(target_dir, MVN_CODE_PREFIX, "com", "mycompany", "javapython", VFS_JAVA_FILE)
|
213 | 278 | self.create_virtual_filesystem_file(virtual_filesystem_java_file, POLYGLOT_APP_JAVA_PKG)
|
214 | 279 |
|
|
0 commit comments