Mercurial > hg > graal-compiler
comparison mxtool/mx.py @ 5118:e5427faad192
Merge
author | Christian Haeubl <christian.haeubl@oracle.com> |
---|---|
date | Mon, 19 Mar 2012 15:51:49 -0700 |
parents | 54819cdcca7f |
children | 8ea90b7c8586 |
comparison
equal
deleted
inserted
replaced
5117:b6d1ba51d163 | 5118:e5427faad192 |
---|---|
508 def __init__(self): | 508 def __init__(self): |
509 self.java_initialized = False | 509 self.java_initialized = False |
510 ArgumentParser.__init__(self, prog='mx') | 510 ArgumentParser.__init__(self, prog='mx') |
511 | 511 |
512 self.add_argument('-v', action='store_true', dest='verbose', help='enable verbose output') | 512 self.add_argument('-v', action='store_true', dest='verbose', help='enable verbose output') |
513 self.add_argument('-V', action='store_true', dest='very_verbose', help='enable very verbose output') | |
513 self.add_argument('--dbg', type=int, dest='java_dbg_port', help='make Java processes wait on <port> for a debugger', metavar='<port>') | 514 self.add_argument('--dbg', type=int, dest='java_dbg_port', help='make Java processes wait on <port> for a debugger', metavar='<port>') |
514 self.add_argument('-d', action='store_const', const=8000, dest='java_dbg_port', help='alias for "-dbg 8000"') | 515 self.add_argument('-d', action='store_const', const=8000, dest='java_dbg_port', help='alias for "-dbg 8000"') |
515 self.add_argument('--cp-pfx', dest='cp_prefix', help='class path prefix', metavar='<arg>') | 516 self.add_argument('--cp-pfx', dest='cp_prefix', help='class path prefix', metavar='<arg>') |
516 self.add_argument('--cp-sfx', dest='cp_suffix', help='class path suffix', metavar='<arg>') | 517 self.add_argument('--cp-sfx', dest='cp_suffix', help='class path suffix', metavar='<arg>') |
517 self.add_argument('--J', dest='java_args', help='Java VM arguments (e.g. --J @-dsa)', metavar='@<args>', default=DEFAULT_JAVA_ARGS) | 518 self.add_argument('--J', dest='java_args', help='Java VM arguments (e.g. --J @-dsa)', metavar='@<args>', default=DEFAULT_JAVA_ARGS) |
534 | 535 |
535 # Give the timeout options a default value to avoid the need for hasattr() tests | 536 # Give the timeout options a default value to avoid the need for hasattr() tests |
536 opts.__dict__.setdefault('timeout', 0) | 537 opts.__dict__.setdefault('timeout', 0) |
537 opts.__dict__.setdefault('ptimeout', 0) | 538 opts.__dict__.setdefault('ptimeout', 0) |
538 | 539 |
540 if opts.very_verbose: | |
541 opts.verbose = True | |
542 | |
539 if opts.java_home is None: | 543 if opts.java_home is None: |
540 opts.java_home = os.environ.get('JAVA_HOME') | 544 opts.java_home = os.environ.get('JAVA_HOME') |
541 | 545 |
542 if opts.java_home is None or opts.java_home == '': | 546 if opts.java_home is None or opts.java_home == '': |
543 abort('Could not find Java home. Use --java-home option or ensure JAVA_HOME environment variable is set.') | 547 abort('Could not find Java home. Use --java-home option or ensure JAVA_HOME environment variable is set.') |
638 assert isinstance(args, types.ListType), "'args' must be a list: " + str(args) | 642 assert isinstance(args, types.ListType), "'args' must be a list: " + str(args) |
639 for arg in args: | 643 for arg in args: |
640 assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg) | 644 assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg) |
641 | 645 |
642 if _opts.verbose: | 646 if _opts.verbose: |
647 if _opts.very_verbose: | |
648 log('Environment variables:') | |
649 for key in sorted(os.environ.keys()): | |
650 log(' ' + key + '=' + os.environ[key]) | |
643 log(' '.join(args)) | 651 log(' '.join(args)) |
644 | 652 |
645 if timeout is None and _opts.ptimeout != 0: | 653 if timeout is None and _opts.ptimeout != 0: |
646 timeout = _opts.ptimeout | 654 timeout = _opts.ptimeout |
647 | 655 |
695 finally: | 703 finally: |
696 _currentSubprocess = None | 704 _currentSubprocess = None |
697 | 705 |
698 if retcode and nonZeroIsFatal: | 706 if retcode and nonZeroIsFatal: |
699 if _opts.verbose: | 707 if _opts.verbose: |
700 raise subprocess.CalledProcessError(retcode, ' '.join(args)) | 708 if _opts.very_verbose: |
709 raise subprocess.CalledProcessError(retcode, ' '.join(args)) | |
710 else: | |
711 log('[exit code: ' + str(retcode)+ ']') | |
701 abort(retcode) | 712 abort(retcode) |
702 | 713 |
703 return retcode | 714 return retcode |
704 | 715 |
705 def exe_suffix(name): | 716 def exe_suffix(name): |
725 A JavaCompliance simplifies comparing Java compliance values extracted from a JDK version string. | 736 A JavaCompliance simplifies comparing Java compliance values extracted from a JDK version string. |
726 """ | 737 """ |
727 class JavaCompliance: | 738 class JavaCompliance: |
728 def __init__(self, ver): | 739 def __init__(self, ver): |
729 m = re.match('1\.(\d+).*', ver) | 740 m = re.match('1\.(\d+).*', ver) |
730 assert m is not None, 'not a recognized version string: ' + vstring | 741 assert m is not None, 'not a recognized version string: ' + ver |
731 self.value = int(m.group(1)) | 742 self.value = int(m.group(1)) |
732 | 743 |
733 def __str__ (self): | 744 def __str__ (self): |
734 return '1.' + str(self.value) | 745 return '1.' + str(self.value) |
735 | 746 |
955 if not suppliedParser: | 966 if not suppliedParser: |
956 parser = ArgumentParser(prog='mx build') | 967 parser = ArgumentParser(prog='mx build') |
957 | 968 |
958 javaCompliance = java().javaCompliance | 969 javaCompliance = java().javaCompliance |
959 | 970 |
971 defaultEcjPath = join(_mainSuite.dir, 'mx', 'ecj.jar') | |
972 | |
960 parser = parser if parser is not None else ArgumentParser(prog='mx build') | 973 parser = parser if parser is not None else ArgumentParser(prog='mx build') |
961 parser.add_argument('-f', action='store_true', dest='force', help='force compilation even if class files are up to date') | 974 parser.add_argument('-f', action='store_true', dest='force', help='force compilation even if class files are up to date') |
962 parser.add_argument('-c', action='store_true', dest='clean', help='removes existing build output') | 975 parser.add_argument('-c', action='store_true', dest='clean', help='removes existing build output') |
963 parser.add_argument('--source', dest='compliance', help='Java compliance level', default=str(javaCompliance)) | 976 parser.add_argument('--source', dest='compliance', help='Java compliance level', default=str(javaCompliance)) |
964 parser.add_argument('--Wapi', action='store_true', dest='warnAPI', help='show warnings about using internal APIs') | 977 parser.add_argument('--Wapi', action='store_true', dest='warnAPI', help='show warnings about using internal APIs') |
965 parser.add_argument('--projects', action='store', help='comma separated projects to build (omit to build all projects)') | 978 parser.add_argument('--projects', action='store', help='comma separated projects to build (omit to build all projects)') |
966 parser.add_argument('--no-java', action='store_false', dest='java', help='do not build Java projects') | 979 parser.add_argument('--no-java', action='store_false', dest='java', help='do not build Java projects') |
967 parser.add_argument('--no-native', action='store_false', dest='native', help='do not build native projects') | 980 parser.add_argument('--no-native', action='store_false', dest='native', help='do not build native projects') |
968 parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler instead of javac', metavar='<path>') | 981 parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler (default: ' + defaultEcjPath + ')', default=defaultEcjPath, metavar='<path>') |
969 | 982 |
970 if suppliedParser: | 983 if suppliedParser: |
971 parser.add_argument('remainder', nargs=REMAINDER, metavar='...') | 984 parser.add_argument('remainder', nargs=REMAINDER, metavar='...') |
972 | 985 |
973 args = parser.parse_args(args) | 986 args = parser.parse_args(args) |
974 | 987 |
975 jdtJar = None | 988 jdtJar = None |
976 if args.jdt is not None: | 989 if args.jdt is not None: |
977 if args.jdt.endswith('.jar'): | 990 if args.jdt.endswith('.jar'): |
978 jdtJar=args.jdt | 991 jdtJar=args.jdt |
992 if not exists(jdtJar) and os.path.abspath(jdtJar) == os.path.abspath(defaultEcjPath): | |
993 # Silently ignore JDT if default location is used but not ecj.jar exists there | |
994 jdtJar = None | |
979 elif isdir(args.jdt): | 995 elif isdir(args.jdt): |
980 plugins = join(args.jdt, 'plugins') | 996 plugins = join(args.jdt, 'plugins') |
981 choices = [f for f in os.listdir(plugins) if fnmatch.fnmatch(f, 'org.eclipse.jdt.core_*.jar')] | 997 choices = [f for f in os.listdir(plugins) if fnmatch.fnmatch(f, 'org.eclipse.jdt.core_*.jar')] |
982 if len(choices) != 0: | 998 if len(choices) != 0: |
983 jdtJar = join(plugins, sorted(choices, reverse=True)[0]) | 999 jdtJar = join(plugins, sorted(choices, reverse=True)[0]) |
1051 if jasminAvailable is None: | 1067 if jasminAvailable is None: |
1052 try: | 1068 try: |
1053 with open(os.devnull) as devnull: | 1069 with open(os.devnull) as devnull: |
1054 subprocess.call('jasmin', stdout=devnull, stderr=subprocess.STDOUT) | 1070 subprocess.call('jasmin', stdout=devnull, stderr=subprocess.STDOUT) |
1055 jasminAvailable = True | 1071 jasminAvailable = True |
1056 except OSError as e: | 1072 except OSError: |
1057 jasminAvailable = False | 1073 jasminAvailable = False |
1058 | 1074 |
1059 if jasminAvailable: | 1075 if jasminAvailable: |
1060 log('Assembling Jasmin file ' + src) | 1076 log('Assembling Jasmin file ' + src) |
1061 run(['jasmin', '-d', jasminOutputDir, src]) | 1077 run(['jasmin', '-d', jasminOutputDir, src]) |
1117 errFilt=Filter().eat | 1133 errFilt=Filter().eat |
1118 | 1134 |
1119 run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt) | 1135 run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt) |
1120 else: | 1136 else: |
1121 log('Compiling Java sources for {0} with JDT...'.format(p.name)) | 1137 log('Compiling Java sources for {0} with JDT...'.format(p.name)) |
1138 jdtArgs = [java().java, '-Xmx1g', '-jar', jdtJar, | |
1139 '-' + args.compliance, | |
1140 '-cp', cp, '-g', '-enableJavadoc', | |
1141 '-warn:-unusedImport,-unchecked', | |
1142 '-d', outputDir] | |
1122 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') | 1143 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') |
1123 if not exists(jdtProperties): | 1144 if not exists(jdtProperties): |
1124 raise SystemError('JDT properties file {0} not found'.format(jdtProperties)) | 1145 # Try to fix a missing properties file by running eclipseinit |
1125 run([java().java, '-Xmx1g', '-jar', jdtJar, | 1146 eclipseinit([]) |
1126 '-properties', jdtProperties, | 1147 if not exists(jdtProperties): |
1127 '-' + args.compliance, | 1148 log('JDT properties file {0} not found'.format(jdtProperties)) |
1128 '-cp', cp, '-g', | 1149 else: |
1129 '-warn:-unusedImport,-unchecked', | 1150 jdtArgs += ['-properties', jdtProperties] |
1130 '-d', outputDir, '@' + argfile.name]) | 1151 jdtArgs.append('@' + argfile.name) |
1152 run(jdtArgs) | |
1131 finally: | 1153 finally: |
1132 os.remove(argfileName) | 1154 os.remove(argfileName) |
1133 | 1155 |
1134 if suppliedParser: | 1156 if suppliedParser: |
1135 return args | 1157 return args |
1356 | 1378 |
1357 def println(out, obj): | 1379 def println(out, obj): |
1358 out.write(str(obj) + '\n') | 1380 out.write(str(obj) + '\n') |
1359 | 1381 |
1360 for p in projects(): | 1382 for p in projects(): |
1383 if p.native: | |
1384 continue | |
1385 | |
1361 if not exists(p.dir): | 1386 if not exists(p.dir): |
1362 os.makedirs(p.dir) | 1387 os.makedirs(p.dir) |
1363 | |
1364 if p.native: | |
1365 eclipseNativeSettingsDir = join(suite.dir, 'mx', 'eclipse-native-settings') | |
1366 if exists(eclipseNativeSettingsDir): | |
1367 for name in os.listdir(eclipseNativeSettingsDir): | |
1368 path = join(eclipseNativeSettingsDir, name) | |
1369 if isfile(path): | |
1370 with open(join(eclipseNativeSettingsDir, name)) as f: | |
1371 content = f.read() | |
1372 content = content.replace('${javaHome}', java().jdk) | |
1373 update_file(join(p.dir, name), content) | |
1374 continue | |
1375 | 1388 |
1376 out = StringIO.StringIO() | 1389 out = StringIO.StringIO() |
1377 | 1390 |
1378 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 1391 println(out, '<?xml version="1.0" encoding="UTF-8"?>') |
1379 println(out, '<classpath>') | 1392 println(out, '<classpath>') |
1400 if dep.mustExist: | 1413 if dep.mustExist: |
1401 dep.get_path(resolve=True) | 1414 dep.get_path(resolve=True) |
1402 if isabs(path): | 1415 if isabs(path): |
1403 println(out, '\t<classpathentry exported="true" kind="lib" path="' + path + '"/>') | 1416 println(out, '\t<classpathentry exported="true" kind="lib" path="' + path + '"/>') |
1404 else: | 1417 else: |
1405 projRelPath = os.path.relpath(join(suite.dir, path), p.dir) | 1418 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse |
1406 println(out, '\t<classpathentry exported="true" kind="lib" path="' + projRelPath + '"/>') | 1419 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's |
1420 # safest to simply use absolute paths. | |
1421 println(out, '\t<classpathentry exported="true" kind="lib" path="' + join(suite.dir, path) + '"/>') | |
1407 else: | 1422 else: |
1408 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>') | 1423 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>') |
1409 | 1424 |
1410 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>') | 1425 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>') |
1411 println(out, '</classpath>') | 1426 println(out, '</classpath>') |