Skip to content

Commit a6ada6c

Browse files
committed
register the vms and benchmark suites after the suite is initialized
- at this time the mx projects / distributions are available - extend the GraalPythonVM with extra arguments to extend the classpath
1 parent 2607662 commit a6ada6c

File tree

2 files changed

+125
-84
lines changed

2 files changed

+125
-84
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 72 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,25 @@
3737
import mx_urlrewrites
3838
from mx_gate import Task
3939
from mx_graalpython_bench_param import PATH_MESO, BENCHMARKS
40-
from mx_graalpython_benchmark import PythonBenchmarkSuite
40+
from mx_graalpython_benchmark import PythonBenchmarkSuite, python_vm_registry, CPythonVm, PyPyVm, GraalPythonVm, \
41+
CONFIGURATION_DEFAULT
4142
from mx_unittest import unittest
4243

43-
_suite = mx.suite('graalpython')
44-
_mx_graal = mx.suite("compiler", fatalIfMissing=False)
45-
_sulong = mx.suite("sulong")
44+
SUITE = mx.suite('graalpython')
45+
SUITE_COMPILER = mx.suite("compiler", fatalIfMissing=False)
46+
SUITE_SULONG = mx.suite("sulong")
4647

4748

4849
def _get_core_home():
49-
return os.path.join(_suite.dir, "graalpython", "lib-graalpython")
50+
return os.path.join(SUITE.dir, "graalpython", "lib-graalpython")
5051

5152

5253
def _get_stdlib_home():
53-
return os.path.join(_suite.dir, "graalpython", "lib-python", "3")
54+
return os.path.join(SUITE.dir, "graalpython", "lib-python", "3")
5455

5556

5657
def _get_svm_binary():
57-
return os.path.join(_suite.dir, "graalpython-svm")
58+
return os.path.join(SUITE.dir, "graalpython-svm")
5859

5960

6061
def __get_svm_binary_from_graalvm():
@@ -131,7 +132,7 @@ def _extract_graalpython_internal_options(args):
131132
elif arg == '-force-long':
132133
internal += ["-Dcom.oracle.graal.python.forceLongType=true"] # false
133134

134-
elif arg == '-debug-perf' and _mx_graal:
135+
elif arg == '-debug-perf' and SUITE_COMPILER:
135136
# internal += ['-Dgraal.InliningDepthError=500']
136137
# internal += ['-Dgraal.EscapeAnalysisIterations=3']
137138
# internal += ['-XX:JVMCINMethodSizeLimit=1000000']
@@ -149,7 +150,7 @@ def _extract_graalpython_internal_options(args):
149150
# internal += ['-Dgraal.MaximumLoopExplosionCount=1000']
150151
# internal += ['-Dgraal.TruffleCompilationThreshold=100000']
151152

152-
elif arg == '-compile-truffle-immediately' and _mx_graal:
153+
elif arg == '-compile-truffle-immediately' and SUITE_COMPILER:
153154
internal += ['-Dgraal.TruffleCompileImmediately=true']
154155
internal += ['-Dgraal.TruffleCompilationExceptionsAreThrown=true']
155156

@@ -160,7 +161,7 @@ def _extract_graalpython_internal_options(args):
160161

161162

162163
def check_vm(vm_warning=True, must_be_jvmci=False):
163-
if not _mx_graal:
164+
if not SUITE_COMPILER:
164165
if must_be_jvmci:
165166
print '** Error ** : graal compiler was not found!'
166167
sys.exit(1)
@@ -170,7 +171,7 @@ def check_vm(vm_warning=True, must_be_jvmci=False):
170171

171172

172173
def get_jdk():
173-
if _mx_graal:
174+
if SUITE_COMPILER:
174175
tag = 'jvmci'
175176
else:
176177
tag = None
@@ -201,7 +202,7 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs):
201202
if '--python.WithJavaStacktrace' not in graalpython_args:
202203
graalpython_args.insert(0, '--python.WithJavaStacktrace')
203204

204-
if _sulong:
205+
if SUITE_SULONG:
205206
dists.append('SULONG')
206207
if mx.suite("sulong-managed", fatalIfMissing=False):
207208
dists.append('SULONG_MANAGED')
@@ -217,9 +218,9 @@ def _is_user(user, home=None):
217218
return os.environ.get("USER") == user
218219

219220
if _is_user("tim", "MAGLEV_HOME") or _is_user("cbasca") or _is_user("fa"):
220-
_suite.import_suite("tools", version=None, urlinfos=None, in_subdir=True)
221+
SUITE.import_suite("tools", version=None, urlinfos=None, in_subdir=True)
221222
dists.append('CHROMEINSPECTOR')
222-
if _sulong:
223+
if SUITE_SULONG:
223224
vm_args.append("-Dpolyglot.llvm.enableLVI=true")
224225

