@@ -945,17 +945,86 @@ def _join_bin(home, name):
945945 return os .path .join (home , "bin" , name )
946946
947947
948- def graalpy_standalone ():
948+ def _graalpy_launcher (managed = False ):
949+ name = 'graalpy-managed' if managed else 'graalpy'
950+ return f"{ name } .exe" if WIN32 else name
951+
952+
953+ def graalpy_standalone_home (standalone_type , enterprise = False ):
954+ assert standalone_type in ['native' , 'jvm' ]
949955 jdk_version = mx .get_jdk ().javaCompliance # Not our "get_jdk", because we do not want the jvmci tag.
950- mx_args = ['-p' , os .path .join (mx .suite ('truffle' ).dir , '..' , 'vm' ), '--env' , 'ce-python' ]
951- if not DISABLE_REBUILD :
952- mx .run_mx (mx_args + ["build" , "--dep" , f"PYTHON_JAVA_STANDALONE_SVM_JAVA{ jdk_version } " ])
953- out = mx .OutputCapture ()
954- mx .run_mx (mx_args + ["standalone-home" , "--type" , "jvm" , "python" ], out = out )
955- python_home = out .data .splitlines ()[- 1 ].strip ()
956+ python_home = os .environ .get ("GRAALPY_HOME" , None )
957+ if python_home and "*" in python_home :
958+ python_home = os .path .abspath (glob .glob (python_home )[0 ])
959+ mx .log ("Using GraalPy standalone from GRAALPY_HOME: " + python_home )
960+ # Try to verify that we're getting what we expect:
961+ has_java = os .path .exists (os .path .join (python_home , 'jvm' , 'bin' , 'java' ))
962+ if has_java != (standalone_type == 'jvm' ):
963+ mx .abort (f"GRAALPY_HOME is not compatible with the requested distribution type.\n "
964+ f"jvm/bin/java exists?: { has_java } , requested type={ standalone_type } ." )
965+
966+ line = ''
967+ with open (os .path .join (python_home , 'release' ), 'r' ) as f :
968+ while 'JAVA_VERSION=' not in line :
969+ line = f .readline ()
970+ if 'JAVA_VERSION=' not in line :
971+ mx .abort (f"GRAALPY_HOME does not contain 'release' file. Cannot check Java version." )
972+ actual_jdk_version = line .strip ('JAVA_VERSION=' ).strip (' "\n \r ' )
973+ if actual_jdk_version != jdk_version :
974+ mx .abort (f"GRAALPY_HOME is not compatible with the requested JDK version.\n "
975+ f"actual version: '{ actual_jdk_version } ', version string: { line } , requested version: { jdk_version } ." )
976+
977+ launcher = os .path .join (python_home , 'bin' , _graalpy_launcher (enterprise ))
978+ out = mx .OutputCapture ()
979+ import_managed_status = mx .run ([launcher , "-c" , "import __graalpython_enterprise__" ], nonZeroIsFatal = False , out = out , err = out )
980+ if enterprise != (import_managed_status == 0 ):
981+ mx .abort (f"GRAALPY_HOME is not compatible with requested distribution kind ({ import_managed_status = } , { enterprise = } , { out = } )." )
982+ else :
983+ env_file = 'ce-python'
984+ vm_suite_path = os .path .join (mx .suite ('truffle' ).dir , '..' , 'vm' )
985+ svm_distr = ''
986+ if enterprise :
987+ env_file = 'ee-python'
988+ vm_suite_path = os .path .join (mx .suite ('graal-enterprise' ).dir , '..' , 'vm-enterprise' )
989+ svm_distr = '_SVMEE'
990+ mx_args = ['-p' , vm_suite_path , '--env' , env_file ]
991+ if not DISABLE_REBUILD :
992+ dep_type = 'JAVA' if standalone_type == 'jvm' else 'NATIVE'
993+ mx .run_mx (mx_args + ["build" , "--dep" , f"PYTHON_{ dep_type } _STANDALONE_SVM{ svm_distr } _JAVA{ jdk_version } " ])
994+ out = mx .OutputCapture ()
995+ mx .run_mx (mx_args + ["standalone-home" , "--type" , standalone_type , "python" ], out = out )
996+ python_home = out .data .splitlines ()[- 1 ].strip ()
956997 return python_home
957998
958999
1000+ def graalpy_standalone (standalone_type , managed = False ):
1001+ assert standalone_type in ['native' , 'jvm' ]
1002+ if standalone_type == 'native' and mx_gate .get_jacoco_agent_args ():
1003+ return graalpy_standalone ('jvm' )
1004+
1005+ launcher = os .path .join (graalpy_standalone_home (standalone_type , managed ), 'bin' , _graalpy_launcher (managed ))
1006+ return make_coverage_launcher_if_needed (launcher )
1007+
1008+ def graalpy_standalone_jvm ():
1009+ return graalpy_standalone ('jvm' )
1010+
1011+
1012+ def graalpy_standalone_native ():
1013+ return graalpy_standalone ('native' )
1014+
1015+
1016+ def graalpy_standalone_jvm_managed ():
1017+ return graalpy_standalone ('jvm' , managed = True )
1018+
1019+
1020+ def graalpy_standalone_jvm_enterprise ():
1021+ return os .path .join (graalpy_standalone_home ('jvm' , enterprise = True ), 'bin' , _graalpy_launcher (managed = False ))
1022+
1023+
1024+ def graalpy_standalone_native_managed ():
1025+ return graalpy_standalone ('native' , managed = True )
1026+
1027+
9591028def graalvm_jdk ():
9601029 jdk_version = mx .get_jdk ().javaCompliance # Not our "get_jdk", because we do not want the jvmci tag.
9611030 mx_args = ['-p' , os .path .join (mx .suite ('truffle' ).dir , '..' , 'vm' ), '--env' , 'ce' ]
@@ -995,8 +1064,12 @@ def deploy_local_maven_repo():
9951064
9961065def python_gvm (_ = None ):
9971066 home = _graalvm_home (envfile = "graalpython-bash-launcher" )
998- launcher = _join_bin (home , "graalpy" )
1067+ launcher = make_coverage_launcher_if_needed (_join_bin (home , "graalpy" ))
1068+ mx .log (launcher )
1069+ return launcher
1070+
9991071
1072+ def make_coverage_launcher_if_needed (launcher ):
10001073 if mx_gate .get_jacoco_agent_args ():
10011074 # patch our launchers created under jacoco to also run with jacoco.
10021075 # do not use is_collecting_coverage() here, we only want to patch when
@@ -1007,6 +1080,7 @@ def graalvm_vm_arg(java_arg):
10071080 java_arg = f .read ()
10081081 assert java_arg [0 ] == "-" , java_arg
10091082 return shlex .quote (f'--vm.{ java_arg [1 :]} ' )
1083+
10101084 agent_args = ' ' .join (graalvm_vm_arg (arg ) for arg in mx_gate .get_jacoco_agent_args () or [])
10111085
10121086 # We need to make sure the arguments get passed to subprocesses, so we create a temporary launcher
@@ -1019,23 +1093,7 @@ def graalvm_vm_arg(java_arg):
10191093 f .write (f'{ original_launcher } --jvm { exe_arg } { agent_args } "$@"\n ' )
10201094 os .chmod (bash_launcher , 0o775 )
10211095 mx .log (f"Replaced { launcher } with { bash_launcher } to collect coverage" )
1022- return bash_launcher
1023-
1024- mx .log (launcher )
1025- return launcher
1026-
1027-
1028- def python_managed_gvm (_ = None ):
1029- home = _graalvm_home (envfile = "graalpython-managed-bash-launcher" )
1030- launcher = _join_bin (home , "graalpy-managed" )
1031- mx .log (launcher )
1032- return launcher
1033-
1034-
1035- def python_enterprise_gvm (_ = None ):
1036- home = _graalvm_home (envfile = "graalpython-managed-bash-launcher" )
1037- launcher = _join_bin (home , "graalpy" )
1038- mx .log (launcher )
1096+ launcher = bash_launcher
10391097 return launcher
10401098
10411099
@@ -1048,13 +1106,6 @@ def python_svm(_=None):
10481106 return launcher
10491107
10501108
1051- def python_managed_svm ():
1052- home = _graalvm_home (envfile = "graalpython-managed-launcher" )
1053- launcher = _join_bin (home , "graalpy-managed" )
1054- mx .log (launcher )
1055- return launcher
1056-
1057-
10581109def native_image (args ):
10591110 mx .run_mx ([
10601111 "-p" , os .path .join (mx .suite ("truffle" ).dir , ".." , "substratevm" ),
@@ -1071,14 +1122,6 @@ def native_image(args):
10711122 ])
10721123
10731124
1074- def python_so ():
1075- return _graalvm_home (envfile = "graalpython-libpolyglot" )
1076-
1077-
1078- def python_managed_so ():
1079- return _graalvm_home (envfile = "graalpython-managed-libpolyglot" )
1080-
1081-
10821125def _graalpytest_driver ():
10831126 return os .path .join (SUITE .dir , "graalpython" , "com.oracle.graal.python.test" , "src" , "graalpytest.py" )
10841127
@@ -1524,7 +1567,7 @@ def graalpython_gate_runner(args, tasks):
15241567 if not WIN32 :
15251568 mx .run (["env" ])
15261569 run_python_unittests (
1527- python_gvm (),
1570+ graalpy_standalone_jvm (),
15281571 javaAsserts = True ,
15291572 exclude = excluded_tests ,
15301573 nonZeroIsFatal = nonZeroIsFatal ,
@@ -1544,39 +1587,35 @@ def graalpython_gate_runner(args, tasks):
15441587
15451588 with Task ('GraalPython sandboxed tests' , tasks , tags = [GraalPythonTags .unittest_sandboxed ]) as task :
15461589 if task :
1547- run_python_unittests (python_managed_gvm (), javaAsserts = True , exclude = excluded_tests , report = report ())
1590+ run_python_unittests (graalpy_standalone_native_managed (), javaAsserts = True , exclude = excluded_tests , report = report ())
15481591
15491592 with Task ('GraalPython multi-context unittests' , tasks , tags = [GraalPythonTags .unittest_multi ]) as task :
15501593 if task :
1551- run_python_unittests (python_gvm (), args = ["-multi-context" ], javaAsserts = True , exclude = excluded_tests , nonZeroIsFatal = nonZeroIsFatal , report = report ())
1594+ run_python_unittests (graalpy_standalone_jvm (), args = ["-multi-context" ], javaAsserts = True , exclude = excluded_tests , nonZeroIsFatal = nonZeroIsFatal , report = report ())
15521595
15531596 with Task ('GraalPython Jython emulation tests' , tasks , tags = [GraalPythonTags .unittest_jython ]) as task :
15541597 if task :
1555- run_python_unittests (python_gvm (), args = ["--python.EmulateJython" ], paths = ["test_interop.py" ], javaAsserts = True , report = report (), nonZeroIsFatal = nonZeroIsFatal )
1556-
1557- with Task ('GraalPython ginstall' , tasks , tags = [GraalPythonTags .ginstall ], report = True ) as task :
1558- if task :
1559- run_ginstall (python_gvm (), args = ["--quiet" ])
1598+ run_python_unittests (graalpy_standalone_jvm (), args = ["--python.EmulateJython" ], paths = ["test_interop.py" ], javaAsserts = True , report = report (), nonZeroIsFatal = nonZeroIsFatal )
15601599
15611600 with Task ('GraalPython HPy tests' , tasks , tags = [GraalPythonTags .unittest_hpy ]) as task :
15621601 if task :
1563- run_hpy_unittests (python_svm (), nonZeroIsFatal = nonZeroIsFatal , report = report ())
1602+ run_hpy_unittests (graalpy_standalone_native (), nonZeroIsFatal = nonZeroIsFatal , report = report ())
15641603
15651604 with Task ('GraalPython HPy sandboxed tests' , tasks , tags = [GraalPythonTags .unittest_hpy_sandboxed ]) as task :
15661605 if task :
1567- run_hpy_unittests (python_managed_svm (), include_native = False , report = report ())
1606+ run_hpy_unittests (graalpy_standalone_native_managed (), include_native = False , report = report ())
15681607
15691608 with Task ('GraalPython posix module tests' , tasks , tags = [GraalPythonTags .unittest_posix ]) as task :
15701609 if task :
1571- run_python_unittests (python_gvm (), args = ["--PosixModuleBackend=native" ], paths = ["test_posix.py" , "test_mmap.py" ], javaAsserts = True , report = report ())
1572- run_python_unittests (python_gvm (), args = ["--PosixModuleBackend=java" ], paths = ["test_posix.py" , "test_mmap.py" ], javaAsserts = True , report = report ())
1610+ run_python_unittests (graalpy_standalone_jvm (), args = ["--PosixModuleBackend=native" ], paths = ["test_posix.py" , "test_mmap.py" ], javaAsserts = True , report = report ())
1611+ run_python_unittests (graalpy_standalone_jvm (), args = ["--PosixModuleBackend=java" ], paths = ["test_posix.py" , "test_mmap.py" ], javaAsserts = True , report = report ())
15731612
15741613 with Task ('GraalPython standalone module tests' , tasks , tags = [GraalPythonTags .unittest_standalone ]) as task :
15751614 if task :
15761615 env = {
15771616 'ENABLE_STANDALONE_UNITTESTS' : 'true' ,
15781617 'JAVA_HOME' : graalvm_jdk (),
1579- 'PYTHON_STANDALONE_HOME' : graalpy_standalone ( )
1618+ 'PYTHON_STANDALONE_HOME' : graalpy_standalone_home ( 'jvm' )
15801619 }
15811620 mvn_repo_path = deploy_local_maven_repo ()
15821621 # setup maven downloader overrides
@@ -1595,20 +1634,20 @@ def graalpython_gate_runner(args, tasks):
15951634 with Task ('GraalPython Python tests' , tasks , tags = [GraalPythonTags .tagged ]) as task :
15961635 if task :
15971636 # don't fail this task if we're running with the jacoco agent, we know that some tests don't pass with it enabled
1598- run_tagged_unittests (python_svm (), nonZeroIsFatal = (not is_collecting_coverage ()), report = report ())
1637+ run_tagged_unittests (graalpy_standalone_native (), nonZeroIsFatal = (not is_collecting_coverage ()), report = report ())
15991638
16001639 with Task ('GraalPython sandboxed Python tests' , tasks , tags = [GraalPythonTags .tagged_sandboxed ]) as task :
16011640 if task :
1602- run_tagged_unittests (python_managed_gvm (), checkIfWithGraalPythonEE = True , cwd = SUITE .dir , report = report ())
1641+ run_tagged_unittests (graalpy_standalone_native_managed (), checkIfWithGraalPythonEE = True , cwd = SUITE .dir , report = report ())
16031642
16041643 # Unittests on SVM
16051644 with Task ('GraalPython tests on SVM' , tasks , tags = [GraalPythonTags .svmunit , GraalPythonTags .windows ]) as task :
16061645 if task :
1607- run_python_unittests (python_svm (), exclude = excluded_tests , aot_compatible = True , report = report ())
1646+ run_python_unittests (graalpy_standalone_native (), exclude = excluded_tests , aot_compatible = True , report = report ())
16081647
16091648 with Task ('GraalPython sandboxed tests on SVM' , tasks , tags = [GraalPythonTags .svmunit_sandboxed ]) as task :
16101649 if task :
1611- run_python_unittests (python_managed_svm (), aot_compatible = True , report = report ())
1650+ run_python_unittests (graalpy_standalone_native_managed (), aot_compatible = True , report = report ())
16121651
16131652 with Task ('GraalPython license header update' , tasks , tags = [GraalPythonTags .license ]) as task :
16141653 if task :
@@ -2463,7 +2502,7 @@ def python_coverage(args):
24632502 '--exclude-src-gen' ,
24642503 ], env = env )
24652504 if args .truffle :
2466- executable = python_gvm ()
2505+ executable = graalpy_standalone_jvm ()
24672506 file_filter = f"*lib-graalpython*,*graalpython/include*,*com.oracle.graal.python.cext*,*lib/graalpy{ graal_version_short ()} *,*include/python{ py_version_short ()} *"
24682507 if os .environ .get ("TAGGED_UNITTEST_PARTIAL" ):
24692508 variants = [
@@ -2546,7 +2585,7 @@ def python_coverage(args):
25462585 f .name
25472586 ], env = None )
25482587
2549- home_launcher = os .path .join ( os . path . dirname (os .path .dirname (executable )), 'languages/python' )
2588+ home_launcher = os .path .dirname (os .path .dirname (executable ))
25502589 suite_dir = SUITE .dir
25512590 if suite_dir .endswith ("/" ):
25522591 suite_dir = suite_dir [:- 1 ]
@@ -3088,7 +3127,6 @@ def processDeps(self, deps):
30883127 'python-style' : [python_style_checks , '[--fix] [--no-spotbugs]' ],
30893128 'python-svm' : [no_return (python_svm ), '' ],
30903129 'python-gvm' : [no_return (python_gvm ), '' ],
3091- 'python-managed-gvm' : [no_return (python_managed_gvm ), '' ],
30923130 'python-unittests' : [python3_unittests , '' ],
30933131 'python-compare-unittests' : [compare_unittests , '' ],
30943132 'python-retag-unittests' : [retag_unittests , '' ],
0 commit comments