Mercurial > hg > graal-compiler
comparison mx/mx_graal.py @ 15405:5dcf0ae606f3
mx: new export command
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Mon, 28 Apr 2014 12:07:49 +0200 |
parents | 27fa615f5a1c |
children | 5947bb02474f |
comparison
equal
deleted
inserted
replaced
15404:27fa615f5a1c | 15405:5dcf0ae606f3 |
---|---|
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 |
161 rmIfExists(join(_graal_home, 'build-nograal')) | 161 rmIfExists(join(_graal_home, 'build-nograal')) |
162 rmIfExists(_jdksDir()) | 162 rmIfExists(_jdksDir()) |
163 rmIfExists(mx.distribution('GRAAL').path) | 163 rmIfExists(mx.distribution('GRAAL').path) |
164 | 164 |
165 def export(args): | 165 def export(args): |
166 """create a GraalVM zip file for distribution""" | 166 """create archives of builds splitted by vmbuild and vm""" |
167 | 167 |
168 parser = ArgumentParser(prog='mx export') | 168 parser = ArgumentParser(prog='mx export') |
169 parser.add_argument('--omit-vm-build', action='store_false', dest='vmbuild', help='omit VM build step') | |
170 parser.add_argument('--omit-dist-init', action='store_false', dest='distInit', help='omit class files and IDE configurations from distribution') | |
171 parser.add_argument('zipfile', nargs=REMAINDER, metavar='zipfile') | |
172 | |
173 args = parser.parse_args(args) | 169 args = parser.parse_args(args) |
174 | 170 |
175 tmp = tempfile.mkdtemp(prefix='tmp', dir=_graal_home) | 171 # collect data about export |
176 if args.vmbuild: | 172 infos = dict() |
177 # Make sure the product VM binary is up to date | 173 infos['timestamp'] = time.time() |
178 with VM(build='product'): | 174 |
179 build([]) | 175 hgcfg = mx.HgConfig() |
180 | 176 hgcfg.check() |
181 mx.log('Copying Java sources and mx files...') | 177 infos['revision'] = hgcfg.tip('.') |
182 mx.run(('hg archive -I graal -I mx -I mxtool -I mx.sh ' + tmp).split()) | 178 infos['revision_dirty'] = hgcfg.isDirty('.') |
183 | 179 # TODO: infos['repository'] |
184 # Copy the GraalVM JDK | 180 |
185 mx.log('Copying GraalVM JDK...') | 181 infos['jdkversion'] = str(mx.java().version) |
186 src = _jdk() | 182 |
187 dst = join(tmp, basename(src)) | 183 infos['architecture'] = _arch() |
188 shutil.copytree(src, dst) | 184 infos['platform'] = mx.get_os() |
189 zfName = join(_graal_home, 'graalvm-' + mx.get_os() + '.zip') | 185 |
190 zf = zipfile.ZipFile(zfName, 'w') | 186 if mx.get_os != 'windows': |
191 for root, _, files in os.walk(tmp): | 187 pass |
192 for f in files: | 188 # infos['ccompiler'] |
193 name = join(root, f) | 189 # infos['linker'] |
194 arcname = name[len(tmp) + 1:] | 190 |
195 zf.write(join(tmp, name), arcname) | 191 infos['hostname'] = socket.gethostname() |
196 | 192 |
197 # create class files and IDE configurations | 193 def _writeJson(suffix, properties): |
198 if args.distInit: | 194 d = infos.copy() |
199 mx.log('Creating class files...') | 195 for k, v in properties.iteritems(): |
200 mx.run('mx build'.split(), cwd=tmp) | 196 assert not d.has_key(k) |
201 mx.log('Creating IDE configurations...') | 197 d[k] = v |
202 mx.run('mx ideinit'.split(), cwd=tmp) | 198 |
203 | 199 jsonFileName = 'export-' + suffix + '.json' |
204 # clean up temp directory | 200 with open(jsonFileName, 'w') as f: |
205 mx.log('Cleaning up...') | 201 print >> f, json.dumps(d) |
206 shutil.rmtree(tmp) | 202 return jsonFileName |
207 | 203 |
208 mx.log('Created distribution in ' + zfName) | 204 |
205 def _genFileName(archivtype, middle): | |
206 idPrefix = infos['revision'] + '_' | |
207 idSuffix = '.tar.gz' | |
208 return join(_graal_home, "graalvm_" + archivtype + "_" + idPrefix + middle + idSuffix) | |
209 | |
210 def _genFileArchPlatformName(archivtype, middle): | |
211 return _genFileName(archivtype, infos['platform'] + '_' + infos['architecture'] + '_' + middle) | |
212 | |
213 | |
214 # archive different build types of hotspot | |
215 for vmBuild in _vmbuildChoices: | |
216 jdkpath = join(_jdksDir(), vmBuild) | |
217 if not exists(jdkpath): | |
218 mx.logv("skipping " + vmBuild) | |
219 continue | |
220 | |
221 tarName = _genFileArchPlatformName('basejdk', vmBuild) | |
222 mx.logv("creating basejdk " + tarName) | |
223 vmSet = set() | |
224 with tarfile.open(tarName, 'w:gz') as tar: | |
225 for root, _, files in os.walk(jdkpath): | |
226 if basename(root) in _vmChoices.keys(): | |
227 # TODO: add some assert to check path assumption | |
228 vmSet.add(root) | |
229 continue | |
230 | |
231 for f in files: | |
232 name = join(root, f) | |
233 # print name | |
234 tar.add(name, name) | |
235 | |
236 n = _writeJson("basejdk-" + vmBuild, {'vmbuild' : vmBuild}) | |
237 tar.add(n, n) | |
238 | |
239 # create a separate archive for each VM | |
240 for vm in vmSet: | |
241 bVm = basename(vm) | |
242 vmTarName = _genFileArchPlatformName('vm', vmBuild + '_' + bVm) | |
243 mx.logv("creating vm " + vmTarName) | |
244 | |
245 debugFiles = set() | |
246 with tarfile.open(vmTarName, 'w:gz') as tar: | |
247 for root, _, files in os.walk(vm): | |
248 for f in files: | |
249 # TODO: mac, windows, solaris? | |
250 if any(map(f.endswith, [".debuginfo"])): | |
251 debugFiles.add(f) | |
252 else: | |
253 name = join(root, f) | |
254 # print name | |
255 tar.add(name, name) | |
256 | |
257 n = _writeJson("vm-" + vmBuild + "-" + bVm, {'vmbuild' : vmBuild, 'vm' : bVm}) | |
258 tar.add(n, n) | |
259 | |
260 if len(debugFiles) > 0: | |
261 debugTarName = _genFileArchPlatformName('debugfilesvm', vmBuild + '_' + bVm) | |
262 mx.logv("creating debugfilesvm " + debugTarName) | |
263 with tarfile.open(debugTarName, 'w:gz') as tar: | |
264 for f in debugFiles: | |
265 name = join(root, f) | |
266 # print name | |
267 tar.add(name, name) | |
268 | |
269 n = _writeJson("debugfilesvm-" + vmBuild + "-" + bVm, {'vmbuild' : vmBuild, 'vm' : bVm}) | |
270 tar.add(n, n) | |
271 | |
272 # graal directory | |
273 graalDirTarName = _genFileName('classfiles', 'javac') | |
274 mx.logv("creating graal " + graalDirTarName) | |
275 with tarfile.open(graalDirTarName, 'w:gz') as tar: | |
276 for root, _, files in os.walk("graal"): | |
277 for f in [f for f in files if not f.endswith('.java')]: | |
278 name = join(root, f) | |
279 # print name | |
280 tar.add(name, name) | |
281 | |
282 n = _writeJson("graal", {'javacompiler' : 'javac'}) | |
283 tar.add(n, n) | |
284 | |
209 | 285 |
210 def _run_benchmark(args, availableBenchmarks, runBenchmark): | 286 def _run_benchmark(args, availableBenchmarks, runBenchmark): |
211 | 287 |
212 vmOpts, benchmarksAndOptions = _extract_VM_args(args, useDoubleDash=availableBenchmarks is None) | 288 vmOpts, benchmarksAndOptions = _extract_VM_args(args, useDoubleDash=availableBenchmarks is None) |
213 | 289 |