225226
vm_args += mx.get_runtime_jvm_args(dists, jdk=jdk)
@@ -254,7 +255,7 @@ def nativebuild(args):
254255

255256

256257
def nativeclean(args):
257-
mx.run(['find', _suite.dir, '-name', '*.bc', '-delete'])
258+
mx.run(['find', SUITE.dir, '-name', '*.bc', '-delete'])
258259

259260

260261
def python3_unittests(args):
@@ -291,17 +292,17 @@ def python_gate(args):
291292

292293

293294
def find_jdt():
294-
pardir = os.path.abspath(os.path.join(_suite.dir, ".."))
295-
for f in [os.path.join(_suite.dir, f) for f in os.listdir(_suite.dir)] + [os.path.join(pardir, f) for f in os.listdir(pardir)]:
295+
pardir = os.path.abspath(os.path.join(SUITE.dir, ".."))
296+
for f in [os.path.join(SUITE.dir, f) for f in os.listdir(SUITE.dir)] + [os.path.join(pardir, f) for f in os.listdir(pardir)]:
296297
if os.path.basename(f).startswith("ecj-") and os.path.basename(f).endswith(".jar"):
297298
mx.log("Automatically choosing %s for JDT" % f)
298299
os.environ["JDT"] = f
299300
return
300301

301302

302303
def find_eclipse():
303-
pardir = os.path.abspath(os.path.join(_suite.dir, ".."))
304-
for f in [os.path.join(_suite.dir, f) for f in os.listdir(_suite.dir)] + [os.path.join(pardir, f) for f in os.listdir(pardir)]:
304+
pardir = os.path.abspath(os.path.join(SUITE.dir, ".."))
305+
for f in [os.path.join(SUITE.dir, f) for f in os.listdir(SUITE.dir)] + [os.path.join(pardir, f) for f in os.listdir(pardir)]:
305306
if os.path.basename(f) == "eclipse" and os.path.isdir(f):
306307
mx.log("Automatically choosing %s for Eclipse" % f)
307308
eclipse_exe = os.path.join(f, "eclipse")
@@ -351,7 +352,7 @@ def gate_unittests(args=[], subdir=""):
351352

352353
def run_python_unittests(python_binary, args=[], aot_compatible=True, exclude=[]):
353354
# tests root directory
354-
tests_folder = os.path.join(_suite.dir, "graalpython", "com.oracle.graal.python.test", "src", "tests")
355+
tests_folder = os.path.join(SUITE.dir, "graalpython", "com.oracle.graal.python.test", "src", "tests")
355356

356357
# list of excluded tests
357358
if aot_compatible:
@@ -377,7 +378,7 @@ def is_included(path):
377378
except OSError:
378379
pass
379380

380-
args += [os.path.join(_suite.dir, "graalpython", "com.oracle.graal.python.test", "src", "graalpytest.py"), "-v"]
381+
args += [os.path.join(SUITE.dir, "graalpython", "com.oracle.graal.python.test", "src", "graalpytest.py"), "-v"]
381382
args += testfiles
382383
return mx.run([python_binary] + args, nonZeroIsFatal=True)
383384

@@ -414,15 +415,15 @@ def graalpython_gate_runner(args, tasks):
414415
if not os.path.exists(svm_image_name):
415416
svm_image_name = python_svm(["-h"])
416417
llvm_home = mx_subst.path_substitutions.substitute('--native.Dllvm.home=<path:SULONG_LIBS>')
417-
args = ["--python.CoreHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-graalpython"),
418-
"--python.StdLibHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-python/3"),
418+
args = ["--python.CoreHome=%s" % os.path.join(SUITE.dir, "graalpython", "lib-graalpython"),
419+
"--python.StdLibHome=%s" % os.path.join(SUITE.dir, "graalpython", "lib-python/3"),
419420
llvm_home]
420421
run_python_unittests(svm_image_name, args)
421422

