Mercurial > hg > graal-compiler
comparison mx/commands.py @ 8506:c3657d00e343
-Merge with tip
author | Christos Kotselidis <christos.kotselidis@oracle.com> |
---|---|
date | Thu, 21 Mar 2013 14:11:13 +0100 |
parents | 2bfb9644dcc2 |
children | 83fde86ae759 |
comparison
equal
deleted
inserted
replaced
8505:dee7c8b578c7 | 8506:c3657d00e343 |
---|---|
25 # questions. | 25 # questions. |
26 # | 26 # |
27 # ---------------------------------------------------------------------------------------------------- | 27 # ---------------------------------------------------------------------------------------------------- |
28 | 28 |
29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing | 29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing |
30 from os.path import join, exists, dirname, basename | 30 from os.path import join, exists, dirname, basename, getmtime |
31 from argparse import ArgumentParser, REMAINDER | 31 from argparse import ArgumentParser, REMAINDER |
32 import mx | 32 import mx |
33 import sanitycheck | 33 import sanitycheck |
34 import json | 34 import json |
35 | 35 |
50 | 50 |
51 _native_dbg = None | 51 _native_dbg = None |
52 | 52 |
53 _make_eclipse_launch = False | 53 _make_eclipse_launch = False |
54 | 54 |
55 _copyrightTemplate = """/* | 55 _minVersion = mx.JavaVersion('1.7.0_04') |
56 * Copyright (c) {0}, Oracle and/or its affiliates. All rights reserved. | |
57 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
58 * | |
59 * This code is free software; you can redistribute it and/or modify it | |
60 * under the terms of the GNU General Public License version 2 only, as | |
61 * published by the Free Software Foundation. | |
62 * | |
63 * This code is distributed in the hope that it will be useful, but WITHOUT | |
64 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
65 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
66 * version 2 for more details (a copy is included in the LICENSE file that | |
67 * accompanied this code). | |
68 * | |
69 * You should have received a copy of the GNU General Public License version | |
70 * 2 along with this work; if not, write to the Free Software Foundation, | |
71 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
72 * | |
73 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
74 * or visit www.oracle.com if you need additional information or have any | |
75 * questions. | |
76 */ | |
77 | |
78 """ | |
79 | 56 |
80 def _chmodDir(chmodFlags, dirname, fnames): | 57 def _chmodDir(chmodFlags, dirname, fnames): |
81 os.chmod(dirname, chmodFlags) | 58 os.chmod(dirname, chmodFlags) |
82 for name in fnames: | 59 for name in fnames: |
83 os.chmod(os.path.join(dirname, name), chmodFlags) | 60 os.chmod(os.path.join(dirname, name), chmodFlags) |
89 """clean the GraalVM source tree""" | 66 """clean the GraalVM source tree""" |
90 opts = mx.clean(args, parser=ArgumentParser(prog='mx clean')) | 67 opts = mx.clean(args, parser=ArgumentParser(prog='mx clean')) |
91 if opts.native: | 68 if opts.native: |
92 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16') | 69 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16') |
93 mx.run([mx.gmake_cmd(), 'clean'], cwd=join(_graal_home, 'make')) | 70 mx.run([mx.gmake_cmd(), 'clean'], cwd=join(_graal_home, 'make')) |
94 jdks = join(_graal_home, 'jdk' + mx.java().version) | 71 jdks = join(_graal_home, 'jdk' + str(mx.java().version)) |
95 if exists(jdks): | 72 if exists(jdks): |
96 shutil.rmtree(jdks) | 73 shutil.rmtree(jdks) |
97 | 74 |
98 def export(args): | 75 def export(args): |
99 """create a GraalVM zip file for distribution""" | 76 """create a GraalVM zip file for distribution""" |
312 """ | 289 """ |
313 if platform.system() == 'Windows': | 290 if platform.system() == 'Windows': |
314 return join(jdk, 'jre', 'lib', _arch(), 'jvm.cfg') | 291 return join(jdk, 'jre', 'lib', _arch(), 'jvm.cfg') |
315 return join(_vmLibDirInJdk(jdk), 'jvm.cfg') | 292 return join(_vmLibDirInJdk(jdk), 'jvm.cfg') |
316 | 293 |
317 def _jdk(build='product', create=False): | 294 def _jdk(build='product', vmToCheck=None, create=False): |
318 """ | 295 """ |
319 Get the JDK into which Graal is installed, creating it first if necessary. | 296 Get the JDK into which Graal is installed, creating it first if necessary. |
320 """ | 297 """ |
321 jdk = join(_graal_home, 'jdk' + mx.java().version, build) | 298 jdk = join(_graal_home, 'jdk' + str(mx.java().version), build) |
322 jdkContents = ['bin', 'include', 'jre', 'lib'] | 299 jdkContents = ['bin', 'include', 'jre', 'lib'] |
323 if (exists(join(jdk, 'db'))): | 300 if (exists(join(jdk, 'db'))): |
324 jdkContents.append('db') | 301 jdkContents.append('db') |
325 if mx.get_os() != 'windows': | 302 if mx.get_os() != 'windows': |
326 jdkContents.append('man') | 303 jdkContents.append('man') |
340 # reliably used as the bootstrap for a HotSpot build. | 317 # reliably used as the bootstrap for a HotSpot build. |
341 jvmCfg = _vmCfgInJdk(jdk) | 318 jvmCfg = _vmCfgInJdk(jdk) |
342 if not exists(jvmCfg): | 319 if not exists(jvmCfg): |
343 mx.abort(jvmCfg + ' does not exist') | 320 mx.abort(jvmCfg + ' does not exist') |
344 | 321 |
345 lines = [] | |
346 defaultVM = None | 322 defaultVM = None |
347 with open(jvmCfg) as f: | 323 with open(jvmCfg) as f: |
348 for line in f: | 324 for line in f: |
349 if line.startswith('-') and defaultVM is None: | 325 if line.startswith('-') and defaultVM is None: |
350 parts = line.split() | 326 parts = line.split() |
351 assert len(parts) == 2, parts | 327 assert len(parts) == 2, parts |
352 assert parts[1] == 'KNOWN', parts[1] | 328 assert parts[1] == 'KNOWN', parts[1] |
353 defaultVM = parts[0][1:] | 329 defaultVM = parts[0][1:] |
354 lines.append('-' + defaultVM + '0 KNOWN\n') | |
355 lines.append(line) | |
356 | 330 |
357 assert defaultVM is not None, 'Could not find default VM in ' + jvmCfg | 331 assert defaultVM is not None, 'Could not find default VM in ' + jvmCfg |
358 if mx.get_os() != 'windows': | 332 if mx.get_os() != 'windows': |
359 chmodRecursive(jdk, 0755) | 333 chmodRecursive(jdk, 0755) |
360 shutil.copytree(join(_vmLibDirInJdk(jdk), defaultVM), join(_vmLibDirInJdk(jdk), defaultVM + '0')) | 334 shutil.copytree(join(_vmLibDirInJdk(jdk), defaultVM), join(_vmLibDirInJdk(jdk), defaultVM + '0')) |
361 | 335 |
362 with open(jvmCfg, 'w') as f: | 336 with open(jvmCfg, 'w') as fp: |
363 for line in lines: | 337 print >> fp, '-' + defaultVM + '0 KNOWN' |
364 f.write(line) | |
365 | 338 |
366 # Install a copy of the disassembler library | 339 # Install a copy of the disassembler library |
367 try: | 340 try: |
368 hsdis([], copyToDir=_vmLibDirInJdk(jdk)) | 341 hsdis([], copyToDir=_vmLibDirInJdk(jdk)) |
369 except SystemExit: | 342 except SystemExit: |
370 pass | 343 pass |
371 else: | 344 else: |
372 if not exists(jdk): | 345 if not exists(jdk): |
373 mx.abort('The ' + build + ' VM has not been created - run \'mx clean; mx build ' + build + '\'') | 346 mx.abort('The ' + build + ' VM has not been created - run "mx build ' + build + '"') |
347 | |
348 _installGraalJarInJdks(mx.distribution('GRAAL')) | |
349 | |
350 if vmToCheck is not None: | |
351 jvmCfg = _vmCfgInJdk(jdk) | |
352 found = False | |
353 with open(jvmCfg) as f: | |
354 for line in f: | |
355 if line.strip() == '-' + vmToCheck + ' KNOWN': | |
356 found = True | |
357 break | |
358 if not found: | |
359 mx.abort('The ' + build + ' ' + vmToCheck + ' VM has not been created - run "mx --vm ' + vmToCheck + ' build ' + build + '"') | |
360 | |
374 return jdk | 361 return jdk |
362 | |
363 def _installGraalJarInJdks(graalDist): | |
364 graalJar = graalDist.path | |
365 jdks = join(_graal_home, 'jdk' + str(mx.java().version)) | |
366 if exists(jdks): | |
367 for e in os.listdir(jdks): | |
368 jreLibDir = join(jdks, e, 'jre', 'lib') | |
369 if exists(jreLibDir): | |
370 # do a copy and then a move to get atomic updating (on Unix) of graal.jar in the JRE | |
371 fd, tmp = tempfile.mkstemp(suffix='', prefix='graal.jar', dir=jreLibDir) | |
372 shutil.copyfile(graalJar, tmp) | |
373 os.close(fd) | |
374 shutil.move(tmp, join(jreLibDir, 'graal.jar')) | |
375 | 375 |
376 # run a command in the windows SDK Debug Shell | 376 # run a command in the windows SDK Debug Shell |
377 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}): | 377 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}): |
378 newLine = os.linesep | 378 newLine = os.linesep |
379 STARTTOKEN = 'RUNINDEBUGSHELL_STARTSEQUENCE' | 379 STARTTOKEN = 'RUNINDEBUGSHELL_STARTSEQUENCE' |
433 | 433 |
434 def jdkhome(args, vm=None): | 434 def jdkhome(args, vm=None): |
435 """print the JDK directory selected for the 'vm' command""" | 435 """print the JDK directory selected for the 'vm' command""" |
436 | 436 |
437 build = _vmbuild if _vmSourcesAvailable else 'product' | 437 build = _vmbuild if _vmSourcesAvailable else 'product' |
438 print join(_graal_home, 'jdk' + mx.java().version, build) | 438 print join(_graal_home, 'jdk' + str(mx.java().version), build) |
439 | |
440 def initantbuild(args): | |
441 """(re)generates an ant build file for producing graal.jar""" | |
442 parser=ArgumentParser(prog='mx initantbuild') | |
443 parser.add_argument('-f', '--buildfile', help='file to generate', default=join(_graal_home, 'make', 'build-graal.xml')) | |
444 | |
445 args = parser.parse_args(args) | |
446 | |
447 out = mx.XMLDoc() | |
448 | |
449 out.comment(""" | |
450 Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
451 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
452 | |
453 This code is free software; you can redistribute it and/or modify it | |
454 under the terms of the GNU General Public License version 2 only, as | |
455 published by the Free Software Foundation. Oracle designates this | |
456 particular file as subject to the "Classpath" exception as provided | |
457 by Oracle in the LICENSE file that accompanied this code. | |
458 | |
459 This code is distributed in the hope that it will be useful, but WITHOUT | |
460 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
461 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
462 version 2 for more details (a copy is included in the LICENSE file that | |
463 accompanied this code). | |
464 | |
465 You should have received a copy of the GNU General Public License version | |
466 2 along with this work; if not, write to the Free Software Foundation, | |
467 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
468 | |
469 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
470 or visit www.oracle.com if you need additional information or have any | |
471 questions. | |
472 """) | |
473 | |
474 out.open('project', {'name' : 'graal', 'default' : 'main', 'basedir' : '.'}) | |
475 out.element('property', {'name' : 'src.dir', 'value' : '${gamma.dir}/graal'}) | |
476 out.element('property', {'name' : 'classes.dir', 'value' : '${shared.dir}/graal'}) | |
477 out.element('property', {'name' : 'jar.dir', 'value' : '${shared.dir}'}) | |
478 out.element('property', {'name' : 'jar.file', 'value' : '${jar.dir}/graal.jar'}) | |
479 | |
480 out.element('target', {'name' : 'main', 'depends' : 'jar'}) | |
481 | |
482 out.open('target', {'name' : 'compile'}) | |
483 out.element('mkdir', {'dir' : '${classes.dir}'}) | |
484 out.open('javac', {'destdir' : '${classes.dir}', 'debug' : 'on', 'includeantruntime' : 'false', }) | |
485 for p in mx.sorted_deps(mx.distribution('GRAAL').deps): | |
486 out.element('src', {'path' : '${src.dir}/' + p.name}) | |
487 out.element('compilerarg', {'value' : '-XDignore.symbol.file'}) | |
488 | |
489 out.open('classpath') | |
490 out.open('fileset', {'dir' : '${java.home}/../lib'}) | |
491 out.element('include', {'name' : 'tools.jar'}) | |
492 out.close('fileset') | |
493 out.close('classpath') | |
494 | |
495 out.close('javac') | |
496 out.close('target') | |
497 | |
498 out.open('target', {'name' : 'jar', 'depends' : 'compile'}) | |
499 out.element('mkdir', {'dir' : '${jar.dir}'}) | |
500 out.element('jar', {'destfile' : '${jar.file}', 'basedir' : '${classes.dir}'}) | |
501 out.close('target') | |
502 | |
503 out.open('target', {'name' : 'clean'}) | |
504 out.element('delete', {'dir' : '${classes.dir}'}) | |
505 out.element('delete', {'file' : '${jar.filr}'}) | |
506 out.close('target') | |
507 | |
508 out.close('project') | |
509 | |
510 mx.update_file(args.buildfile, out.xml(indent=' ', newl='\n')) | |
439 | 511 |
440 def build(args, vm=None): | 512 def build(args, vm=None): |
441 """build the VM binary | 513 """build the VM binary |
442 | 514 |
443 The global '--vm' option selects which VM to build. This command also | 515 The global '--vm' option selects which VM to build. This command also |
463 elif vm == 'client': | 535 elif vm == 'client': |
464 buildSuffix = '1' | 536 buildSuffix = '1' |
465 else: | 537 else: |
466 assert vm == 'graal', vm | 538 assert vm == 'graal', vm |
467 buildSuffix = 'graal' | 539 buildSuffix = 'graal' |
540 | |
541 initantbuild([]) | |
468 | 542 |
469 for build in builds: | 543 for build in builds: |
470 if build == 'ide-build-target': | 544 if build == 'ide-build-target': |
471 build = os.environ.get('IDE_BUILD_TARGET', 'product') | 545 build = os.environ.get('IDE_BUILD_TARGET', 'product') |
472 if len(build) == 0: | 546 if len(build) == 0: |
483 os.makedirs(vmDir) | 557 os.makedirs(vmDir) |
484 | 558 |
485 def filterXusage(line): | 559 def filterXusage(line): |
486 if not 'Xusage.txt' in line: | 560 if not 'Xusage.txt' in line: |
487 sys.stderr.write(line + os.linesep) | 561 sys.stderr.write(line + os.linesep) |
488 | |
489 # Check that the declaration of graal_projects in arguments.cpp is up to date | |
490 argumentsCpp = join(_graal_home, 'src', 'share', 'vm', 'runtime', 'arguments.cpp') | |
491 assert exists(argumentsCpp), 'File does not exist: ' + argumentsCpp | |
492 with open(argumentsCpp) as fp: | |
493 source = fp.read(); | |
494 decl = 'const char* graal_projects[] = {' | |
495 start = source.find(decl) | |
496 assert start != -1, 'Could not find "' + decl + '" in ' + fp.name | |
497 end = source.find('};', start) | |
498 assert end != -1, 'Could not find "' + decl + '" ... "};" in ' + fp.name | |
499 actual = frozenset(re.findall(r'"([^"]+)"', source[start + len(decl):end])) | |
500 expected = frozenset([p.name for p in mx.project('com.oracle.graal.hotspot.' + _arch()).all_deps([], False)]) | |
501 missing = expected - actual | |
502 extra = actual - expected | |
503 if len(missing) != 0: | |
504 mx.abort(fp.name + ':' + str(source[:start].count('\n') + 1) + ': add missing project(s) to declaration:\n ' + '\n '.join(missing)) | |
505 if len(extra) != 0: | |
506 mx.abort(fp.name + ':' + str(source[:start].count('\n') + 1) + ': remove project(s) from declaration:\n ' + '\n '.join(extra)) | |
507 | 562 |
508 # Check if a build really needs to be done | 563 # Check if a build really needs to be done |
509 timestampFile = join(vmDir, '.build-timestamp') | 564 timestampFile = join(vmDir, '.build-timestamp') |
510 if opts2.force or not exists(timestampFile): | 565 if opts2.force or not exists(timestampFile): |
511 mustBuild = True | 566 mustBuild = True |
587 found = False | 642 found = False |
588 if not exists(jvmCfg): | 643 if not exists(jvmCfg): |
589 mx.abort(jvmCfg + ' does not exist') | 644 mx.abort(jvmCfg + ' does not exist') |
590 | 645 |
591 prefix = '-' + vm | 646 prefix = '-' + vm |
592 vmKnown = prefix + ' KNOWN\n' | 647 vmKnown = prefix + ' KNOWN' |
593 lines = [] | |
594 with open(jvmCfg) as f: | 648 with open(jvmCfg) as f: |
595 for line in f: | 649 for line in f: |
596 if vmKnown in line: | 650 if vmKnown == line.strip(): |
597 found = True | 651 found = True |
598 break | 652 break |
599 if not line.startswith(prefix): | |
600 lines.append(line) | |
601 if not found: | 653 if not found: |
602 mx.log('Appending "' + prefix + ' KNOWN" to ' + jvmCfg) | 654 mx.log('Appending "' + prefix + ' KNOWN" to ' + jvmCfg) |
603 lines.append(vmKnown) | |
604 if mx.get_os() != 'windows': | 655 if mx.get_os() != 'windows': |
605 os.chmod(jvmCfg, 0755) | 656 os.chmod(jvmCfg, 0755) |
606 with open(jvmCfg, 'w') as f: | 657 with open(jvmCfg, 'a') as f: |
607 for line in lines: | 658 print >> f, vmKnown |
608 f.write(line) | |
609 | 659 |
610 if exists(timestampFile): | 660 if exists(timestampFile): |
611 os.utime(timestampFile, None) | 661 os.utime(timestampFile, None) |
612 else: | 662 else: |
613 file(timestampFile, 'a') | 663 file(timestampFile, 'a') |
625 | 675 |
626 if vm is None: | 676 if vm is None: |
627 vm = _vm | 677 vm = _vm |
628 | 678 |
629 build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product' | 679 build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product' |
630 jdk = _jdk(build) | 680 jdk = _jdk(build, vmToCheck=vm) |
631 mx.expand_project_in_args(args) | 681 mx.expand_project_in_args(args) |
632 if _make_eclipse_launch: | 682 if _make_eclipse_launch: |
633 mx.make_eclipse_launch(args, 'graal-' + build, name=None, deps=mx.project('com.oracle.graal.hotspot').all_deps([], True)) | 683 mx.make_eclipse_launch(args, 'graal-' + build, name=None, deps=mx.project('com.oracle.graal.hotspot').all_deps([], True)) |
634 if len([a for a in args if 'PrintAssembly' in a]) != 0: | 684 if len([a for a in args if 'PrintAssembly' in a]) != 0: |
635 hsdis([], copyToDir=_vmLibDirInJdk(jdk)) | 685 hsdis([], copyToDir=_vmLibDirInJdk(jdk)) |
652 'destfile' : 'jacoco.exec' | 702 'destfile' : 'jacoco.exec' |
653 } | 703 } |
654 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args | 704 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args |
655 if '-d64' not in args: | 705 if '-d64' not in args: |
656 args = ['-d64'] + args | 706 args = ['-d64'] + args |
707 | |
657 exe = join(jdk, 'bin', mx.exe_suffix('java')) | 708 exe = join(jdk, 'bin', mx.exe_suffix('java')) |
658 dbg = _native_dbg.split() if _native_dbg is not None else [] | 709 dbg = _native_dbg.split() if _native_dbg is not None else [] |
659 return mx.run(dbg + [exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) | 710 return mx.run(dbg + [exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) |
660 | 711 |
661 def _find_classes_with_annotations(p, pkgRoot, annotations, includeInnerClasses=False): | 712 def _find_classes_with_annotations(p, pkgRoot, annotations, includeInnerClasses=False): |
666 """ | 717 """ |
667 | 718 |
668 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0 | 719 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0 |
669 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses) | 720 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses) |
670 | 721 |
671 def _run_tests(args, harness): | 722 def _run_tests(args, harness, annotations, testfile): |
672 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] | 723 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] |
673 neg = [a[1:] for a in args if a[0] == '-'] | 724 neg = [a[1:] for a in args if a[0] == '-'] |
674 vmArgs = [a[1:] for a in args if a[0] == '@'] | 725 vmArgs = [a[1:] for a in args if a[0] == '@'] |
675 | 726 |
676 def containsAny(c, substrings): | 727 def containsAny(c, substrings): |
677 for s in substrings: | 728 for s in substrings: |
678 if s in c: | 729 if s in c: |
679 return True | 730 return True |
680 return False | 731 return False |
681 | 732 |
733 classes = [] | |
682 for p in mx.projects(): | 734 for p in mx.projects(): |
683 classes = _find_classes_with_annotations(p, None, ['@Test']) | 735 classes += _find_classes_with_annotations(p, None, annotations) |
684 | 736 |
685 if len(pos) != 0: | 737 if len(pos) != 0: |
686 classes = [c for c in classes if containsAny(c, pos)] | 738 classes = [c for c in classes if containsAny(c, pos)] |
687 if len(neg) != 0: | 739 if len(neg) != 0: |
688 classes = [c for c in classes if not containsAny(c, neg)] | 740 classes = [c for c in classes if not containsAny(c, neg)] |
689 | 741 |
690 if len(classes) != 0: | 742 projectscp = mx.classpath([pcp.name for pcp in mx.projects()]) |
691 mx.log('running tests in ' + p.name) | 743 |
692 harness(p, vmArgs, classes) | 744 if len(classes) != 0: |
745 f_testfile = open(testfile, 'w') | |
746 for c in classes: | |
747 f_testfile.write(c + '\n') | |
748 f_testfile.close() | |
749 harness(projectscp, vmArgs) | |
750 | |
751 def _unittest(args, annotations): | |
752 mxdir = dirname(__file__) | |
753 name = 'JUnitWrapper' | |
754 javaSource = join(mxdir, name + '.java') | |
755 javaClass = join(mxdir, name + '.class') | |
756 (_, testfile) = tempfile.mkstemp(".testclasses", "graal") | |
757 | |
758 def harness(projectscp, vmArgs): | |
759 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): | |
760 subprocess.check_call([mx.java().javac, '-cp', projectscp, '-d', mxdir, javaSource]) | |
761 prefixArgs = ['-XX:-BootstrapGraal', '-esa', '-ea'] | |
762 vm(prefixArgs + vmArgs + ['-cp', projectscp + ':' + mxdir, name] + [testfile]) | |
763 | |
764 _run_tests(args, harness, annotations, testfile) | |
765 os.remove(testfile) | |
693 | 766 |
694 def unittest(args): | 767 def unittest(args): |
695 """run the JUnit tests | 768 """run the JUnit tests (all testcases) |
696 | 769 |
697 If filters are supplied, only tests whose fully qualified name | 770 If filters are supplied, only tests whose fully qualified name |
698 include a filter as a substring are run. Negative filters are | 771 include a filter as a substring are run. Negative filters are |
699 those with a '-' prefix. VM args should have a @ prefix.""" | 772 those with a '-' prefix. VM args should have a @ prefix.""" |
700 | 773 |
701 def harness(p, vmArgs, classes): | 774 _unittest(args, ['@Test', '@LongTest']) |
702 prefixArgs = ['-XX:-BootstrapGraal', '-esa', '-ea'] | 775 |
703 vm(prefixArgs + vmArgs + ['-cp', mx.classpath(p.name), 'org.junit.runner.JUnitCore'] + classes) | 776 def shortunittest(args): |
704 _run_tests(args, harness) | 777 """run the JUnit tests (short testcases only) |
778 | |
779 If filters are supplied, only tests whose fully qualified name | |
780 include a filter as a substring are run. Negative filters are | |
781 those with a '-' prefix. VM args should have a @ prefix.""" | |
782 | |
783 _unittest(args, ['@Test']) | |
784 | |
785 def longunittest(args): | |
786 """run the JUnit tests (long testcases only) | |
787 | |
788 If filters are supplied, only tests whose fully qualified name | |
789 include a filter as a substring are run. Negative filters are | |
790 those with a '-' prefix. VM args should have a @ prefix.""" | |
791 | |
792 _unittest(args, ['@LongTest']) | |
705 | 793 |
706 def buildvms(args): | 794 def buildvms(args): |
707 """build one or more VMs in various configurations""" | 795 """build one or more VMs in various configurations""" |
708 | 796 |
709 parser = ArgumentParser(prog='mx buildvms'); | 797 parser = ArgumentParser(prog='mx buildvms'); |
782 if eclipse_exe is not None: | 870 if eclipse_exe is not None: |
783 t = Task('CodeFormatCheck') | 871 t = Task('CodeFormatCheck') |
784 if mx.eclipseformat(['-e', eclipse_exe]) != 0: | 872 if mx.eclipseformat(['-e', eclipse_exe]) != 0: |
785 t.abort('Formatter modified files - run "mx eclipseformat", check in changes and repush') | 873 t.abort('Formatter modified files - run "mx eclipseformat", check in changes and repush') |
786 tasks.append(t.stop()) | 874 tasks.append(t.stop()) |
875 | |
876 t = Task('Canonicalization Check') | |
877 mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...')) | |
878 if mx.canonicalizeprojects([]) != 0: | |
879 t.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.') | |
880 tasks.append(t.stop()) | |
787 | 881 |
788 t = Task('BuildJava') | 882 t = Task('BuildJava') |
789 build(['--no-native', '--jdt-warning-as-error']) | 883 build(['--no-native', '--jdt-warning-as-error']) |
884 tasks.append(t.stop()) | |
885 | |
886 t = Task('Checkstyle') | |
887 if mx.checkstyle([]) != 0: | |
888 t.abort('Checkstyle warnings were found') | |
790 tasks.append(t.stop()) | 889 tasks.append(t.stop()) |
791 | 890 |
792 if exists('jacoco.exec'): | 891 if exists('jacoco.exec'): |
793 os.unlink('jacoco.exec') | 892 os.unlink('jacoco.exec') |
794 | 893 |
795 if args.jacocout is not None: | 894 if args.jacocout is not None: |
796 _jacoco = 'append' | 895 _jacoco = 'append' |
797 else: | 896 else: |
798 _jacoco = 'off' | 897 _jacoco = 'off' |
799 | |
800 | 898 |
801 t = Task('BuildHotSpotGraal: fastdebug,product') | 899 t = Task('BuildHotSpotGraal: fastdebug,product') |
802 buildvms(['--vms', 'graal', '--builds', 'fastdebug,product']) | 900 buildvms(['--vms', 'graal,server', '--builds', 'fastdebug,product']) |
803 tasks.append(t.stop()) | 901 tasks.append(t.stop()) |
804 | 902 |
805 _vmbuild = 'fastdebug' | 903 _vmbuild = 'fastdebug' |
806 t = Task('BootstrapWithSystemAssertions:fastdebug') | 904 t = Task('BootstrapWithSystemAssertions:fastdebug') |
807 vm(['-esa', '-version']) | 905 vm(['-esa', '-version']) |
808 tasks.append(t.stop()) | 906 tasks.append(t.stop()) |
809 | 907 |
810 _vmbuild = 'product' | 908 _vmbuild = 'product' |
811 t = Task('UnitTests:product') | 909 t = Task('BootstrapWithRegisterPressure:product') |
910 vm(['-G:RegisterPressure=rbx,r11,r14,xmm3,xmm11,xmm14', '-esa', '-version']) | |
911 tasks.append(t.stop()) | |
912 | |
913 originalVm = _vm | |
914 _vm = 'server' # hosted mode | |
915 t = Task('UnitTests:hosted-product') | |
812 unittest([]) | 916 unittest([]) |
813 tasks.append(t.stop()) | 917 tasks.append(t.stop()) |
918 _vm = originalVm | |
814 | 919 |
815 for vmbuild in ['fastdebug', 'product']: | 920 for vmbuild in ['fastdebug', 'product']: |
816 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): | 921 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): |
817 t = Task(str(test) + ':' + vmbuild) | 922 t = Task(str(test) + ':' + vmbuild) |
818 if not test.test('graal'): | 923 if not test.test('graal'): |
821 | 926 |
822 if args.jacocout is not None: | 927 if args.jacocout is not None: |
823 jacocoreport([args.jacocout]) | 928 jacocoreport([args.jacocout]) |
824 | 929 |
825 _jacoco = 'off' | 930 _jacoco = 'off' |
826 | |
827 t = Task('Checkstyle') | |
828 if mx.checkstyle([]) != 0: | |
829 t.abort('Checkstyle warnings were found') | |
830 tasks.append(t.stop()) | |
831 | |
832 t = Task('Canonicalization Check') | |
833 mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...')) | |
834 if mx.canonicalizeprojects([]) != 0: | |
835 t.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.') | |
836 tasks.append(t.stop()) | |
837 | 931 |
838 t = Task('CleanAndBuildGraalVisualizer') | 932 t = Task('CleanAndBuildGraalVisualizer') |
839 mx.run(['ant', '-f', join(_graal_home, 'visualizer', 'build.xml'), '-q', 'clean', 'build']) | 933 mx.run(['ant', '-f', join(_graal_home, 'visualizer', 'build.xml'), '-q', 'clean', 'build']) |
840 tasks.append(t.stop()) | 934 tasks.append(t.stop()) |
841 | 935 |
1014 mx.abort('-it (Iteration time) needs a numeric value (seconds)') | 1108 mx.abort('-it (Iteration time) needs a numeric value (seconds)') |
1015 vmArgs.remove('-it') | 1109 vmArgs.remove('-it') |
1016 benchArgs.remove(args[itIdx+1]) | 1110 benchArgs.remove(args[itIdx+1]) |
1017 vm = _vm; | 1111 vm = _vm; |
1018 sanitycheck.getSPECjvm2008(benchArgs, skipCheck, skipValid, wt, it).bench(vm, opts=vmArgs) | 1112 sanitycheck.getSPECjvm2008(benchArgs, skipCheck, skipValid, wt, it).bench(vm, opts=vmArgs) |
1113 | |
1114 def specjbb2013(args): | |
1115 """runs the composite SPECjbb2013 benchmark | |
1116 | |
1117 All options begining with - will be passed to the vm""" | |
1118 benchArgs = [a for a in args if a[0] != '-'] | |
1119 vmArgs = [a for a in args if a[0] == '-'] | |
1120 vm = _vm; | |
1121 sanitycheck.getSPECjbb2013(benchArgs).bench(vm, opts=vmArgs) | |
1122 | |
1123 def specjbb2005(args): | |
1124 """runs the composite SPECjbb2005 benchmark | |
1125 | |
1126 All options begining with - will be passed to the vm""" | |
1127 benchArgs = [a for a in args if a[0] != '-'] | |
1128 vmArgs = [a for a in args if a[0] == '-'] | |
1129 vm = _vm; | |
1130 sanitycheck.getSPECjbb2005(benchArgs).bench(vm, opts=vmArgs) | |
1019 | 1131 |
1020 def hsdis(args, copyToDir=None): | 1132 def hsdis(args, copyToDir=None): |
1021 """download the hsdis library | 1133 """download the hsdis library |
1022 | 1134 |
1023 This is needed to support HotSpot's assembly dumping features. | 1135 This is needed to support HotSpot's assembly dumping features. |
1092 out = args[0] | 1204 out = args[0] |
1093 elif len(args) > 1: | 1205 elif len(args) > 1: |
1094 mx.abort('jacocoreport takes only one argument : an output directory') | 1206 mx.abort('jacocoreport takes only one argument : an output directory') |
1095 mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out]) | 1207 mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out]) |
1096 | 1208 |
1097 def jar(args): | |
1098 parser = ArgumentParser(prog='mx jar'); | |
1099 parser.add_argument('projects', nargs=REMAINDER, metavar='projects...') | |
1100 args = parser.parse_args(args) | |
1101 | |
1102 if not args.projects: | |
1103 mx.abort('Please specify at least one project to jar.') | |
1104 | |
1105 for pname in args.projects: | |
1106 p = mx.project(pname, fatalIfMissing=True) | |
1107 outputDir = p.output_dir() | |
1108 targetJar = join(p.dir, p.name + '.jar') | |
1109 mx.jar(targetJar, [outputDir]) | |
1110 | |
1111 def site(args): | 1209 def site(args): |
1112 """create a website containing javadoc and the project dependency graph""" | 1210 """create a website containing javadoc and the project dependency graph""" |
1113 | 1211 |
1114 return mx.site(['--name', 'Graal', | 1212 return mx.site(['--name', 'Graal', |
1115 '--jd', '@-tag', '--jd', '@test:X', | 1213 '--jd', '@-tag', '--jd', '@test:X', |
1127 'build': [build, '[-options]'], | 1225 'build': [build, '[-options]'], |
1128 'buildvms': [buildvms, '[-options]'], | 1226 'buildvms': [buildvms, '[-options]'], |
1129 'clean': [clean, ''], | 1227 'clean': [clean, ''], |
1130 'hsdis': [hsdis, '[att]'], | 1228 'hsdis': [hsdis, '[att]'], |
1131 'hcfdis': [hcfdis, ''], | 1229 'hcfdis': [hcfdis, ''], |
1230 'initantbuild' : [initantbuild, '[-options]'], | |
1132 'igv' : [igv, ''], | 1231 'igv' : [igv, ''], |
1133 'jdkhome': [jdkhome, ''], | 1232 'jdkhome': [jdkhome, ''], |
1134 'dacapo': [dacapo, '[[n] benchmark] [VM options|@DaCapo options]'], | 1233 'dacapo': [dacapo, '[[n] benchmark] [VM options|@DaCapo options]'], |
1135 'scaladacapo': [scaladacapo, '[[n] benchmark] [VM options|@Scala DaCapo options]'], | 1234 'scaladacapo': [scaladacapo, '[[n] benchmark] [VM options|@Scala DaCapo options]'], |
1136 'specjvm2008': [specjvm2008, '[VM options|@specjvm2008 options]'], | 1235 'specjvm2008': [specjvm2008, '[VM options|specjvm2008 options (-v, -ikv, -ict, -wt, -it)]'], |
1137 'jar': [jar, '[-options]'], | 1236 'specjbb2013': [specjbb2013, '[VM options]'], |
1237 'specjbb2005': [specjbb2005, '[VM options]'], | |
1138 #'example': [example, '[-v] example names...'], | 1238 #'example': [example, '[-v] example names...'], |
1139 'gate' : [gate, '[-options]'], | 1239 'gate' : [gate, '[-options]'], |
1140 'gv' : [gv, ''], | 1240 'gv' : [gv, ''], |
1141 'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'], | 1241 'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'], |
1142 'unittest' : [unittest, '[filters...]'], | 1242 'unittest' : [unittest, '[filters...]'], |
1243 'longunittest' : [longunittest, '[filters...]'], | |
1244 'shortunittest' : [shortunittest, '[filters...]'], | |
1143 'jacocoreport' : [jacocoreport, '[output directory]'], | 1245 'jacocoreport' : [jacocoreport, '[output directory]'], |
1144 'site' : [site, '[-options]'], | 1246 'site' : [site, '[-options]'], |
1145 'vm': [vm, '[-options] class [args...]'], | 1247 'vm': [vm, '[-options] class [args...]'], |
1146 'vmg': [vmg, '[-options] class [args...]'], | 1248 'vmg': [vmg, '[-options] class [args...]'], |
1147 'vmfg': [vmfg, '[-options] class [args...]'], | 1249 'vmfg': [vmfg, '[-options] class [args...]'], |
1166 'build': [build, '[-options] [product|debug|fastdebug]...'] | 1268 'build': [build, '[-options] [product|debug|fastdebug]...'] |
1167 }) | 1269 }) |
1168 | 1270 |
1169 mx.commands.update(commands) | 1271 mx.commands.update(commands) |
1170 | 1272 |
1171 def mx_post_parse_cmd_line(opts): | 1273 def mx_post_parse_cmd_line(opts):# |
1172 version = mx.java().version.split('-')[0] | 1274 # TODO _minVersion check could probably be part of a Suite in mx? |
1173 parts = version.split('.') | 1275 if (mx.java().version < _minVersion) : |
1174 assert len(parts) >= 2 | 1276 mx.abort('Requires Java version ' + str(_minVersion) + ' or greater, got version ' + str(mx.java().version)) |
1175 assert parts[0] == '1' | |
1176 major = int(parts[1]) | |
1177 minor = 0 | |
1178 update = 0 | |
1179 if len(parts) >= 3: | |
1180 minorParts = parts[2].split('_') | |
1181 if len(minorParts) >= 1: | |
1182 minor = int(minorParts[0]) | |
1183 if len(minorParts) >= 2: | |
1184 update = int(minorParts[1]) | |
1185 | |
1186 if (not major >= 7) or (major == 7 and minor == 0 and not update >= 4) : | |
1187 mx.abort('Requires Java version 1.7.0_04 or greater, got version ' + version) | |
1188 | 1277 |
1189 if (_vmSourcesAvailable): | 1278 if (_vmSourcesAvailable): |
1190 if hasattr(opts, 'vm') and opts.vm is not None: | 1279 if hasattr(opts, 'vm') and opts.vm is not None: |
1191 global _vm | 1280 global _vm |
1192 _vm = opts.vm | 1281 _vm = opts.vm |
1197 _make_eclipse_launch = getattr(opts, 'make_eclipse_launch', False) | 1286 _make_eclipse_launch = getattr(opts, 'make_eclipse_launch', False) |
1198 global _jacoco | 1287 global _jacoco |
1199 _jacoco = opts.jacoco | 1288 _jacoco = opts.jacoco |
1200 global _native_dbg | 1289 global _native_dbg |
1201 _native_dbg = opts.native_dbg | 1290 _native_dbg = opts.native_dbg |
1291 | |
1292 mx.distribution('GRAAL').add_update_listener(_installGraalJarInJdks) |