comparison mx/mx_graal.py @ 21958:ab37091f0980

replaced class file patching with use of jre/lib/jvmci/graal.properties to set graal.version system property
author Doug Simon <doug.simon@oracle.com>
date Sat, 13 Jun 2015 00:58:03 +0200
parents 4fe034122fd3
children f15b1d92e34b
comparison
equal deleted inserted replaced
21957:555f788b964b 21958:ab37091f0980
604 jvmciJars = [join(jreJVMCIDir, e) for e in os.listdir(jreJVMCIDir) if e.endswith('.jar')] 604 jvmciJars = [join(jreJVMCIDir, e) for e in os.listdir(jreJVMCIDir) if e.endswith('.jar')]
605 jreJVMCIServicesDir = join(jreJVMCIDir, 'services') 605 jreJVMCIServicesDir = join(jreJVMCIDir, 'services')
606 jreJVMCIOptionsDir = join(jreJVMCIDir, 'options') 606 jreJVMCIOptionsDir = join(jreJVMCIDir, 'options')
607 _extractJVMCIFiles(_getJdkDeployedJars(jdkDir), jvmciJars, jreJVMCIServicesDir, jreJVMCIOptionsDir) 607 _extractJVMCIFiles(_getJdkDeployedJars(jdkDir), jvmciJars, jreJVMCIServicesDir, jreJVMCIOptionsDir)
608 608
609 def _patchGraalVersionConstant(dist): 609 def _updateGraalPropertiesFile(jreLibDir):
610 """ 610 """
611 Patches the constant "@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@" in the constant pool of Graal.class 611 Updates (or creates) 'jreLibDir'/jvmci/graal.properties to set/modify the
612 with the computed Graal version string. 612 graal.version property.
613 """ 613 """
614 zf = zipfile.ZipFile(dist.path, 'r') 614 version = graal_version()
615 graalClassfilePath = 'com/oracle/graal/api/runtime/Graal.class' 615 graalProperties = join(jreLibDir, 'jvmci', 'graal.properties')
616 try: 616 if not exists(graalProperties):
617 graalClassfile = zf.read(graalClassfilePath) 617 with open(graalProperties, 'w') as fp:
618 except KeyError: 618 print >> fp, 'graal.version=' + version
619 mx.log(graalClassfilePath + ' is not present in ' + dist.path) 619 else:
620 return 620 content = []
621 placeholder = '@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@' 621 with open(graalProperties) as fp:
622 placeholderLen = len(placeholder) 622 for line in fp:
623 versionSpec = '{:' + str(placeholderLen) + '}' 623 if line.startswith('graal.version='):
624 versionStr = versionSpec.format(graal_version()) 624 content.append('graal.version=' + version)
625 625 else:
626 if len(versionStr) > placeholderLen: 626 content.append(line.rstrip(os.linesep))
627 # Truncate the version string if necessary 627 with open(graalProperties, 'w') as fp:
628 assert versionStr.startswith('unknown'), versionStr 628 fp.write(os.linesep.join(content))
629 versionStr = versionStr[:placeholderLen]
630 if placeholder not in graalClassfile:
631 assert versionStr in graalClassfile, 'could not find "' + placeholder + '" or "' + versionStr + '" constant in ' + dist.path + '!' + graalClassfilePath
632 zf.close()
633 return False
634
635 zfOutFd, zfOutPath = tempfile.mkstemp(suffix='', prefix=basename(dist.path) + '.', dir=dirname(dist.path))
636 zfOut = zipfile.ZipFile(zfOutPath, 'w')
637 for zi in zf.infolist():
638 if zi.filename == graalClassfilePath:
639 data = graalClassfile.replace(placeholder, versionStr)
640 else:
641 data = zf.read(zi)
642 zfOut.writestr(zi, data)
643 zfOut.close()
644 os.close(zfOutFd)
645 zf.close()
646 shutil.move(zfOutPath, dist.path)
647 629
648 def _installDistInJdks(deployableDist): 630 def _installDistInJdks(deployableDist):
649 """ 631 """
650 Installs the jar(s) for a given Distribution into all existing JVMCI JDKs 632 Installs the jar(s) for a given Distribution into all existing JVMCI JDKs
651 """ 633 """
652 dist = mx.distribution(deployableDist.name) 634 dist = mx.distribution(deployableDist.name)
653 if dist.name == 'GRAAL':
654 _patchGraalVersionConstant(dist)
655
656 jdks = _jdksDir() 635 jdks = _jdksDir()
657 if exists(jdks): 636 if exists(jdks):
658 for e in os.listdir(jdks): 637 for e in os.listdir(jdks):
659 jdkDir = join(jdks, e) 638 jdkDir = join(jdks, e)
660 jreLibDir = join(jdkDir, 'jre', 'lib') 639 jreLibDir = join(jdkDir, 'jre', 'lib')
671 if dist.sourcesPath: 650 if dist.sourcesPath:
672 _copyToJdk(dist.sourcesPath, jdkDir) 651 _copyToJdk(dist.sourcesPath, jdkDir)
673 if deployableDist.usesJVMCIClassLoader: 652 if deployableDist.usesJVMCIClassLoader:
674 # deploy service files 653 # deploy service files
675 _updateJVMCIFiles(jdkDir) 654 _updateJVMCIFiles(jdkDir)
655 if dist.name == 'GRAAL':
656 _updateGraalPropertiesFile(jreLibDir)
676 657
677 def _getJdkDeployedJars(jdkDir): 658 def _getJdkDeployedJars(jdkDir):
678 """ 659 """
679 Gets jar paths for all deployed distributions in the context of 660 Gets jar paths for all deployed distributions in the context of
680 a given JDK directory. 661 a given JDK directory.
810 cached_graal_version = most_recent_tag_version 791 cached_graal_version = most_recent_tag_version
811 else: 792 else:
812 major, minor = map(int, most_recent_tag_version.split('.')) 793 major, minor = map(int, most_recent_tag_version.split('.'))
813 cached_graal_version = str(major) + '.' + str(minor + 1) + '-' + dev_suffix 794 cached_graal_version = str(major) + '.' + str(minor + 1) + '-' + dev_suffix
814 else: 795 else:
815 cached_graal_version = 'unknown-{0}'.format(platform.node()) 796 cached_graal_version = 'unknown-{0}-{1}'.format(platform.node(), time.strftime('%Y-%m-%d_%H-%M-%S_%Z'))
816 797
817 return cached_graal_version 798 return cached_graal_version
818 799
819 def build(args, vm=None): 800 def build(args, vm=None):
820 """build the VM binary 801 """build the VM binary