comparison mxtool/mx.py @ 4147:55376d8953a6

Improved 'build' and 'clean' commands.
author Doug Simon <doug.simon@oracle.com>
date Mon, 19 Dec 2011 22:22:56 +0100
parents 9aee7df31417
children bf5efc22fb3f
comparison
equal deleted inserted replaced
4146:4eb5b2469b6f 4147:55376d8953a6
477 if opts.user_home is None or opts.user_home == '': 477 if opts.user_home is None or opts.user_home == '':
478 abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.') 478 abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.')
479 479
480 os.environ['JAVA_HOME'] = opts.java_home 480 os.environ['JAVA_HOME'] = opts.java_home
481 os.environ['HOME'] = opts.user_home 481 os.environ['HOME'] = opts.user_home
482
483 opts.java = join(opts.java_home, 'bin', 'java')
484 opts.javac = join(opts.java_home, 'bin', 'javac')
485 opts.javap = join(opts.java_home, 'bin', 'javap')
486 482
487 commandAndArgs = opts.__dict__.pop('commandAndArgs') 483 commandAndArgs = opts.__dict__.pop('commandAndArgs')
488 484
489 for s in suites(): 485 for s in suites():
490 mod = s.commands 486 mod = s.commands
509 """ 505 """
510 assert _java is not None 506 assert _java is not None
511 return _java 507 return _java
512 508
513 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None): 509 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
514 return run(_java.format_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) 510 return run(java().format_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
515 511
516 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None): 512 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
517 """ 513 """
518 Run a command in a subprocess, wait for it to complete and return the exit status of the process. 514 Run a command in a subprocess, wait for it to complete and return the exit status of the process.
519 If the exit status is non-zero and `nonZeroIsFatal` is true, then the program is exited with 515 If the exit status is non-zero and `nonZeroIsFatal` is true, then the program is exited with
726 myDir = dirname(__file__) 722 myDir = dirname(__file__)
727 723
728 javaSource = join(myDir, 'URLConnectionDownload.java') 724 javaSource = join(myDir, 'URLConnectionDownload.java')
729 javaClass = join(myDir, 'URLConnectionDownload.class') 725 javaClass = join(myDir, 'URLConnectionDownload.class')
730 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): 726 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
731 subprocess.check_call([_opts.javac, '-d', myDir, javaSource]) 727 subprocess.check_call([java().javac, '-d', myDir, javaSource])
732 if run([_opts.java, '-cp', myDir, 'URLConnectionDownload', path] + urls) != 0: 728 if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + urls) != 0:
733 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + 729 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' +
734 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') 730 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually')
735 731
736 def update_file(path, content): 732 def update_file(path, content):
737 """ 733 """
765 and linkers for the various source code types.""" 761 and linkers for the various source code types."""
766 762
767 parser = ArgumentParser(prog='mx build'); 763 parser = ArgumentParser(prog='mx build');
768 parser.add_argument('-f', action='store_true', dest='force', help='force compilation even if class files are up to date') 764 parser.add_argument('-f', action='store_true', dest='force', help='force compilation even if class files are up to date')
769 parser.add_argument('-c', action='store_true', dest='clean', help='removes existing build output') 765 parser.add_argument('-c', action='store_true', dest='clean', help='removes existing build output')
770 parser.add_argument('--no-native', action='store_false', dest='native', help='do not build com.oracle.max.vm.native') 766 parser.add_argument('--source', dest='compliance', help='Java compliance level', default='1.6')
767 parser.add_argument('--Wapi', action='store_true', dest='warnAPI', help='show warnings about using internal APIs')
768 parser.add_argument('--no-native', action='store_false', dest='native', help='do not build native projects')
771 parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler instead of javac', metavar='<path>') 769 parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler instead of javac', metavar='<path>')
772 770
773 args = parser.parse_args(args) 771 args = parser.parse_args(args)
774 772
775 jdtJar = None 773 jdtJar = None
784 782
785 built = set() 783 built = set()
786 for p in sorted_deps(): 784 for p in sorted_deps():
787 785
788 if p.native: 786 if p.native:
789 log('Compiling C sources in {0}...'.format(p.dir)) 787 log('Calling GNU make {0}...'.format(p.dir))
790 788
791 if args.clean: 789 if args.clean:
792 run([gmake_cmd(), 'clean'], cwd=p.dir) 790 run([gmake_cmd(), 'clean'], cwd=p.dir)
793 791
794 run([gmake_cmd()], cwd=p.dir) 792 run([gmake_cmd()], cwd=p.dir)
842 argfile.close() 840 argfile.close()
843 841
844 try: 842 try:
845 if jdtJar is None: 843 if jdtJar is None:
846 log('Compiling Java sources in {0} with javac...'.format(sourceDir)) 844 log('Compiling Java sources in {0} with javac...'.format(sourceDir))
847 845 errFilt = None
848 class Filter: 846 if not args.warnAPI:
849 """ 847 class Filter:
850 Class to filter the 'is Sun proprietary API and may be removed in a future release' 848 """
851 warning when compiling the VM classes. 849 Class to errFilt the 'is Sun proprietary API and may be removed in a future release'
850 warning when compiling the VM classes.
851
852 """
853 def __init__(self):
854 self.c = 0
855
856 def eat(self, line):
857 if 'proprietary API':
858 self.c = 2
859 elif self.c != 0:
860 self.c -= 1
861 else:
862 print line.rstrip()
863 errFilt=Filter().eat
852 864
853 """ 865 run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt)
854 def __init__(self):
855 self.c = 0
856
857 def eat(self, line):
858 if 'Sun proprietary API' in line:
859 self.c = 2
860 elif self.c != 0:
861 self.c -= 1
862 else:
863 print line.rstrip()
864
865 run([_opts.javac, '-g', '-J-Xmx1g', '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=Filter().eat)
866 else: 866 else:
867 log('Compiling Java sources in {0} with JDT...'.format(sourceDir)) 867 log('Compiling Java sources in {0} with JDT...'.format(sourceDir))
868 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') 868 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs')
869 if not exists(jdtProperties): 869 if not exists(jdtProperties):
870 raise SystemError('JDT properties file {0} not found'.format(jdtProperties)) 870 raise SystemError('JDT properties file {0} not found'.format(jdtProperties))
871 run([_opts.java, '-Xmx1g', '-jar', jdtJar, '-1.6', '-cp', cp, '-g', 871 run([java().java, '-Xmx1g', '-jar', jdtJar,
872 '-properties', jdtProperties, 872 '-properties', jdtProperties,
873 '-' + args.compliance,
874 '-cp', cp, '-g',
873 '-warn:-unusedImport,-unchecked', 875 '-warn:-unusedImport,-unchecked',
874 '-d', outputDir, '@' + argfile.name]) 876 '-d', outputDir, '@' + argfile.name])
875 finally: 877 finally:
876 os.remove(argfileName) 878 os.remove(argfileName)
877 879
1073 1075
1074 Run the JDK javap class file disassembler with the following prepended options: 1076 Run the JDK javap class file disassembler with the following prepended options:
1075 1077
1076 -private -verbose -classpath <path to project classes>""" 1078 -private -verbose -classpath <path to project classes>"""
1077 1079
1078 javap = _opts.javap 1080 javap = java().javap
1079 if not exists(javap): 1081 if not exists(javap):
1080 abort('The javap executable does not exists: ' + javap) 1082 abort('The javap executable does not exists: ' + javap)
1081 else: 1083 else:
1082 run([javap, '-private', '-verbose', '-classpath', classpath()] + args) 1084 run([javap, '-private', '-verbose', '-classpath', classpath()] + args)
1083 1085