comparison mx/commands.py @ 8261:2237260c6fdb

the contents of jvm.cfg are reset when copying the JDK so that the non-default VMs must be built before being run
author Doug Simon <doug.simon@oracle.com>
date Wed, 13 Mar 2013 21:55:08 +0100
parents b9eb0d939e60
children b246434a3e4a
comparison
equal deleted inserted replaced
8260:b81f42160093 8261:2237260c6fdb
314 """ 314 """
315 if platform.system() == 'Windows': 315 if platform.system() == 'Windows':
316 return join(jdk, 'jre', 'lib', _arch(), 'jvm.cfg') 316 return join(jdk, 'jre', 'lib', _arch(), 'jvm.cfg')
317 return join(_vmLibDirInJdk(jdk), 'jvm.cfg') 317 return join(_vmLibDirInJdk(jdk), 'jvm.cfg')
318 318
319 def _jdk(build='product', create=False): 319 def _jdk(build='product', vmToCheck=None, create=False):
320 """ 320 """
321 Get the JDK into which Graal is installed, creating it first if necessary. 321 Get the JDK into which Graal is installed, creating it first if necessary.
322 """ 322 """
323 jdk = join(_graal_home, 'jdk' + str(mx.java().version), build) 323 jdk = join(_graal_home, 'jdk' + str(mx.java().version), build)
324 jdkContents = ['bin', 'include', 'jre', 'lib'] 324 jdkContents = ['bin', 'include', 'jre', 'lib']
342 # reliably used as the bootstrap for a HotSpot build. 342 # reliably used as the bootstrap for a HotSpot build.
343 jvmCfg = _vmCfgInJdk(jdk) 343 jvmCfg = _vmCfgInJdk(jdk)
344 if not exists(jvmCfg): 344 if not exists(jvmCfg):
345 mx.abort(jvmCfg + ' does not exist') 345 mx.abort(jvmCfg + ' does not exist')
346 346
347 lines = []
348 defaultVM = None 347 defaultVM = None
349 with open(jvmCfg) as f: 348 with open(jvmCfg) as f:
350 for line in f: 349 for line in f:
351 if line.startswith('-') and defaultVM is None: 350 if line.startswith('-') and defaultVM is None:
352 parts = line.split() 351 parts = line.split()
353 assert len(parts) == 2, parts 352 assert len(parts) == 2, parts
354 assert parts[1] == 'KNOWN', parts[1] 353 assert parts[1] == 'KNOWN', parts[1]
355 defaultVM = parts[0][1:] 354 defaultVM = parts[0][1:]
356 lines.append('-' + defaultVM + '0 KNOWN\n')
357 lines.append(line)
358 355
359 assert defaultVM is not None, 'Could not find default VM in ' + jvmCfg 356 assert defaultVM is not None, 'Could not find default VM in ' + jvmCfg
360 if mx.get_os() != 'windows': 357 if mx.get_os() != 'windows':
361 chmodRecursive(jdk, 0755) 358 chmodRecursive(jdk, 0755)
362 shutil.copytree(join(_vmLibDirInJdk(jdk), defaultVM), join(_vmLibDirInJdk(jdk), defaultVM + '0')) 359 shutil.copytree(join(_vmLibDirInJdk(jdk), defaultVM), join(_vmLibDirInJdk(jdk), defaultVM + '0'))
363 360
364 with open(jvmCfg, 'w') as f: 361 with open(jvmCfg, 'w') as fp:
365 for line in lines: 362 print >> fp, '-' + defaultVM + '0 KNOWN'
366 f.write(line)
367 363
368 # Install a copy of the disassembler library 364 # Install a copy of the disassembler library
369 try: 365 try:
370 hsdis([], copyToDir=_vmLibDirInJdk(jdk)) 366 hsdis([], copyToDir=_vmLibDirInJdk(jdk))
371 except SystemExit: 367 except SystemExit:
372 pass 368 pass
373 else: 369 else:
374 if not exists(jdk): 370 if not exists(jdk):
375 mx.abort('The ' + build + ' VM has not been created - run \'mx clean; mx build ' + build + '\'') 371 mx.abort('The ' + build + ' VM has not been created - run "mx build ' + build + '"')
376 372
377 _installGraalJarInJdks(mx.distribution('GRAAL')) 373 _installGraalJarInJdks(mx.distribution('GRAAL'))
378 374
375 if vmToCheck is not None:
376 jvmCfg = _vmCfgInJdk(jdk)
377 found = False
378 with open(jvmCfg) as f:
379 for line in f:
380 if line.strip() == '-' + vmToCheck + ' KNOWN':
381 found = True
382 break
383 if not found:
384 mx.abort('The ' + build + ' ' + vmToCheck + ' VM has not been created - run "mx --vm ' + vmToCheck + ' build ' + build + '"')
385
379 return jdk 386 return jdk
380 387
381 def _installGraalJarInJdks(graalDist): 388 def _installGraalJarInJdks(graalDist):
382 graalJar = graalDist.path 389 graalJar = graalDist.path
383 jdks = join(_graal_home, 'jdk' + str(mx.java().version)) 390 jdks = join(_graal_home, 'jdk' + str(mx.java().version))
586 found = False 593 found = False
587 if not exists(jvmCfg): 594 if not exists(jvmCfg):
588 mx.abort(jvmCfg + ' does not exist') 595 mx.abort(jvmCfg + ' does not exist')
589 596
590 prefix = '-' + vm 597 prefix = '-' + vm
591 vmKnown = prefix + ' KNOWN\n' 598 vmKnown = prefix + ' KNOWN'
592 lines = []
593 with open(jvmCfg) as f: 599 with open(jvmCfg) as f:
594 for line in f: 600 for line in f:
595 if vmKnown in line: 601 if vmKnown == line.strip():
596 found = True 602 found = True
597 break 603 break
598 if not line.startswith(prefix):
599 lines.append(line)
600 if not found: 604 if not found:
601 mx.log('Appending "' + prefix + ' KNOWN" to ' + jvmCfg) 605 mx.log('Appending "' + prefix + ' KNOWN" to ' + jvmCfg)
602 lines.append(vmKnown)
603 if mx.get_os() != 'windows': 606 if mx.get_os() != 'windows':
604 os.chmod(jvmCfg, 0755) 607 os.chmod(jvmCfg, 0755)
605 with open(jvmCfg, 'w') as f: 608 with open(jvmCfg, 'a') as f:
606 for line in lines: 609 print >> f, vmKnown
607 f.write(line)
608 610
609 if exists(timestampFile): 611 if exists(timestampFile):
610 os.utime(timestampFile, None) 612 os.utime(timestampFile, None)
611 else: 613 else:
612 file(timestampFile, 'a') 614 file(timestampFile, 'a')
624 626
625 if vm is None: 627 if vm is None:
626 vm = _vm 628 vm = _vm
627 629
628 build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product' 630 build = vmbuild if vmbuild is not None else _vmbuild if _vmSourcesAvailable else 'product'
629 jdk = _jdk(build) 631 jdk = _jdk(build, vmToCheck=vm)
630 mx.expand_project_in_args(args) 632 mx.expand_project_in_args(args)
631 if _make_eclipse_launch: 633 if _make_eclipse_launch:
632 mx.make_eclipse_launch(args, 'graal-' + build, name=None, deps=mx.project('com.oracle.graal.hotspot').all_deps([], True)) 634 mx.make_eclipse_launch(args, 'graal-' + build, name=None, deps=mx.project('com.oracle.graal.hotspot').all_deps([], True))
633 if len([a for a in args if 'PrintAssembly' in a]) != 0: 635 if len([a for a in args if 'PrintAssembly' in a]) != 0:
634 hsdis([], copyToDir=_vmLibDirInJdk(jdk)) 636 hsdis([], copyToDir=_vmLibDirInJdk(jdk))