Mercurial > hg > truffle
comparison mx/commands.py @ 4156:843c8d6720da
Added 'export' command for creating a GraalVM zip file distribution without the Mercurial data or VM sources.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 21 Dec 2011 14:54:26 +0100 |
parents | 394404b2d9bd |
children | b26279781d95 |
comparison
equal
deleted
inserted
replaced
4155:394404b2d9bd | 4156:843c8d6720da |
---|---|
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, StringIO | 29 import os, sys, shutil, StringIO, zipfile, tempfile |
30 from os.path import join, exists, dirname, isfile, isdir, isabs | 30 from os.path import join, exists, dirname, isdir, isabs, basename |
31 from argparse import ArgumentParser, REMAINDER | |
31 import mx | 32 import mx |
32 import sanitycheck | 33 import sanitycheck |
33 | 34 |
34 _graal_home = dirname(dirname(__file__)) | 35 _graal_home = dirname(dirname(__file__)) |
36 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) | |
35 _vmbuild = 'product' | 37 _vmbuild = 'product' |
36 | 38 |
37 def clean(args): | 39 def clean(args): |
38 """cleans the GraalVM source tree""" | 40 """cleans the GraalVM source tree""" |
39 mx.clean(args) | 41 mx.clean(args) |
40 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16') | 42 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16') |
41 mx.run([mx.gmake_cmd(), 'clean'], cwd=join(_graal_home, 'make')) | 43 mx.run([mx.gmake_cmd(), 'clean'], cwd=join(_graal_home, 'make')) |
44 | |
45 def export(args): | |
46 """create a GraalVM zip file for distribution""" | |
47 | |
48 parser = ArgumentParser(prog='mx export'); | |
49 parser.add_argument('--omit-vm-build', action='store_false', dest='vmbuild', help='omit VM build step') | |
50 parser.add_argument('--omit-dist-init', action='store_false', dest='distInit', help='omit class files and IDE configurations from distribution') | |
51 parser.add_argument('zipfile', nargs=REMAINDER, metavar='zipfile') | |
52 | |
53 args = parser.parse_args(args) | |
54 | |
55 tmp = tempfile.mkdtemp(prefix='tmp', dir=_graal_home) | |
56 if args.vmbuild: | |
57 # Make sure the product VM binary is up to date | |
58 build(['product']) | |
59 | |
60 mx.log('Copying Java sources and mx files...') | |
61 mx.run(('hg archive -I graal -I mx -I mxtool -I mx.sh ' + tmp).split()) | |
62 | |
63 # Copy the GraalVM JDK | |
64 mx.log('Copying GraalVM JDK...') | |
65 src = _jdk() | |
66 dst = join(tmp, basename(src)) | |
67 shutil.copytree(src, dst) | |
68 zfName = join(_graal_home, 'graalvm-' + mx.get_os() + '.zip') | |
69 zf = zipfile.ZipFile(zfName, 'w') | |
70 for root, _, files in os.walk(tmp): | |
71 for f in files: | |
72 name = join(root, f) | |
73 arcname = name[len(tmp) + 1:] | |
74 zf.write(join(tmp, name), arcname) | |
75 | |
76 # create class files and IDE configurations | |
77 if args.distInit: | |
78 mx.log('Creating class files...') | |
79 mx.run('mx build'.split(), cwd=tmp) | |
80 mx.log('Creating IDE configurations...') | |
81 mx.run('mx ideinit'.split(), cwd=tmp) | |
82 | |
83 # clean up temp directory | |
84 mx.log('Cleaning up...') | |
85 shutil.rmtree(tmp) | |
86 | |
87 mx.log('Created distribution in ' + zfName) | |
42 | 88 |
43 def example(args): | 89 def example(args): |
44 """run some or all Graal examples""" | 90 """run some or all Graal examples""" |
45 examples = { | 91 examples = { |
46 'safeadd': ['com.oracle.max.graal.examples.safeadd', 'com.oracle.max.graal.examples.safeadd.Main'], | 92 'safeadd': ['com.oracle.max.graal.examples.safeadd', 'com.oracle.max.graal.examples.safeadd.Main'], |
163 build = args.pop(0) | 209 build = args.pop(0) |
164 | 210 |
165 # Call mx.build to compile the Java sources | 211 # Call mx.build to compile the Java sources |
166 mx.build(args + ['--source', '1.7']) | 212 mx.build(args + ['--source', '1.7']) |
167 | 213 |
214 if not _vmSourcesAvailable: | |
215 return | |
216 | |
168 jdk = _jdk(build, True) | 217 jdk = _jdk(build, True) |
169 if build == 'debug': | 218 if build == 'debug': |
170 build = 'jvmg' | 219 build = 'jvmg' |
171 | 220 |
172 graalVmDir = join(jdk, 'jre', 'lib', 'amd64', 'graal') | 221 graalVmDir = join(jdk, 'jre', 'lib', 'amd64', 'graal') |
182 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) | 231 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) |
183 | 232 |
184 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None): | 233 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None): |
185 """run the GraalVM""" | 234 """run the GraalVM""" |
186 | 235 |
187 build = _vmbuild | 236 build = _vmbuild if _vmSourcesAvailable else 'product' |
188 if mx.java().debug: | 237 if mx.java().debug: |
189 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args | 238 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args |
190 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) | 239 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) |
191 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) | 240 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) |
192 | 241 |
193 def ideinit(args): | 242 def ideinit(args): |
194 """(re)generate Eclipse project configurations | 243 """(re)generate Eclipse project configurations""" |
195 | |
196 The exit code of this command reflects how many files were updated.""" | |
197 | 244 |
198 | 245 |
199 def println(out, obj): | 246 def println(out, obj): |
200 out.write(str(obj) + '\n') | 247 out.write(str(obj) + '\n') |
201 | 248 |
203 if p.native: | 250 if p.native: |
204 continue | 251 continue |
205 | 252 |
206 if not exists(p.dir): | 253 if not exists(p.dir): |
207 os.makedirs(p.dir) | 254 os.makedirs(p.dir) |
208 | |
209 changedFiles = 0 | |
210 | 255 |
211 out = StringIO.StringIO() | 256 out = StringIO.StringIO() |
212 | 257 |
213 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 258 println(out, '<?xml version="1.0" encoding="UTF-8"?>') |
214 println(out, '<classpath>') | 259 println(out, '<classpath>') |
240 else: | 285 else: |
241 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>') | 286 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>') |
242 | 287 |
243 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>') | 288 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>') |
244 println(out, '</classpath>') | 289 println(out, '</classpath>') |
245 | 290 mx.update_file(join(p.dir, '.classpath'), out.getvalue()) |
246 if mx.update_file(join(p.dir, '.classpath'), out.getvalue()): | |
247 changedFiles += 1 | |
248 | |
249 out.close() | 291 out.close() |
250 | 292 |
251 csConfig = join(mx.project(p.checkstyleProj).dir, '.checkstyle_checks.xml') | 293 csConfig = join(mx.project(p.checkstyleProj).dir, '.checkstyle_checks.xml') |
252 if exists(csConfig): | 294 if exists(csConfig): |
253 out = StringIO.StringIO() | 295 out = StringIO.StringIO() |
277 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir | 319 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir |
278 println(out, '\t\t<filter-data value="' + line + '"/>') | 320 println(out, '\t\t<filter-data value="' + line + '"/>') |
279 println(out, '\t</filter>') | 321 println(out, '\t</filter>') |
280 | 322 |
281 println(out, '</fileset-config>') | 323 println(out, '</fileset-config>') |
282 | 324 mx.update_file(dotCheckstyle, out.getvalue()) |
283 if mx.update_file(dotCheckstyle, out.getvalue()): | |
284 changedFiles += 1 | |
285 | |
286 out.close() | 325 out.close() |
287 | 326 |
288 | 327 |
289 out = StringIO.StringIO() | 328 out = StringIO.StringIO() |
290 | 329 |
311 println(out, '\t\t<nature>org.eclipse.jdt.core.javanature</nature>') | 350 println(out, '\t\t<nature>org.eclipse.jdt.core.javanature</nature>') |
312 if exists(csConfig): | 351 if exists(csConfig): |
313 println(out, '\t\t<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>') | 352 println(out, '\t\t<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>') |
314 println(out, '\t</natures>') | 353 println(out, '\t</natures>') |
315 println(out, '</projectDescription>') | 354 println(out, '</projectDescription>') |
316 | 355 mx.update_file(join(p.dir, '.project'), out.getvalue()) |
317 if mx.update_file(join(p.dir, '.project'), out.getvalue()): | |
318 changedFiles += 1 | |
319 | |
320 out.close() | 356 out.close() |
321 | 357 |
322 out = StringIO.StringIO() | 358 out = StringIO.StringIO() |
323 | |
324 settingsDir = join(p.dir, ".settings") | 359 settingsDir = join(p.dir, ".settings") |
325 if not exists(settingsDir): | 360 if not exists(settingsDir): |
326 os.mkdir(settingsDir) | 361 os.mkdir(settingsDir) |
327 | 362 |
328 myDir = dirname(__file__) | 363 myDir = dirname(__file__) |
329 | 364 |
330 with open(join(myDir, 'org.eclipse.jdt.core.prefs')) as f: | 365 with open(join(myDir, 'org.eclipse.jdt.core.prefs')) as f: |
331 content = f.read() | 366 content = f.read() |
332 if mx.update_file(join(settingsDir, 'org.eclipse.jdt.core.prefs'), content): | 367 mx.update_file(join(settingsDir, 'org.eclipse.jdt.core.prefs'), content) |
333 changedFiles += 1 | |
334 | 368 |
335 with open(join(myDir, 'org.eclipse.jdt.ui.prefs')) as f: | 369 with open(join(myDir, 'org.eclipse.jdt.ui.prefs')) as f: |
336 content = f.read() | 370 content = f.read() |
337 if mx.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content): | 371 mx.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content) |
338 changedFiles += 1 | |
339 | |
340 if changedFiles != 0: | |
341 mx.abort(changedFiles) | |
342 | 372 |
343 def mx_init(): | 373 def mx_init(): |
344 _vmbuild = 'product' | 374 _vmbuild = 'product' |
345 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') | |
346 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM') | |
347 mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM') | |
348 mx.add_argument('--optimized', action='store_const', dest='vmbuild', const='optimized', help='select the optimized VM') | |
349 commands = { | 375 commands = { |
350 'build': [build, '[product|debug|fastdebug|optimized]'], | 376 'clean': [clean, ''], |
377 'build': [build, ''], | |
351 'dacapo': [dacapo, '[benchmark] [VM options]'], | 378 'dacapo': [dacapo, '[benchmark] [VM options]'], |
352 'example': [example, '[-v] example names...'], | 379 'example': [example, '[-v] example names...'], |
353 'clean': [clean, ''], | |
354 'vm': [vm, '[-options] class [args...]'], | 380 'vm': [vm, '[-options] class [args...]'], |
355 'ideinit': [ideinit, ''], | 381 'ideinit': [ideinit, ''] |
356 'sanity' : [sanitychecks, ''], | |
357 } | 382 } |
383 | |
384 if (_vmSourcesAvailable): | |
385 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') | |
386 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM') | |
387 mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM') | |
388 mx.add_argument('--optimized', action='store_const', dest='vmbuild', const='optimized', help='select the optimized VM') | |
389 | |
390 commands.update({ | |
391 'export': [export, '[-options] [zipfile]'], | |
392 'build': [build, '[product|debug|fastdebug|optimized]'], | |
393 'sanity' : [sanitychecks, ''], | |
394 }) | |
395 | |
358 mx.commands.update(commands) | 396 mx.commands.update(commands) |
359 | 397 |
360 def mx_post_parse_cmd_line(opts): | 398 def mx_post_parse_cmd_line(opts): |
361 version = mx.java().version | 399 version = mx.java().version |
362 parts = version.split('.') | 400 parts = version.split('.') |
364 assert parts[0] == '1' | 402 assert parts[0] == '1' |
365 major = int(parts[1]) | 403 major = int(parts[1]) |
366 if not major >= 7: | 404 if not major >= 7: |
367 mx.abort('Requires Java version 1.7 or greater, got version ' + version) | 405 mx.abort('Requires Java version 1.7 or greater, got version ' + version) |
368 | 406 |
369 | 407 if (_vmSourcesAvailable): |
370 global _vmbuild | 408 global _vmbuild |
371 if not opts.vmbuild is None: | 409 if not opts.vmbuild is None: |
372 _vmbuild = opts.vmbuild | 410 _vmbuild = opts.vmbuild |