Mercurial > hg > truffle
comparison mx/mx_graal.py @ 15451:3774b6f4319b
Merge with 2f684eda1938cc92a72a35461c8d00f1871fe389
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 29 Apr 2014 12:43:27 -0700 |
parents | 5947bb02474f |
children | f73fc9309f12 |
comparison
equal
deleted
inserted
replaced
15450:be0c151d912b | 15451:3774b6f4319b |
---|---|
24 # or visit www.oracle.com if you need additional information or have any | 24 # or visit www.oracle.com if you need additional information or have any |
25 # questions. | 25 # questions. |
26 # | 26 # |
27 # ---------------------------------------------------------------------------------------------------- | 27 # ---------------------------------------------------------------------------------------------------- |
28 | 28 |
29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing, StringIO | 29 import os, sys, shutil, zipfile, tarfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing, StringIO, socket |
30 from os.path import join, exists, dirname, basename, getmtime | 30 from os.path import join, exists, dirname, basename, getmtime |
31 from argparse import ArgumentParser, RawDescriptionHelpFormatter, REMAINDER | 31 from argparse import ArgumentParser, RawDescriptionHelpFormatter, REMAINDER |
32 from outputparser import OutputParser, ValuesMatcher | 32 from outputparser import OutputParser, ValuesMatcher |
33 import mx | 33 import mx |
34 import xml.dom.minidom | 34 import xml.dom.minidom |
35 import sanitycheck | 35 import sanitycheck |
36 import itertools | 36 import itertools |
37 import json, textwrap | 37 import json, textwrap |
38 import fnmatch | |
38 | 39 |
39 # This works because when mx loads this file, it makes sure __file__ gets an absolute path | 40 # This works because when mx loads this file, it makes sure __file__ gets an absolute path |
40 _graal_home = dirname(dirname(__file__)) | 41 _graal_home = dirname(dirname(__file__)) |
41 | 42 |
42 """ Used to distinguish an exported GraalVM (see 'mx export'). """ | 43 """ Used to distinguish an exported GraalVM (see 'mx export'). """ |
160 rmIfExists(join(_graal_home, 'build-nograal')) | 161 rmIfExists(join(_graal_home, 'build-nograal')) |
161 rmIfExists(_jdksDir()) | 162 rmIfExists(_jdksDir()) |
162 rmIfExists(mx.distribution('GRAAL').path) | 163 rmIfExists(mx.distribution('GRAAL').path) |
163 | 164 |
164 def export(args): | 165 def export(args): |
165 """create a GraalVM zip file for distribution""" | 166 """create archives of builds split by vmbuild and vm""" |
166 | 167 |
167 parser = ArgumentParser(prog='mx export') | 168 parser = ArgumentParser(prog='mx export') |
168 parser.add_argument('--omit-vm-build', action='store_false', dest='vmbuild', help='omit VM build step') | |
169 parser.add_argument('--omit-dist-init', action='store_false', dest='distInit', help='omit class files and IDE configurations from distribution') | |
170 parser.add_argument('zipfile', nargs=REMAINDER, metavar='zipfile') | |
171 | |
172 args = parser.parse_args(args) | 169 args = parser.parse_args(args) |
173 | 170 |
174 tmp = tempfile.mkdtemp(prefix='tmp', dir=_graal_home) | 171 # collect data about export |
175 if args.vmbuild: | 172 infos = dict() |
176 # Make sure the product VM binary is up to date | 173 infos['timestamp'] = time.time() |
177 with VM(vmbuild='product'): | 174 |
178 build([]) | 175 hgcfg = mx.HgConfig() |
179 | 176 hgcfg.check() |
180 mx.log('Copying Java sources and mx files...') | 177 infos['revision'] = hgcfg.tip('.') + ('+' if hgcfg.isDirty('.') else '') |
181 mx.run(('hg archive -I graal -I mx -I mxtool -I mx.sh ' + tmp).split()) | 178 # TODO: infos['repository'] |
182 | 179 |
183 # Copy the GraalVM JDK | 180 infos['jdkversion'] = str(mx.java().version) |
184 mx.log('Copying GraalVM JDK...') | 181 |
185 src = _jdk() | 182 infos['architecture'] = _arch() |
186 dst = join(tmp, basename(src)) | 183 infos['platform'] = mx.get_os() |
187 shutil.copytree(src, dst) | 184 |
188 zfName = join(_graal_home, 'graalvm-' + mx.get_os() + '.zip') | 185 if mx.get_os != 'windows': |
189 zf = zipfile.ZipFile(zfName, 'w') | 186 pass |
190 for root, _, files in os.walk(tmp): | 187 # infos['ccompiler'] |
191 for f in files: | 188 # infos['linker'] |
192 name = join(root, f) | 189 |
193 arcname = name[len(tmp) + 1:] | 190 infos['hostname'] = socket.gethostname() |
194 zf.write(join(tmp, name), arcname) | 191 |
195 | 192 def _writeJson(suffix, properties): |
196 # create class files and IDE configurations | 193 d = infos.copy() |
197 if args.distInit: | 194 for k, v in properties.iteritems(): |
198 mx.log('Creating class files...') | 195 assert not d.has_key(k) |
199 mx.run('mx build'.split(), cwd=tmp) | 196 d[k] = v |
200 mx.log('Creating IDE configurations...') | 197 |
201 mx.run('mx ideinit'.split(), cwd=tmp) | 198 jsonFileName = 'export-' + suffix + '.json' |
202 | 199 with open(jsonFileName, 'w') as f: |
203 # clean up temp directory | 200 print >> f, json.dumps(d) |
204 mx.log('Cleaning up...') | 201 return jsonFileName |
205 shutil.rmtree(tmp) | 202 |
206 | 203 |
207 mx.log('Created distribution in ' + zfName) | 204 def _genFileName(archivtype, middle): |
205 idPrefix = infos['revision'] + '_' | |
206 idSuffix = '.tar.gz' | |
207 return join(_graal_home, "graalvm_" + archivtype + "_" + idPrefix + middle + idSuffix) | |
208 | |
209 def _genFileArchPlatformName(archivtype, middle): | |
210 return _genFileName(archivtype, infos['platform'] + '_' + infos['architecture'] + '_' + middle) | |
211 | |
212 | |
213 # archive different build types of hotspot | |
214 for vmBuild in _vmbuildChoices: | |
215 jdkpath = join(_jdksDir(), vmBuild) | |
216 if not exists(jdkpath): | |
217 mx.logv("skipping " + vmBuild) | |
218 continue | |
219 | |
220 tarName = _genFileArchPlatformName('basejdk', vmBuild) | |
221 mx.logv("creating basejdk " + tarName) | |
222 vmSet = set() | |
223 with tarfile.open(tarName, 'w:gz') as tar: | |
224 for root, _, files in os.walk(jdkpath): | |
225 if basename(root) in _vmChoices.keys(): | |
226 # TODO: add some assert to check path assumption | |
227 vmSet.add(root) | |
228 continue | |
229 | |
230 for f in files: | |
231 name = join(root, f) | |
232 # print name | |
233 tar.add(name, name) | |
234 | |
235 n = _writeJson("basejdk-" + vmBuild, {'vmbuild' : vmBuild}) | |
236 tar.add(n, n) | |
237 | |
238 # create a separate archive for each VM | |
239 for vm in vmSet: | |
240 bVm = basename(vm) | |
241 vmTarName = _genFileArchPlatformName('vm', vmBuild + '_' + bVm) | |
242 mx.logv("creating vm " + vmTarName) | |
243 | |
244 debugFiles = set() | |
245 with tarfile.open(vmTarName, 'w:gz') as tar: | |
246 for root, _, files in os.walk(vm): | |
247 for f in files: | |
248 # TODO: mac, windows, solaris? | |
249 if any(map(f.endswith, [".debuginfo"])): | |
250 debugFiles.add(f) | |
251 else: | |
252 name = join(root, f) | |
253 # print name | |
254 tar.add(name, name) | |
255 | |
256 n = _writeJson("vm-" + vmBuild + "-" + bVm, {'vmbuild' : vmBuild, 'vm' : bVm}) | |
257 tar.add(n, n) | |
258 | |
259 if len(debugFiles) > 0: | |
260 debugTarName = _genFileArchPlatformName('debugfilesvm', vmBuild + '_' + bVm) | |
261 mx.logv("creating debugfilesvm " + debugTarName) | |
262 with tarfile.open(debugTarName, 'w:gz') as tar: | |
263 for f in debugFiles: | |
264 name = join(root, f) | |
265 # print name | |
266 tar.add(name, name) | |
267 | |
268 n = _writeJson("debugfilesvm-" + vmBuild + "-" + bVm, {'vmbuild' : vmBuild, 'vm' : bVm}) | |
269 tar.add(n, n) | |
270 | |
271 # graal directory | |
272 graalDirTarName = _genFileName('classfiles', 'javac') | |
273 mx.logv("creating graal " + graalDirTarName) | |
274 with tarfile.open(graalDirTarName, 'w:gz') as tar: | |
275 for root, _, files in os.walk("graal"): | |
276 for f in [f for f in files if not f.endswith('.java')]: | |
277 name = join(root, f) | |
278 # print name | |
279 tar.add(name, name) | |
280 | |
281 n = _writeJson("graal", {'javacompiler' : 'javac'}) | |
282 tar.add(n, n) | |
283 | |
208 | 284 |
209 def _run_benchmark(args, availableBenchmarks, runBenchmark): | 285 def _run_benchmark(args, availableBenchmarks, runBenchmark): |
210 | 286 |
211 vmOpts, benchmarksAndOptions = _extract_VM_args(args, useDoubleDash=availableBenchmarks is None) | 287 vmOpts, benchmarksAndOptions = _extract_VM_args(args, useDoubleDash=availableBenchmarks is None) |
212 | 288 |
859 if not found: | 935 if not found: |
860 mx.log('warning: no tests matched by substring "' + t) | 936 mx.log('warning: no tests matched by substring "' + t) |
861 projectscp = mx.classpath(projs) | 937 projectscp = mx.classpath(projs) |
862 | 938 |
863 if whitelist: | 939 if whitelist: |
864 classes = list(set(classes) & set(whitelist)) | 940 classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] |
865 | 941 |
866 if len(classes) != 0: | 942 if len(classes) != 0: |
867 f_testfile = open(testfile, 'w') | 943 f_testfile = open(testfile, 'w') |
868 for c in classes: | 944 for c in classes: |
869 f_testfile.write(c + '\n') | 945 f_testfile.write(c + '\n') |
903 os.remove(testfile) | 979 os.remove(testfile) |
904 | 980 |
905 _unittestHelpSuffix = """ | 981 _unittestHelpSuffix = """ |
906 Unittest options: | 982 Unittest options: |
907 | 983 |
908 --short-only run short testcases only | 984 --whitelist run only testcases which are included |
909 --long-only run long testcases only | 985 in the given whitelist |
910 --baseline-whitelist run only testcases which are known to | |
911 work with the baseline compiler | |
912 | 986 |
913 To avoid conflicts with VM options '--' can be used as delimiter. | 987 To avoid conflicts with VM options '--' can be used as delimiter. |
914 | 988 |
915 If filters are supplied, only tests whose fully qualified name | 989 If filters are supplied, only tests whose fully qualified name |
916 includes a filter as a substring are run. | 990 includes a filter as a substring are run. |
943 description='run the JUnit tests', | 1017 description='run the JUnit tests', |
944 add_help=False, | 1018 add_help=False, |
945 formatter_class=RawDescriptionHelpFormatter, | 1019 formatter_class=RawDescriptionHelpFormatter, |
946 epilog=_unittestHelpSuffix, | 1020 epilog=_unittestHelpSuffix, |
947 ) | 1021 ) |
948 group = parser.add_mutually_exclusive_group() | 1022 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>') |
949 group.add_argument('--short-only', action='store_true', help='run short testcases only') | |
950 group.add_argument('--long-only', action='store_true', help='run long testcases only') | |
951 parser.add_argument('--baseline-whitelist', action='store_true', help='run baseline testcases only') | |
952 | 1023 |
953 ut_args = [] | 1024 ut_args = [] |
954 delimiter = False | 1025 delimiter = False |
955 # check for delimiter | 1026 # check for delimiter |
956 while len(args) > 0: | 1027 while len(args) > 0: |
966 else: | 1037 else: |
967 # parse all know arguments | 1038 # parse all know arguments |
968 parsed_args, args = parser.parse_known_args(ut_args) | 1039 parsed_args, args = parser.parse_known_args(ut_args) |
969 | 1040 |
970 whitelist = None | 1041 whitelist = None |
971 if parsed_args.baseline_whitelist: | 1042 if parsed_args.whitelist: |
972 baseline_whitelist_file = 'test/baseline_whitelist.txt' | |
973 try: | 1043 try: |
974 with open(join(_graal_home, baseline_whitelist_file)) as fp: | 1044 with open(join(_graal_home, parsed_args.whitelist)) as fp: |
975 whitelist = [l.rstrip() for l in fp.readlines()] | 1045 whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] |
976 except IOError: | 1046 except IOError: |
977 mx.log('warning: could not read baseline whitelist: ' + baseline_whitelist_file) | 1047 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) |
978 | 1048 |
979 if parsed_args.long_only: | 1049 _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist) |
980 annotations = ['@LongTest', '@Parameters'] | |
981 elif parsed_args.short_only: | |
982 annotations = ['@Test'] | |
983 else: | |
984 annotations = ['@Test', '@LongTest', '@Parameters'] | |
985 | |
986 _unittest(args, annotations, whitelist=whitelist) | |
987 | 1050 |
988 def shortunittest(args): | 1051 def shortunittest(args): |
989 """alias for 'unittest --short-only'{0}""" | 1052 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" |
990 | 1053 |
991 args.insert(0, '--short-only') | 1054 args = ['--whitelist', 'test/whitelist_shortunittest.txt'] + args |
992 unittest(args) | |
993 | |
994 def longunittest(args): | |
995 """alias for 'unittest --long-only'{0}""" | |
996 | |
997 args.insert(0, '--long-only') | |
998 unittest(args) | 1055 unittest(args) |
999 | 1056 |
1000 def buildvms(args): | 1057 def buildvms(args): |
1001 """build one or more VMs in various configurations""" | 1058 """build one or more VMs in various configurations""" |
1002 | 1059 |
1102 with VM('server', 'product'): # hosted mode | 1159 with VM('server', 'product'): # hosted mode |
1103 t = Task('UnitTests:hosted-product') | 1160 t = Task('UnitTests:hosted-product') |
1104 unittest([]) | 1161 unittest([]) |
1105 tasks.append(t.stop()) | 1162 tasks.append(t.stop()) |
1106 | 1163 |
1164 with VM('server', 'product'): # hosted mode | |
1165 t = Task('UnitTests-BaselineCompiler:hosted-product') | |
1166 unittest(['--whitelist', 'test/whitelist_baseline.txt', '-G:+UseBaselineCompiler']) | |
1167 tasks.append(t.stop()) | |
1168 | |
1107 for vmbuild in ['fastdebug', 'product']: | 1169 for vmbuild in ['fastdebug', 'product']: |
1108 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild) + sanitycheck.getScalaDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): | 1170 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild) + sanitycheck.getScalaDacapos(level=sanitycheck.SanityCheckLevel.Gate, gateBuildLevel=vmbuild): |
1109 t = Task(str(test) + ':' + vmbuild) | 1171 t = Task(str(test) + ':' + vmbuild) |
1110 if not test.test('graal'): | 1172 if not test.test('graal'): |
1111 t.abort(test.name + ' Failed') | 1173 t.abort(test.name + ' Failed') |
1304 executable = join(libpath, 'c1visualizer', 'bin', 'c1visualizer.exe') | 1366 executable = join(libpath, 'c1visualizer', 'bin', 'c1visualizer.exe') |
1305 else: | 1367 else: |
1306 executable = join(libpath, 'c1visualizer', 'bin', 'c1visualizer') | 1368 executable = join(libpath, 'c1visualizer', 'bin', 'c1visualizer') |
1307 | 1369 |
1308 archive = join(libpath, 'c1visualizer_2014-04-22.zip') | 1370 archive = join(libpath, 'c1visualizer_2014-04-22.zip') |
1309 if not exists(executable): | 1371 if not exists(executable) or not exists(archive): |
1310 if not exists(archive): | 1372 if not exists(archive): |
1311 mx.download(archive, ['https://java.net/downloads/c1visualizer/c1visualizer_2014-04-22.zip']) | 1373 mx.download(archive, ['https://java.net/downloads/c1visualizer/c1visualizer_2014-04-22.zip']) |
1312 zf = zipfile.ZipFile(archive, 'r') | 1374 zf = zipfile.ZipFile(archive, 'r') |
1313 zf.extractall(libpath) | 1375 zf.extractall(libpath) |
1314 | 1376 |
1721 | 1783 |
1722 def trufflejar(args=None): | 1784 def trufflejar(args=None): |
1723 """make truffle.jar""" | 1785 """make truffle.jar""" |
1724 | 1786 |
1725 # Test with the built classes | 1787 # Test with the built classes |
1726 _unittest(["com.oracle.truffle.api.test", "com.oracle.truffle.api.dsl.test"], ['@Test', '@LongTest', '@Parameters']) | 1788 _unittest(["com.oracle.truffle.api.test", "com.oracle.truffle.api.dsl.test"], ['@Test', '@Parameters']) |
1727 | 1789 |
1728 # We use the DSL processor as the starting point for the classpath - this | 1790 # We use the DSL processor as the starting point for the classpath - this |
1729 # therefore includes the DSL processor, the DSL and the API. | 1791 # therefore includes the DSL processor, the DSL and the API. |
1730 packagejar(mx.classpath("com.oracle.truffle.dsl.processor").split(os.pathsep), "truffle.jar", None, "com.oracle.truffle.dsl.processor.TruffleProcessor") | 1792 packagejar(mx.classpath("com.oracle.truffle.dsl.processor").split(os.pathsep), "truffle.jar", None, "com.oracle.truffle.dsl.processor.TruffleProcessor") |
1731 | 1793 |
1732 # Test with the JAR | 1794 # Test with the JAR |
1733 _unittest(["com.oracle.truffle.api.test", "com.oracle.truffle.api.dsl.test"], ['@Test', '@LongTest', '@Parameters'], "truffle.jar:") | 1795 _unittest(["com.oracle.truffle.api.test", "com.oracle.truffle.api.dsl.test"], ['@Test', '@Parameters'], "truffle.jar:") |
1734 | 1796 |
1735 | 1797 |
1736 def isGraalEnabled(vm): | 1798 def isGraalEnabled(vm): |
1737 return vm != 'original' and not vm.endswith('nograal') | 1799 return vm != 'original' and not vm.endswith('nograal') |
1738 | 1800 |
1951 'specjbb2013': [specjbb2013, '[VM options] [-- [SPECjbb2013 options]]'], | 2013 'specjbb2013': [specjbb2013, '[VM options] [-- [SPECjbb2013 options]]'], |
1952 'specjbb2005': [specjbb2005, '[VM options] [-- [SPECjbb2005 options]]'], | 2014 'specjbb2005': [specjbb2005, '[VM options] [-- [SPECjbb2005 options]]'], |
1953 'gate' : [gate, '[-options]'], | 2015 'gate' : [gate, '[-options]'], |
1954 'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'], | 2016 'bench' : [bench, '[-resultfile file] [all(default)|dacapo|specjvm2008|bootstrap]'], |
1955 'unittest' : [unittest, '[unittest options] [--] [VM options] [filters...]', _unittestHelpSuffix], | 2017 'unittest' : [unittest, '[unittest options] [--] [VM options] [filters...]', _unittestHelpSuffix], |
1956 'longunittest' : [longunittest, '[unittest options] [--] [VM options] [filters...]', _unittestHelpSuffix], | |
1957 'makejmhdeps' : [makejmhdeps, ''], | 2018 'makejmhdeps' : [makejmhdeps, ''], |
1958 'shortunittest' : [shortunittest, '[unittest options] [--] [VM options] [filters...]', _unittestHelpSuffix], | 2019 'shortunittest' : [shortunittest, '[unittest options] [--] [VM options] [filters...]', _unittestHelpSuffix], |
1959 'jacocoreport' : [jacocoreport, '[output directory]'], | 2020 'jacocoreport' : [jacocoreport, '[output directory]'], |
1960 'site' : [site, '[-options]'], | 2021 'site' : [site, '[-options]'], |
1961 'vm': [vm, '[-options] class [args...]'], | 2022 'vm': [vm, '[-options] class [args...]'], |