Mercurial > hg > truffle
comparison mx/mx_graal.py @ 21098:5d09e1eda922
Only extract service files for Graal services
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Thu, 23 Apr 2015 13:31:20 +0200 |
parents | 2ee48d02afe3 |
children | 3f51d02e536f |
comparison
equal
deleted
inserted
replaced
21097:391f94d4d23f | 21098:5d09e1eda922 |
---|---|
592 shutil.copyfile(src, tmp) | 592 shutil.copyfile(src, tmp) |
593 os.close(fd) | 593 os.close(fd) |
594 shutil.move(tmp, dstLib) | 594 shutil.move(tmp, dstLib) |
595 os.chmod(dstLib, permissions) | 595 os.chmod(dstLib, permissions) |
596 | 596 |
597 def _isGraalService(className, graalJars): | |
598 javap = mx.java().javap | |
599 output = subprocess.check_output([javap, '-cp', os.pathsep.join(graalJars), className], stderr=subprocess.STDOUT) | |
600 lines = output.split(os.linesep) | |
601 decl = 'public interface ' + className | |
602 for line in lines: | |
603 if line.startswith(decl): | |
604 declLine = line.strip() | |
605 break | |
606 if not declLine: | |
607 mx.abort('Could not find interface for service ' + className + ':\n' + output) | |
608 afterName = declLine[len(decl):] | |
609 if not afterName.startswith(' extends '): | |
610 return False | |
611 superInterfaces = afterName[len(' extends '):-len(' {')].split(',') | |
612 if 'com.oracle.graal.api.runtime.Service' in superInterfaces: | |
613 return True | |
614 for superInterface in superInterfaces: | |
615 if '<' in superInterface: | |
616 superInterface = superInterface[:superInterface.index('<')] | |
617 if _isGraalService(superInterface, graalJars): | |
618 return True | |
619 return False | |
620 | |
597 def _updateGraalServiceFiles(jdkDir): | 621 def _updateGraalServiceFiles(jdkDir): |
598 jreGraalDir = join(jdkDir, 'jre', 'lib', 'graal') | 622 jreGraalDir = join(jdkDir, 'jre', 'lib', 'graal') |
599 graalJars = [join(jreGraalDir, e) for e in os.listdir(jreGraalDir) if e.startswith('graal') and e.endswith('.jar')] | 623 graalJars = [join(jreGraalDir, e) for e in os.listdir(jreGraalDir) if e.startswith('graal') and e.endswith('.jar')] |
600 jreGraalServicesDir = join(jreGraalDir, 'services') | 624 jreGraalServicesDir = join(jreGraalDir, 'services') |
601 if exists(jreGraalServicesDir): | 625 if exists(jreGraalServicesDir): |
607 for member in zf.namelist(): | 631 for member in zf.namelist(): |
608 if not member.startswith('META-INF/services'): | 632 if not member.startswith('META-INF/services'): |
609 continue | 633 continue |
610 serviceName = basename(member) | 634 serviceName = basename(member) |
611 # we don't handle directories | 635 # we don't handle directories |
612 assert serviceName | 636 assert serviceName and member == 'META-INF/services/' + serviceName |
637 if not _isGraalService(serviceName, graalJars): | |
638 continue | |
613 target = join(jreGraalServicesDir, serviceName) | 639 target = join(jreGraalServicesDir, serviceName) |
614 lines = [] | 640 lines = [] |
615 with zf.open(member) as serviceFile: | 641 with zf.open(member) as serviceFile: |
616 lines.extend(serviceFile.readlines()) | 642 lines.extend(serviceFile.readlines()) |
617 if exists(target): | 643 if exists(target): |