@@ -849,9 +849,9 @@ private static Path ensureLauncher(Launcher launcherArgs, BuildToolLog log) thro
849849 }
850850 }
851851
852- private static boolean checkWinLauncherJavaPath (Path venvCfg , Path java ) {
852+ private static boolean checkPyVenvCfgFile (Path pyVenvCfg , Path java ) {
853853 try {
854- for (String line : Files .readAllLines (venvCfg )) {
854+ for (String line : Files .readAllLines (pyVenvCfg )) {
855855 if (line .trim ().startsWith ("venvlauncher_command = " + java )) {
856856 return true ;
857857 }
@@ -872,11 +872,16 @@ private static void generateLaunchers(Launcher launcherArgs, BuildToolLog log) t
872872 Path java = Paths .get (System .getProperty ("java.home" ), "bin" , "java" );
873873 String classpath = String .join (File .pathSeparator , launcherArgs .computeClassPath ());
874874 String extraJavaOptions = String .join (" " , GraalPyRunner .getExtraJavaOptions ());
875- if (IS_MAC ) {
875+ if (IS_MAC || IS_WINDOWS ) {
876+ if (Files .exists (launcherArgs .launcherPath ) && checkPyVenvCfgFile (launcherArgs .launcherPath .getParent ().resolve ("pyvenv.cfg" ), java )) {
877+ return ;
878+ }
879+ var launcherFolder = IS_WINDOWS ? "nt" : "macos" ;
880+ var launcherName = IS_WINDOWS ? "graalpy.exe" : "graalpy" ;
876881 var script = formatMultiline ("""
877882 import os, shutil, struct, venv
878883 from pathlib import Path
879- vl = os.path.join(venv.__path__[0], 'scripts', 'macos ', 'graalpy ')
884+ vl = os.path.join(venv.__path__[0], 'scripts', '%s ', '%s ')
880885 tl = os.path.join(r'%s')
881886 os.makedirs(Path(tl).parent.absolute(), exist_ok=True)
882887 shutil.copy(vl, tl)
@@ -885,7 +890,7 @@ private static void generateLaunchers(Launcher launcherArgs, BuildToolLog log) t
885890 with open(pyvenvcfg, 'w', encoding='utf-8') as f:
886891 f.write('venvlauncher_command = ')
887892 f.write(cmd)
888- """ , launcherArgs .launcherPath , java , extraJavaOptions , classpath , GRAALPY_MAIN_CLASS );
893+ """ , launcherFolder , launcherName , launcherArgs .launcherPath , java , extraJavaOptions , classpath , GRAALPY_MAIN_CLASS );
889894 File tmp ;
890895 try {
891896 tmp = File .createTempFile ("create_launcher" , ".py" );
@@ -906,7 +911,7 @@ with open(pyvenvcfg, 'w', encoding='utf-8') as f:
906911 throw new IOException ("failed to run Graalpy launcher" , e );
907912 }
908913 }
909- else if (! IS_WINDOWS ) {
914+ else {
910915 // we do not bother checking if it exists and has correct java home, since it is
911916 // simple
912917 // to regenerate the launcher
@@ -923,40 +928,6 @@ else if (!IS_WINDOWS) {
923928 } catch (IOException e ) {
924929 throw new IOException (String .format ("failed to create launcher %s" , launcherArgs .launcherPath ), e );
925930 }
926- } else if (!Files .exists (launcherArgs .launcherPath )
927- || !checkWinLauncherJavaPath (launcherArgs .launcherPath .getParent ().resolve ("pyenv.cfg" ), java )) {
928- // on windows, generate a venv launcher that executes the java command
929- var script = formatMultiline ("""
930- import os, shutil, struct, venv
931- from pathlib import Path
932- vl = os.path.join(venv.__path__[0], 'scripts', 'nt', 'graalpy.exe')
933- tl = os.path.join(r'%s')
934- os.makedirs(Path(tl).parent.absolute(), exist_ok=True)
935- shutil.copy(vl, tl)
936- cmd = r'%s --enable-native-access=ALL-UNNAMED %s -classpath "%s" %s'
937- pyvenvcfg = os.path.join(os.path.dirname(tl), "pyvenv.cfg")
938- with open(pyvenvcfg, 'w', encoding='utf-8') as f:
939- f.write('venvlauncher_command = ')
940- f.write(cmd)
941- """ , launcherArgs .launcherPath , java , extraJavaOptions , classpath , GRAALPY_MAIN_CLASS );
942- File tmp ;
943- try {
944- tmp = File .createTempFile ("create_launcher" , ".py" );
945- } catch (IOException e ) {
946- throw new IOException ("failed to create tmp launcher" , e );
947- }
948- tmp .deleteOnExit ();
949- try (var wr = new FileWriter (tmp , StandardCharsets .UTF_8 )) {
950- wr .write (script );
951- } catch (IOException e ) {
952- throw new IOException (String .format ("failed to write tmp launcher %s" , tmp ), e );
953- }
954-
955- try {
956- GraalPyRunner .run (classpath , log , tmp .getAbsolutePath ());
957- } catch (InterruptedException e ) {
958- throw new IOException ("failed to run Graalpy launcher" , e );
959- }
960931 }
961932 }
962933
0 commit comments