comparison mx.jvmci/mx_jvmci.py @ 23331:459ec97bec01

updates to jvm.cfg should respect DEFAULT_VM
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 22 Mar 2016 20:40:16 -0700
parents fc1036575a76
children d5690e838afa
comparison
equal deleted inserted replaced
23330:83b296a07c33 23331:459ec97bec01
1127 def updateJvmCfg(jdkDir, vm): 1127 def updateJvmCfg(jdkDir, vm):
1128 jvmCfg = getVmCfgInJdk(jdkDir) 1128 jvmCfg = getVmCfgInJdk(jdkDir)
1129 if not exists(jvmCfg): 1129 if not exists(jvmCfg):
1130 mx.abort(jvmCfg + ' does not exist') 1130 mx.abort(jvmCfg + ' does not exist')
1131 1131
1132 prefix = '-' + vm + ' ' 1132 def getVMEntry(vm):
1133 vmKnown = prefix + 'KNOWN\n' 1133 """Return the set of lines that should be in jvm.cfg for this vm configuration"""
1134 known = '-' + vm + ' ' + 'KNOWN\n'
1135 cfgLines = []
1136 cfgLines.append(known)
1137 for alias, aliased in _vmAliases.iteritems():
1138 if vm == aliased:
1139 cfgLines.append('-' + alias + ' ALIASED_TO -' + aliased + '\n')
1140 return known, cfgLines
1141
1142 # Compute the cfg entries for the currently selected VM and the default VM,
1143 # if a default VM has been set.
1144 vmKnown, vmLines = getVMEntry(vm)
1145 defaultVMLines = []
1146 defaultVM = mx.get_env('DEFAULT_VM')
1147 if defaultVM:
1148 if defaultVM == vm:
1149 defaultVM = None
1150 else:
1151 defaultVMPath = join(vmLibDirInJdk(jdkDir), defaultVM, _lib('jvm'))
1152 if not exists(defaultVMPath):
1153 mx.log('Warning: The default VM is "' + defaultVM + '" but it hasn\'t been built yet so "-' + vm + '" will be the default.')
1154 defaultVM = None
1155 else:
1156 defaultVMKnown, defaultVMLines = getVMEntry(defaultVM)
1157
1158 # The default VM should always be set as the default, so read the existing jvm.cfg
1159 # and strip out any lines that mention the vm or the defaultVM, splitting the file
1160 # into a possible comment prefix and all the rest of the lines from the jvm.cfg.
1161 # Note that this will enforce the defaultVM even if the default hasn't been built.
1162 prefix = []
1163 suffix = []
1134 lines = [] 1164 lines = []
1135 found = False 1165 outOfOrder = False
1166 foundVm = False
1167 foundDefaultVM = defaultVM == None
1136 with open(jvmCfg) as f: 1168 with open(jvmCfg) as f:
1137 for line in f: 1169 for line in f:
1170 lines.append(line)
1138 if line.strip() == vmKnown.strip(): 1171 if line.strip() == vmKnown.strip():
1139 found = True 1172 foundVm = True
1140 lines.append(line) 1173 continue
1141 1174 if line.endswith(' ALIASED_TO -' + vm + '\n'):
1142 if not found: 1175 continue
1143 mx.log('Prepending "' + prefix + 'KNOWN" to ' + jvmCfg) 1176 if defaultVM and line.strip() == defaultVMKnown.strip():
1177 foundDefaultVM = True
1178 outOfOrder = foundVm
1179 continue
1180 if defaultVM and line.endswith(' ALIASED_TO -' + defaultVM + '\n'):
1181 continue
1182 if line.startswith('#') and len(suffix) == 0:
1183 prefix.append(line)
1184 else:
1185 suffix.append(line)
1186
1187
1188 # Build the new jvm.cfg out of the comment prefix, the entries for any default VM,
1189 # the entries for the currently selected VM followed by the remaining lines.
1190 allLines = prefix + defaultVMLines + vmLines + suffix
1191
1192 if allLines != lines:
1193 # The computed jvm.cfg is different from what's on disk so try to explain
1194 # what effect the newly written one will have.
1195 if outOfOrder:
1196 # Both vm and defaultVM were already in the jvm.cfg but in a different order
1197 # so vm was the default. The new jvm.cfg sets defaultVM as the default.
1198 mx.log('Resetting "' + defaultVM + '" as default in ' + jvmCfg)
1199 else:
1200 if defaultVM:
1201 if not foundDefaultVM:
1202 # The defaultVM was missing so it's being set to the default.
1203 mx.log('Setting default JVM to "-' + defaultVM + '" in ' + jvmCfg)
1204 if not foundVm:
1205 # vm wasn't found so it's added but is not the default.
1206 mx.log('Adding JVM "-' + vm + '" in ' + jvmCfg)
1207 else:
1208 # No defaultVM was specified or it was the same as vm, so
1209 # vm will be the default.
1210 mx.log('Setting default JVM to "-' + vm + '" in ' + jvmCfg)
1211
1144 if mx.get_os() != 'windows': 1212 if mx.get_os() != 'windows':
1145 os.chmod(jvmCfg, JDK_UNIX_PERMISSIONS_FILE) 1213 os.chmod(jvmCfg, JDK_UNIX_PERMISSIONS_FILE)
1146 with open(jvmCfg, 'w') as f: 1214 with open(jvmCfg, 'w') as f:
1147 written = False 1215 for line in allLines:
1148 for line in lines:
1149 if line.startswith('#'):
1150 f.write(line)
1151 continue
1152 if not written:
1153 f.write(vmKnown)
1154 for alias, aliased in _vmAliases.iteritems():
1155 if vm == aliased:
1156 f.write('-' + alias + ' ALIASED_TO -' + aliased + '\n')
1157 written = True
1158 if line.startswith(prefix):
1159 line = vmKnown
1160 if written:
1161 continue
1162 f.write(line) 1216 f.write(line)
1163 1217
1164 mx_gate.add_jacoco_includes(['jdk.vm.ci.*']) 1218 mx_gate.add_jacoco_includes(['jdk.vm.ci.*'])
1165 1219
1166 def run_vm(args, vm=None, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, vmbuild=None): 1220 def run_vm(args, vm=None, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, vmbuild=None):