Mercurial > hg > graal-compiler
changeset 21603:4437f0da4b26
handle graal.jar that has already had Graal.class patched
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 29 May 2015 16:24:25 +0200 |
parents | 250fbc03954a |
children | 93f282187d90 |
files | mx/mx_graal.py |
diffstat | 1 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/mx/mx_graal.py Fri May 29 16:15:57 2015 +0200 +++ b/mx/mx_graal.py Fri May 29 16:24:25 2015 +0200 @@ -677,16 +677,23 @@ Patches the constant "@@graal.version@@" in the constant pool of Graal.class with the computed Graal version string. """ + zf = zipfile.ZipFile(dist.path, 'r') + graalClassfilePath = 'com/oracle/graal/api/runtime/Graal.class' + graalClassfile = zf.read(graalClassfilePath) + versionSpec = '{:' + str(len('@@graal.version@@')) + '}' + versionStr = versionSpec.format(graal_version()) + if '@@graal.version@@' not in graalClassfile: + assert versionStr in graalClassfile, 'could not find "@@graal.version@@" or "' + versionStr + '" constant in ' + dist.path + '!' + graalClassfilePath + zf.close() + return False + zfOutFd, zfOutPath = tempfile.mkstemp(suffix='', prefix=basename(dist.path) + '.', dir=dirname(dist.path)) zfOut = zipfile.ZipFile(zfOutPath, 'w') - zf = zipfile.ZipFile(dist.path, 'r') for zi in zf.infolist(): - data = zf.read(zi) - if zi.filename == 'com/oracle/graal/api/runtime/Graal.class': - versionSpec = '{:' + str(len('@@graal.version@@')) + '}' - versionStr = versionSpec.format(graal_version()) - #assert '@@graal.version@@' in data, 'could not find "@@graal.version@@" constant in ' + dist.path + '!' + zi.filename - data = data.replace('@@graal.version@@', versionStr) + if zi.filename == graalClassfilePath: + data = graalClassfile.replace('@@graal.version@@', versionStr) + else: + data = zf.read(zi) zfOut.writestr(zi, data) zfOut.close() os.close(zfOutFd)