# HG changeset patch # User Doug Simon # Date 1434149883 -7200 # Node ID ab37091f098024b80fce55893b090314628ea115 # Parent 555f788b964ba248222c12c9c7718d9c3135112e replaced class file patching with use of jre/lib/jvmci/graal.properties to set graal.version system property diff -r 555f788b964b -r ab37091f0980 graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java --- a/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java Sat Jun 13 00:25:30 2015 +0200 +++ b/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java Sat Jun 13 00:58:03 2015 +0200 @@ -39,9 +39,7 @@ GraalRuntimeAccess access = Services.loadSingle(GraalRuntimeAccess.class, false); if (access != null) { GraalRuntime rt = access.getRuntime(); - // The constant is patched in-situ by the build system - System.setProperty("graal.version", "@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@".trim()); - assert !System.getProperty("graal.version").startsWith("@@@@@@@@@@@@@@@@") && !System.getProperty("graal.version").endsWith("@@@@@@@@@@@@@@@@") : "Graal version string constant was not patched by build system"; + assert rt != null; return rt; } return new InvalidGraalRuntime(); diff -r 555f788b964b -r ab37091f0980 mx/mx_graal.py --- a/mx/mx_graal.py Sat Jun 13 00:25:30 2015 +0200 +++ b/mx/mx_graal.py Sat Jun 13 00:58:03 2015 +0200 @@ -606,53 +606,32 @@ jreJVMCIOptionsDir = join(jreJVMCIDir, 'options') _extractJVMCIFiles(_getJdkDeployedJars(jdkDir), jvmciJars, jreJVMCIServicesDir, jreJVMCIOptionsDir) -def _patchGraalVersionConstant(dist): +def _updateGraalPropertiesFile(jreLibDir): """ - Patches the constant "@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@" in the constant pool of Graal.class - with the computed Graal version string. + Updates (or creates) 'jreLibDir'/jvmci/graal.properties to set/modify the + graal.version property. """ - zf = zipfile.ZipFile(dist.path, 'r') - graalClassfilePath = 'com/oracle/graal/api/runtime/Graal.class' - try: - graalClassfile = zf.read(graalClassfilePath) - except KeyError: - mx.log(graalClassfilePath + ' is not present in ' + dist.path) - return - placeholder = '@@@@@@@@@@@@@@@@graal.version@@@@@@@@@@@@@@@@' - placeholderLen = len(placeholder) - versionSpec = '{:' + str(placeholderLen) + '}' - versionStr = versionSpec.format(graal_version()) - - if len(versionStr) > placeholderLen: - # Truncate the version string if necessary - assert versionStr.startswith('unknown'), versionStr - versionStr = versionStr[:placeholderLen] - if placeholder not in graalClassfile: - assert versionStr in graalClassfile, 'could not find "' + placeholder + '" 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') - for zi in zf.infolist(): - if zi.filename == graalClassfilePath: - data = graalClassfile.replace(placeholder, versionStr) - else: - data = zf.read(zi) - zfOut.writestr(zi, data) - zfOut.close() - os.close(zfOutFd) - zf.close() - shutil.move(zfOutPath, dist.path) + version = graal_version() + graalProperties = join(jreLibDir, 'jvmci', 'graal.properties') + if not exists(graalProperties): + with open(graalProperties, 'w') as fp: + print >> fp, 'graal.version=' + version + else: + content = [] + with open(graalProperties) as fp: + for line in fp: + if line.startswith('graal.version='): + content.append('graal.version=' + version) + else: + content.append(line.rstrip(os.linesep)) + with open(graalProperties, 'w') as fp: + fp.write(os.linesep.join(content)) def _installDistInJdks(deployableDist): """ Installs the jar(s) for a given Distribution into all existing JVMCI JDKs """ dist = mx.distribution(deployableDist.name) - if dist.name == 'GRAAL': - _patchGraalVersionConstant(dist) - jdks = _jdksDir() if exists(jdks): for e in os.listdir(jdks): @@ -673,6 +652,8 @@ if deployableDist.usesJVMCIClassLoader: # deploy service files _updateJVMCIFiles(jdkDir) + if dist.name == 'GRAAL': + _updateGraalPropertiesFile(jreLibDir) def _getJdkDeployedJars(jdkDir): """ @@ -812,7 +793,7 @@ major, minor = map(int, most_recent_tag_version.split('.')) cached_graal_version = str(major) + '.' + str(minor + 1) + '-' + dev_suffix else: - cached_graal_version = 'unknown-{0}'.format(platform.node()) + cached_graal_version = 'unknown-{0}-{1}'.format(platform.node(), time.strftime('%Y-%m-%d_%H-%M-%S_%Z')) return cached_graal_version