comparison mx/mx_graal.py @ 13303:d8692e751c65

Added trufflejar command, and abstracted packagejar.
author Chris Seaton <chris.seaton@oracle.com>
date Thu, 12 Dec 2013 20:09:10 +0000
parents 58d8de1f384b
children 30e57b49fdb1
comparison
equal deleted inserted replaced
13300:d5e65a244f7d 13303:d8692e751c65
1344 def sl(args): 1344 def sl(args):
1345 """run an SL program""" 1345 """run an SL program"""
1346 vmArgs, slArgs = _extract_VM_args(args) 1346 vmArgs, slArgs = _extract_VM_args(args)
1347 vm(vmArgs + ['-cp', mx.classpath("com.oracle.truffle.sl"), "com.oracle.truffle.sl.SimpleLanguage"] + slArgs) 1347 vm(vmArgs + ['-cp', mx.classpath("com.oracle.truffle.sl"), "com.oracle.truffle.sl.SimpleLanguage"] + slArgs)
1348 1348
1349 def trufflejar(args=None):
1350 """make truffle.jar"""
1351 # We use the DSL processor as the starting point for the classpath - this
1352 # therefore includes the DSL processor, the DSL and the API.
1353 packagejar(mx.classpath("com.oracle.truffle.dsl.processor").split(os.pathsep), "truffle.jar", None)
1354
1349 def isGraalEnabled(vm): 1355 def isGraalEnabled(vm):
1350 return vm != 'original' and not vm.endswith('nograal') 1356 return vm != 'original' and not vm.endswith('nograal')
1351 1357
1352 def site(args): 1358 def site(args):
1353 """create a website containing javadoc and the project dependency graph""" 1359 """create a website containing javadoc and the project dependency graph"""
1388 'vm': [vm, '[-options] class [args...]'], 1394 'vm': [vm, '[-options] class [args...]'],
1389 'vmg': [vmg, '[-options] class [args...]'], 1395 'vmg': [vmg, '[-options] class [args...]'],
1390 'vmfg': [vmfg, '[-options] class [args...]'], 1396 'vmfg': [vmfg, '[-options] class [args...]'],
1391 'deoptalot' : [deoptalot, '[n]'], 1397 'deoptalot' : [deoptalot, '[n]'],
1392 'longtests' : [longtests, ''], 1398 'longtests' : [longtests, ''],
1393 'sl' : [sl, '[SL args|@VM options]'] 1399 'sl' : [sl, '[SL args|@VM options]'],
1400 'trufflejar' : [trufflejar, ''],
1394 } 1401 }
1395 1402
1396 mx.add_argument('--jacoco', help='instruments com.oracle.* classes using JaCoCo', default='off', choices=['off', 'on', 'append']) 1403 mx.add_argument('--jacoco', help='instruments com.oracle.* classes using JaCoCo', default='off', choices=['off', 'on', 'append'])
1397 mx.add_argument('--vmcwd', dest='vm_cwd', help='current directory will be changed to <path> before the VM is executed', default=None, metavar='<path>') 1404 mx.add_argument('--vmcwd', dest='vm_cwd', help='current directory will be changed to <path> before the VM is executed', default=None, metavar='<path>')
1398 mx.add_argument('--installed-jdks', help='the base directory in which the JDKs cloned from $JAVA_HOME exist. ' + 1405 mx.add_argument('--installed-jdks', help='the base directory in which the JDKs cloned from $JAVA_HOME exist. ' +
1434 _installed_jdks = opts.installed_jdks 1441 _installed_jdks = opts.installed_jdks
1435 global _vm_prefix 1442 global _vm_prefix
1436 _vm_prefix = opts.vm_prefix 1443 _vm_prefix = opts.vm_prefix
1437 1444
1438 mx.distribution('GRAAL').add_update_listener(_installGraalJarInJdks) 1445 mx.distribution('GRAAL').add_update_listener(_installGraalJarInJdks)
1446
1447 def packagejar(classpath, outputFile, mainClass):
1448 prefix = '' if mx.get_os() != 'windows' else '\\??\\' # long file name hack
1449 print "creating", outputFile
1450 filecount, totalsize = 0, 0
1451 with zipfile.ZipFile(outputFile, 'w', zipfile.ZIP_DEFLATED) as zf:
1452 manifest = "Manifest-Version: 1.0\n"
1453 if mainClass != None:
1454 manifest += "Main-Class: %s\n\n" % (mainClass)
1455 zf.writestr("META-INF/MANIFEST.MF", manifest)
1456 for cp in classpath:
1457 print "+", cp
1458 if cp.endswith(".jar"):
1459 with zipfile.ZipFile(cp, 'r') as jar:
1460 for arcname in jar.namelist():
1461 if arcname.endswith('/') or arcname == 'META-INF/MANIFEST.MF' or arcname.endswith('.java') or arcname.lower().startswith("license") or arcname in [".project", ".classpath"]:
1462 continue
1463 zf.writestr(arcname, jar.read(arcname))
1464 else:
1465 for root, _, files in os.walk(cp):
1466 for f in files:
1467 fullname = os.path.join(root, f)
1468 arcname = fullname[len(cp)+1:].replace('\\', '/')
1469 if f.endswith(".class"):
1470 zf.write(prefix + fullname, arcname)
1471
1472 for zi in zf.infolist():
1473 filecount += 1
1474 totalsize += zi.file_size
1475 print "%d files (total size: %.2f kB, jar size: %.2f kB)" % (filecount, totalsize / 1e3, os.path.getsize(outputFile) / 1e3)
1476 mx.run([mx.exe_suffix(join(mx.java().jdk, 'bin', 'pack200')), '-r', '-G', outputFile])
1477 print "repacked jar size: %.2f kB" % (os.path.getsize(outputFile) / 1e3)