@@ -174,8 +174,9 @@ public final class VFSUtils {
174174 """ ;
175175
176176 private static final boolean IS_WINDOWS = System .getProperty ("os.name" ).startsWith ("Windows" );
177+ private static final boolean IS_MAC = System .getProperty ("os.name" ).startsWith ("Mac" );
177178
178- public static final String LAUNCHER_NAME = IS_WINDOWS ? "graalpy.exe" : "graalpy.sh" ;
179+ public static final String LAUNCHER_NAME = IS_WINDOWS ? "graalpy.exe" : IS_MAC ? "graalpy" : "graalpy.sh" ;
179180
180181 private static final String GRAALPY_MAIN_CLASS = "com.oracle.graal.python.shell.GraalPythonMain" ;
181182
@@ -871,7 +872,42 @@ private static void generateLaunchers(Launcher launcherArgs, BuildToolLog log) t
871872 Path java = Paths .get (System .getProperty ("java.home" ), "bin" , "java" );
872873 String classpath = String .join (File .pathSeparator , launcherArgs .computeClassPath ());
873874 String extraJavaOptions = String .join (" " , GraalPyRunner .getExtraJavaOptions ());
874- if (!IS_WINDOWS ) {
875+ if (IS_MAC ) {
876+ var script = formatMultiline ("""
877+ import os, shutil, struct, venv
878+ from pathlib import Path
879+ adjusted = os.path.dirname(os.path.dirname(venv.__path__[0]))
880+ vl = os.path.join(adjusted, 'venv', 'scripts', 'macos', 'graalpy')
881+ tl = os.path.join(r'%s')
882+ os.makedirs(Path(tl).parent.absolute(), exist_ok=True)
883+ shutil.copy(vl, tl)
884+ cmd = r'%s --enable-native-access=ALL-UNNAMED %s -classpath "%s" %s'
885+ pyvenvcfg = os.path.join(os.path.dirname(tl), "pyvenv.cfg")
886+ with open(pyvenvcfg, 'w', encoding='utf-8') as f:
887+ f.write('venvlauncher_command = ')
888+ f.write(cmd)
889+ """ , launcherArgs .launcherPath , java , extraJavaOptions , classpath , GRAALPY_MAIN_CLASS );
890+ File tmp ;
891+ try {
892+ tmp = File .createTempFile ("create_launcher" , ".py" );
893+ } catch (IOException e ) {
894+ throw new IOException ("failed to create tmp launcher" , e );
895+ }
896+ System .out .println ("Created temporary launcher file: " + tmp );
897+ tmp .deleteOnExit ();
898+ try (var wr = new FileWriter (tmp , StandardCharsets .UTF_8 )) {
899+ wr .write (script );
900+ } catch (IOException e ) {
901+ throw new IOException (String .format ("failed to write tmp launcher %s" , tmp ), e );
902+ }
903+
904+ try {
905+ GraalPyRunner .run (classpath , log , tmp .getAbsolutePath ());
906+ } catch (InterruptedException e ) {
907+ throw new IOException ("failed to run Graalpy launcher" , e );
908+ }
909+ }
910+ else if (!IS_WINDOWS ) {
875911 // we do not bother checking if it exists and has correct java home, since it is
876912 // simple
877913 // to regenerate the launcher
0 commit comments