422423
with Task('GraalPython apptests', tasks, tags=[GraalPythonTags.apptests]) as task:
423424
if task:
424425
apprepo = os.environ["GRAALPYTHON_APPTESTS_REPO_URL"]
425-
_apptest_suite = _suite.import_suite(
426+
_apptest_suite = SUITE.import_suite(
426427
"graalpython-apptests",
427428
version="fe1458e3af707f5996f192aedc7b76585501e8ba",
428429
urlinfos=[mx.SuiteImportURLInfo(mx_urlrewrites.rewriteurl(apprepo), "git", mx.vc_system("git"))]
@@ -453,13 +454,13 @@ def graalpython_gate_runner(args, tasks):
453454
if success not in out.data:
454455
mx.abort('Output from generated SVM image "' + svm_image + '" did not match success pattern:\n' + success)
455456
llvm_home = mx_subst.path_substitutions.substitute('--native.Dllvm.home=<path:SULONG_LIBS>')
456-
args = ["--python.CoreHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-graalpython"),
457-
"--python.StdLibHome=%s" % os.path.join(_suite.dir, "graalpython", "lib-python/3"),
457+
args = ["--python.CoreHome=%s" % os.path.join(SUITE.dir, "graalpython", "lib-graalpython"),
458+
"--python.StdLibHome=%s" % os.path.join(SUITE.dir, "graalpython", "lib-python/3"),
458459
llvm_home]
459460
run_python_unittests(svm_image, args)
460461

461462

462-
mx_gate.add_gate_runner(_suite, graalpython_gate_runner)
463+
mx_gate.add_gate_runner(SUITE, graalpython_gate_runner)
463464

464465

465466
def run_shared_lib_test(args=None):
@@ -593,7 +594,7 @@ def run_shared_lib_test(args=None):
593594
}
594595
""")
595596
os.close(fd)
596-
progname = os.path.join(_suite.dir, "graalpython-embedded-tool")
597+
progname = os.path.join(SUITE.dir, "graalpython-embedded-tool")
597598
mx.log("".join(["Running ", "'clang", "-I%s" % svm_lib_path, "-L%s" % svm_lib_path, name, "-o", progname, "-lpolyglot"]))
598599
mx.run(["clang", "-I%s" % svm_lib_path, "-L%s" % svm_lib_path, name, "-o%s" % progname, "-lpolyglot"], nonZeroIsFatal=True)
599600
mx.log("Running " + progname + " with LD_LIBRARY_PATH " + svm_lib_path)
@@ -650,7 +651,7 @@ def getResults(self):
650651
def deploy_binary_if_master(args):
651652
"""if the active branch is 'master', deploy binaries for the primary suite to remote maven repository."""
652653
master_branch = 'master'
653-
active_branch = mx.VC.get_vc(_suite.dir).active_branch(_suite.dir)
654+
active_branch = mx.VC.get_vc(SUITE.dir).active_branch(SUITE.dir)
654655
if active_branch == master_branch:
655656
if sys.platform == "darwin":
656657
args.insert(0, "--platform-dependent")
@@ -684,8 +685,8 @@ def delete_self_if_testdownstream(args):
684685
"""
685686
A helper for downstream testing with binary dependencies
686687
"""
687-
if str(_suite.dir).endswith("testdownstream/graalpython"):
688-
shutil.rmtree(_suite.dir, ignore_errors=True)
688+
if str(SUITE.dir).endswith("testdownstream/graalpython"):
689+
shutil.rmtree(SUITE.dir, ignore_errors=True)
689690

690691

691692
def update_import(name, rev="origin/master", callback=None):
@@ -718,11 +719,11 @@ def update_import_cmd(args):
718719
if name == "sulong":
719720
join = os.path.join
720721
callback=lambda: shutil.copy(
721-
join(_sulong.dir, "include", "truffle.h"),
722-
join(_suite.dir, "graalpython", "com.oracle.graal.python.cext", "include", "truffle.h")
722+
join(SUITE_SULONG.dir, "include", "truffle.h"),
723+
join(SUITE.dir, "graalpython", "com.oracle.graal.python.cext", "include", "truffle.h")
723724
) and shutil.copy(
724725
join(mx.dependency("SULONG_LIBS").output, "polyglot.h"),
725-
join(_suite.dir, "graalpython", "com.oracle.graal.python.cext", "include", "polyglot.h")
726+
join(SUITE.dir, "graalpython", "com.oracle.graal.python.cext", "include", "polyglot.h")
726727
)
727728
# make sure that sulong and regex are the same version
728729
if name == "regex":
@@ -819,11 +820,11 @@ def import_python_sources(args):
819820
files = [line.split(",")[0] for line in f.read().split("\n") if len(line.split(",")) > 1 and line.split(",")[1] == "python.copyright"]
820821

821822
# move to orphaned branch with sources
822-
if _suite.vc.isDirty(_suite.dir):
823+
if SUITE.vc.isDirty(SUITE.dir):
823824
mx.abort("Working dir must be clean")
824-
tip = _suite.vc.tip(_suite.dir).strip()
825-
_suite.vc.git_command(_suite.dir, ["checkout", "python-import"])
826-
_suite.vc.git_command(_suite.dir, ["clean", "-fdx"])
825+
tip = SUITE.vc.tip(SUITE.dir).strip()
826+
SUITE.vc.git_command(SUITE.dir, ["checkout", "python-import"])
827+
SUITE.vc.git_command(SUITE.dir, ["clean", "-fdx"])
827828
shutil.rmtree("graalpython")
828829

829830
for inlined_file in files:
@@ -849,27 +850,18 @@ def import_python_sources(args):
849850
mx.warn("Could not update %s - original file not found" % inlined_file)
850851

851852
# re-copy lib-python
852-
libdir = os.path.join(_suite.dir, "graalpython/lib-python/3")
853+
libdir = os.path.join(SUITE.dir, "graalpython/lib-python/3")
853854
shutil.copytree(os.path.join(pypy_sources, "lib-python", "3"), libdir)
854855

855856
# commit and check back
856-
_suite.vc.git_command(_suite.dir, ["add", "."])
857+
SUITE.vc.git_command(SUITE.dir, ["add", "."])
857858
raw_input("Check that the updated files look as intended, then press RETURN...")
858-
_suite.vc.commit(_suite.dir, "Update Python inlined files: %s" % import_version)
859+
SUITE.vc.commit(SUITE.dir, "Update Python inlined files: %s" % import_version)
859860
answer = raw_input("Should we push python-import (y/N)? ")
860861
if answer and answer in "Yy":
861-
_suite.vc.git_command(_suite.dir, ["push", "origin", "python-import:python-import"])
862-
_suite.vc.update(_suite.dir, rev=tip)
863-
_suite.vc.git_command(_suite.dir, ["merge", "python-import"])
864-
865-
866-
# ----------------------------------------------------------------------------------------------------------------------
867-
#
868-
# add the defined python benchmark suites
869-
#
870-
# ----------------------------------------------------------------------------------------------------------------------
871-
for py_bench_suite in PythonBenchmarkSuite.get_benchmark_suites(BENCHMARKS):
872-
mx_benchmark.add_bm_suite(py_bench_suite)
862+
SUITE.vc.git_command(SUITE.dir, ["push", "origin", "python-import:python-import"])
863+
SUITE.vc.update(SUITE.dir, rev=tip)
864+
SUITE.vc.git_command(SUITE.dir, ["merge", "python-import"])
873865

874866

875867
# ----------------------------------------------------------------------------------------------------------------------
@@ -878,7 +870,7 @@ def import_python_sources(args):
878870
#
879871
# ----------------------------------------------------------------------------------------------------------------------
880872
mx_sdk.register_graalvm_component(mx_sdk.GraalVmLanguage(
881-
suite=_suite,
873+
suite=SUITE,
882874
name='Graal.Python',
883875
short_name='pyn',
884876
dir_name='python',
@@ -911,18 +903,41 @@ def import_python_sources(args):
911903
#
912904
# ----------------------------------------------------------------------------------------------------------------------
913905
if not os.getenv("GRAAL_PYTHONHOME"):
914-
home = os.path.join(_suite.dir, "graalpython")
906+
home = os.path.join(SUITE.dir, "graalpython")
915907
if not os.path.exists(home):
916-
home = [d for d in _suite.dists if d.name == "GRAALPYTHON_GRAALVM_SUPPORT"][0].output
908+
home = [d for d in SUITE.dists if d.name == "GRAALPYTHON_GRAALVM_SUPPORT"][0].output
917909
os.environ["GRAAL_PYTHONHOME"] = home
918910

919911

912+
# ----------------------------------------------------------------------------------------------------------------------
913+
#
914+
# post init
915+
#
916+
# ----------------------------------------------------------------------------------------------------------------------
917+
918+
def _register_vms(namespace):
919+
python_vm_registry.add_vm(CPythonVm(CONFIGURATION_DEFAULT), SUITE)
920+
python_vm_registry.add_vm(PyPyVm(CONFIGURATION_DEFAULT), SUITE)
921+
python_vm_registry.add_vm(GraalPythonVm(config_name=CONFIGURATION_DEFAULT), SUITE, 10)
922+
923+
924+
def _register_bench_suites(namespace):
925+
for py_bench_suite in PythonBenchmarkSuite.get_benchmark_suites(BENCHMARKS):
926+
mx_benchmark.add_bm_suite(py_bench_suite)
927+
928+
929+
def mx_post_parse_cmd_line(namespace):
930+
# all projects are now available at this time
931+
_register_vms(namespace)
932+
_register_bench_suites(namespace)
933+
934+
920935
# ----------------------------------------------------------------------------------------------------------------------
921936
#
922937
# register the suite commands (if any)
923938
#
924939
# ----------------------------------------------------------------------------------------------------------------------
925-
mx.update_commands(_suite, {
940+
mx.update_commands(SUITE, {
926941
'python': [python, '[Python args|@VM options]'],
927942
'python3': [python, '[Python args|@VM options]'],
928943
'deploy-binary-if-master': [deploy_binary_if_master, ''],

0 commit comments

Comments
 (0)