Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 4247:3f6c6e61614e
Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 09 Jan 2012 14:12:53 +0100 |
parents | 3e25132be4b4 |
children | c580db4d6f6f |
comparison
equal
deleted
inserted
replaced
4246:b019b2ebe03e | 4247:3f6c6e61614e |
---|---|
43 # The configuration files (i.e. in the 'mx' sub-directory) of a suite are: | 43 # The configuration files (i.e. in the 'mx' sub-directory) of a suite are: |
44 # | 44 # |
45 # projects - Defines the projects and libraries in the suite and the dependencies between them | 45 # projects - Defines the projects and libraries in the suite and the dependencies between them |
46 # commands.py - Suite specific extensions to the commands available to mx. This is only processed | 46 # commands.py - Suite specific extensions to the commands available to mx. This is only processed |
47 # for the primary suite. | 47 # for the primary suite. |
48 # includes - Other suites to be loaded. This is a recursive. | 48 # includes - Other suites to be loaded. This is recursive. |
49 # env - A set of environment variable definitions. | 49 # env - A set of environment variable definitions. |
50 # | |
51 # The MX_INCLUDES environment variable can also be used to specify other suites. | |
52 # This value of this variable has the same format as a Java class path. | |
53 # | 50 # |
54 # The includes and env files are typically not put under version control | 51 # The includes and env files are typically not put under version control |
55 # as they usually contain local file-system paths. | 52 # as they usually contain local file-system paths. |
56 # | 53 # |
57 # The projects file is like the pom.xml file from Maven except that | 54 # The projects file is like the pom.xml file from Maven except that |
900 if not mustBuild: | 897 if not mustBuild: |
901 for dep in p.all_deps([], False): | 898 for dep in p.all_deps([], False): |
902 if dep.name in built: | 899 if dep.name in built: |
903 mustBuild = True | 900 mustBuild = True |
904 | 901 |
902 javafilelist = [] | |
903 nonjavafilelistdst = [] | |
905 for sourceDir in sourceDirs: | 904 for sourceDir in sourceDirs: |
906 javafilelist = [] | |
907 nonjavafilelist = [] | |
908 for root, _, files in os.walk(sourceDir): | 905 for root, _, files in os.walk(sourceDir): |
909 javafiles = [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] | 906 javafiles = [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] |
910 javafilelist += javafiles | 907 javafilelist += javafiles |
911 nonjavafilelist += [join(root, name) for name in files if not name.endswith('.java')] | 908 |
909 # Copy all non Java resources | |
910 nonjavafilelist = [join(root, name) for name in files if not name.endswith('.java')] | |
911 for src in nonjavafilelist: | |
912 dst = join(outputDir, src[len(sourceDir) + 1:]) | |
913 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) != os.path.getmtime(src)): | |
914 shutil.copyfile(src, dst) | |
915 | |
912 if not mustBuild: | 916 if not mustBuild: |
913 for javafile in javafiles: | 917 for javafile in javafiles: |
914 classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class' | 918 classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class' |
915 if not exists(classfile) or os.path.getmtime(javafile) > os.path.getmtime(classfile): | 919 if not exists(classfile) or os.path.getmtime(javafile) > os.path.getmtime(classfile): |
916 mustBuild = True | 920 mustBuild = True |
917 break | 921 break |
918 | 922 |
919 if not mustBuild: | 923 if not mustBuild: |
920 log('[all class files in {0} are up to date - skipping]'.format(sourceDir)) | 924 log('[all class files for {0} are up to date - skipping]'.format(p.name)) |
921 continue | 925 continue |
922 | 926 |
923 if len(javafilelist) == 0: | 927 if len(javafilelist) == 0: |
924 log('[no Java sources in {0} - skipping]'.format(sourceDir)) | 928 log('[no Java sources for {0} - skipping]'.format(p.name)) |
925 continue | 929 continue |
926 | 930 |
927 built.add(p.name) | 931 built.add(p.name) |
928 | 932 |
929 argfileName = join(p.dir, 'javafilelist.txt') | 933 argfileName = join(p.dir, 'javafilelist.txt') |
930 argfile = open(argfileName, 'wb') | 934 argfile = open(argfileName, 'wb') |
931 argfile.write('\n'.join(javafilelist)) | 935 argfile.write('\n'.join(javafilelist)) |
932 argfile.close() | 936 argfile.close() |
933 | 937 |
934 try: | 938 try: |
935 if jdtJar is None: | 939 if jdtJar is None: |
936 log('Compiling Java sources in {0} with javac...'.format(sourceDir)) | 940 log('Compiling Java sources for {0} with javac...'.format(p.name)) |
937 errFilt = None | 941 errFilt = None |
938 if not args.warnAPI: | 942 if not args.warnAPI: |
939 class Filter: | 943 class Filter: |
940 """ | 944 """ |
941 Class to errFilt the 'is Sun proprietary API and may be removed in a future release' | 945 Class to errFilt the 'is Sun proprietary API and may be removed in a future release' |
942 warning when compiling the VM classes. | 946 warning when compiling the VM classes. |
943 | |
944 """ | |
945 def __init__(self): | |
946 self.c = 0 | |
947 | |
948 def eat(self, line): | |
949 if 'proprietary API' in line: | |
950 self.c = 2 | |
951 elif self.c != 0: | |
952 self.c -= 1 | |
953 else: | |
954 log(line.rstrip()) | |
955 errFilt=Filter().eat | |
956 | 947 |
957 run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt) | 948 """ |
958 else: | 949 def __init__(self): |
959 log('Compiling Java sources in {0} with JDT...'.format(sourceDir)) | 950 self.c = 0 |
960 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') | |
961 if not exists(jdtProperties): | |
962 raise SystemError('JDT properties file {0} not found'.format(jdtProperties)) | |
963 run([java().java, '-Xmx1g', '-jar', jdtJar, | |
964 '-properties', jdtProperties, | |
965 '-' + args.compliance, | |
966 '-cp', cp, '-g', | |
967 '-warn:-unusedImport,-unchecked', | |
968 '-d', outputDir, '@' + argfile.name]) | |
969 finally: | |
970 os.remove(argfileName) | |
971 | 951 |
972 | 952 def eat(self, line): |
973 for name in nonjavafilelist: | 953 if 'proprietary API' in line: |
974 dst = join(outputDir, name[len(sourceDir) + 1:]) | 954 self.c = 2 |
975 if exists(dirname(dst)): | 955 elif self.c != 0: |
976 shutil.copyfile(name, dst) | 956 self.c -= 1 |
977 return args | 957 else: |
958 log(line.rstrip()) | |
959 errFilt=Filter().eat | |
960 | |
961 run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt) | |
962 else: | |
963 log('Compiling Java sources for {0} with JDT...'.format(p.name)) | |
964 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') | |
965 if not exists(jdtProperties): | |
966 raise SystemError('JDT properties file {0} not found'.format(jdtProperties)) | |
967 run([java().java, '-Xmx1g', '-jar', jdtJar, | |
968 '-properties', jdtProperties, | |
969 '-' + args.compliance, | |
970 '-cp', cp, '-g', | |
971 '-warn:-unusedImport,-unchecked', | |
972 '-d', outputDir, '@' + argfile.name]) | |
973 finally: | |
974 os.remove(argfileName) | |
975 | |
976 if suppliedParser: | |
977 return args | |
978 return None | |
978 | 979 |
979 def canonicalizeprojects(args): | 980 def canonicalizeprojects(args): |
980 """process all project files to canonicalize the dependencies | 981 """process all project files to canonicalize the dependencies |
981 | 982 |
982 The exit code of this command reflects how many files were updated.""" | 983 The exit code of this command reflects how many files were updated.""" |
1120 """remove all class files, images, and executables | 1121 """remove all class files, images, and executables |
1121 | 1122 |
1122 Removes all files created by a build, including Java class files, executables, and | 1123 Removes all files created by a build, including Java class files, executables, and |
1123 generated images. | 1124 generated images. |
1124 """ | 1125 """ |
1125 | 1126 |
1126 parser = parser if parser is not None else ArgumentParser(prog='mx build'); | 1127 suppliedParser = parser is not None |
1128 | |
1129 parser = parser if suppliedParser else ArgumentParser(prog='mx build'); | |
1127 parser.add_argument('--no-native', action='store_false', dest='native', help='do not clean native projects') | 1130 parser.add_argument('--no-native', action='store_false', dest='native', help='do not clean native projects') |
1128 parser.add_argument('--no-java', action='store_false', dest='java', help='do not clean Java projects') | 1131 parser.add_argument('--no-java', action='store_false', dest='java', help='do not clean Java projects') |
1129 | 1132 |
1130 args = parser.parse_args(args) | 1133 args = parser.parse_args(args) |
1131 | 1134 |
1137 if args.java: | 1140 if args.java: |
1138 outputDir = p.output_dir() | 1141 outputDir = p.output_dir() |
1139 if outputDir != '' and exists(outputDir): | 1142 if outputDir != '' and exists(outputDir): |
1140 log('Removing {0}...'.format(outputDir)) | 1143 log('Removing {0}...'.format(outputDir)) |
1141 shutil.rmtree(outputDir) | 1144 shutil.rmtree(outputDir) |
1142 return args | 1145 |
1146 if suppliedParser: | |
1147 return args | |
1143 | 1148 |
1144 def help_(args): | 1149 def help_(args): |
1145 """show help for a given command | 1150 """show help for a given command |
1146 | 1151 |
1147 With no arguments, print a list of commands and short help for each command. | 1152 With no arguments, print a list of commands and short help for each command. |
1217 } | 1222 } |
1218 | 1223 |
1219 _argParser = ArgParser() | 1224 _argParser = ArgParser() |
1220 | 1225 |
1221 def main(): | 1226 def main(): |
1222 MX_INCLUDES = os.environ.get('MX_INCLUDES', None) | |
1223 if MX_INCLUDES is not None: | |
1224 for path in MX_INCLUDES.split(os.pathsep): | |
1225 d = join(path, 'mx') | |
1226 if exists(d) and isdir(d): | |
1227 _loadSuite(path) | |
1228 | |
1229 cwdMxDir = join(os.getcwd(), 'mx') | 1227 cwdMxDir = join(os.getcwd(), 'mx') |
1230 if exists(cwdMxDir) and isdir(cwdMxDir): | 1228 if exists(cwdMxDir) and isdir(cwdMxDir): |
1231 _loadSuite(os.getcwd(), True) | 1229 _loadSuite(os.getcwd(), True) |
1232 | 1230 |
1233 opts, commandAndArgs = _argParser._parse_cmd_line() | 1231 opts, commandAndArgs = _argParser._parse_cmd_line() |