changeset 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 d5e65a244f7d
children a1dae6b6d6d2
files mx/mx_graal.py mx/projects
diffstat 2 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mx/mx_graal.py	Thu Dec 12 09:47:11 2013 +0100
+++ b/mx/mx_graal.py	Thu Dec 12 20:09:10 2013 +0000
@@ -1346,6 +1346,12 @@
     vmArgs, slArgs = _extract_VM_args(args)
     vm(vmArgs + ['-cp', mx.classpath("com.oracle.truffle.sl"), "com.oracle.truffle.sl.SimpleLanguage"] + slArgs)
 
+def trufflejar(args=None):
+    """make truffle.jar"""
+    # We use the DSL processor as the starting point for the classpath - this
+    # therefore includes the DSL processor, the DSL and the API.
+    packagejar(mx.classpath("com.oracle.truffle.dsl.processor").split(os.pathsep), "truffle.jar", None)
+
 def isGraalEnabled(vm):
     return vm != 'original' and not vm.endswith('nograal')
 
@@ -1390,7 +1396,8 @@
         'vmfg': [vmfg, '[-options] class [args...]'],
         'deoptalot' : [deoptalot, '[n]'],
         'longtests' : [longtests, ''],
-        'sl' : [sl, '[SL args|@VM options]']
+        'sl' : [sl, '[SL args|@VM options]'],
+        'trufflejar' : [trufflejar, ''],
     }
 
     mx.add_argument('--jacoco', help='instruments com.oracle.* classes using JaCoCo', default='off', choices=['off', 'on', 'append'])
@@ -1436,3 +1443,35 @@
     _vm_prefix = opts.vm_prefix
 
     mx.distribution('GRAAL').add_update_listener(_installGraalJarInJdks)
+
+def packagejar(classpath, outputFile, mainClass):
+    prefix = '' if mx.get_os() != 'windows' else '\\??\\' # long file name hack
+    print "creating", outputFile
+    filecount, totalsize = 0, 0
+    with zipfile.ZipFile(outputFile, 'w', zipfile.ZIP_DEFLATED) as zf:
+        manifest = "Manifest-Version: 1.0\n"
+        if mainClass != None:
+            manifest += "Main-Class: %s\n\n" % (mainClass)
+        zf.writestr("META-INF/MANIFEST.MF", manifest)
+        for cp in classpath:
+            print "+", cp
+            if cp.endswith(".jar"):
+                with zipfile.ZipFile(cp, 'r') as jar:
+                    for arcname in jar.namelist():
+                        if arcname.endswith('/') or arcname == 'META-INF/MANIFEST.MF' or arcname.endswith('.java') or arcname.lower().startswith("license") or arcname in [".project", ".classpath"]:
+                            continue
+                        zf.writestr(arcname, jar.read(arcname))
+            else:
+                for root, _, files in os.walk(cp):
+                    for f in files:
+                        fullname = os.path.join(root, f)
+                        arcname = fullname[len(cp)+1:].replace('\\', '/')
+                        if f.endswith(".class"):
+                            zf.write(prefix + fullname, arcname)
+
+        for zi in zf.infolist():
+            filecount += 1
+            totalsize += zi.file_size
+    print "%d files (total size: %.2f kB, jar size: %.2f kB)" % (filecount, totalsize / 1e3, os.path.getsize(outputFile) / 1e3)
+    mx.run([mx.exe_suffix(join(mx.java().jdk, 'bin', 'pack200')), '-r', '-G', outputFile])
+    print "repacked jar size: %.2f kB" % (os.path.getsize(outputFile) / 1e3)
--- a/mx/projects	Thu Dec 12 09:47:11 2013 +0100
+++ b/mx/projects	Thu Dec 12 20:09:10 2013 +0000
@@ -570,7 +570,6 @@
 project@com.oracle.graal.compiler.hsail.test@checkstyle=com.oracle.graal.graph
 project@com.oracle.graal.compiler.hsail.test@javaCompliance=1.7
 
-
 # graal.asm.hsail
 project@com.oracle.graal.asm.hsail@subDir=graal
 project@com.oracle.graal.asm.hsail@sourceDirs=src