Mercurial > hg > truffle
comparison mxtool/mx.py @ 5194:a6eceb5efb0e
added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 05 Apr 2012 22:35:28 +0200 |
parents | 6fbf12b8e572 |
children | 887b45f6aa02 |
comparison
equal
deleted
inserted
replaced
5193:02da376dd213 | 5194:a6eceb5efb0e |
---|---|
127 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils | 127 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils |
128 import shutil, fnmatch, re, xml.dom.minidom | 128 import shutil, fnmatch, re, xml.dom.minidom |
129 from collections import Callable | 129 from collections import Callable |
130 from threading import Thread | 130 from threading import Thread |
131 from argparse import ArgumentParser, REMAINDER | 131 from argparse import ArgumentParser, REMAINDER |
132 from os.path import join, dirname, exists, getmtime, isabs, expandvars, isdir, isfile | 132 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile |
133 | 133 |
134 DEFAULT_JAVA_ARGS = '-ea -Xss2m -Xmx1g' | 134 DEFAULT_JAVA_ARGS = '-ea -Xss2m -Xmx1g' |
135 | 135 |
136 _projects = dict() | 136 _projects = dict() |
137 _libs = dict() | 137 _libs = dict() |
398 for l in self.libs: | 398 for l in self.libs: |
399 existing = _libs.get(l.name) | 399 existing = _libs.get(l.name) |
400 if existing is not None: | 400 if existing is not None: |
401 abort('cannot redefine library ' + l.name) | 401 abort('cannot redefine library ' + l.name) |
402 _libs[l.name] = l | 402 _libs[l.name] = l |
403 | |
404 class XML(xml.dom.minidom.Document): | |
405 | |
406 def __init__(self): | |
407 xml.dom.minidom.Document.__init__(self) | |
408 self.current = self | |
409 | |
410 def open(self, tag, attributes={}): | |
411 element = self.createElement(tag) | |
412 for key, value in attributes.items(): | |
413 element.setAttribute(key, value) | |
414 self.current.appendChild(element) | |
415 self.current = element | |
416 return self | |
417 | |
418 def close(self): | |
419 assert self.current != self | |
420 self.current = self.current.parentNode | |
421 return self | |
422 | |
423 def element(self, tag, attributes={}): | |
424 return self.open(tag, attributes).close() | |
425 | |
426 def xml(self, indent='', newl='', escape=False): | |
427 assert self.current == self | |
428 result = self.toprettyxml(indent, newl, encoding="UTF-8") | |
429 if escape: | |
430 entities = { '"': """, "'": "'", '\n': ' ' } | |
431 result = xml.sax.saxutils.escape(result, entities) | |
432 return result | |
403 | 433 |
404 def get_os(): | 434 def get_os(): |
405 """ | 435 """ |
406 Get a canonical form of sys.platform. | 436 Get a canonical form of sys.platform. |
407 """ | 437 """ |
1208 javafilelist += [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] | 1238 javafilelist += [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java'] |
1209 if len(javafilelist) == 0: | 1239 if len(javafilelist) == 0: |
1210 log('[no Java sources in {0} - skipping]'.format(sourceDir)) | 1240 log('[no Java sources in {0} - skipping]'.format(sourceDir)) |
1211 continue | 1241 continue |
1212 | 1242 |
1213 timestampFile = join(p.suite.dir, 'mx', '.checkstyle' + sourceDir[len(p.suite.dir):].replace(os.sep, '_') + '.timestamp') | 1243 timestampFile = join(p.suite.dir, 'mx', 'checkstyle-timestamps', sourceDir[len(p.suite.dir) + 1:].replace(os.sep, '_') + '.timestamp') |
1244 if not exists(dirname(timestampFile)): | |
1245 os.makedirs(dirname(timestampFile)) | |
1214 mustCheck = False | 1246 mustCheck = False |
1215 if exists(timestampFile): | 1247 if exists(timestampFile): |
1216 timestamp = os.path.getmtime(timestampFile) | 1248 timestamp = os.path.getmtime(timestampFile) |
1217 for f in javafilelist: | 1249 for f in javafilelist: |
1218 if os.path.getmtime(f) > timestamp: | 1250 if os.path.getmtime(f) > timestamp: |
1369 print 'node [shape=rect];' | 1401 print 'node [shape=rect];' |
1370 for p in projects(): | 1402 for p in projects(): |
1371 for dep in p.canonical_deps(): | 1403 for dep in p.canonical_deps(): |
1372 print '"' + p.name + '"->"' + dep + '"' | 1404 print '"' + p.name + '"->"' + dep + '"' |
1373 print '}' | 1405 print '}' |
1406 | |
1407 def make_eclipse_launch(args, jre, name=None, deps=[]): | |
1408 """ | |
1409 Creates an Eclipse launch configuration file. | |
1410 """ | |
1411 mainClass = None | |
1412 vmArgs = [] | |
1413 appArgs = [] | |
1414 cp = None | |
1415 argsCopy = list(reversed(args)) | |
1416 while len(argsCopy) != 0: | |
1417 a = argsCopy.pop() | |
1418 if a == '-jar': | |
1419 mainClass = '-jar' | |
1420 appArgs = list(reversed(argsCopy)) | |
1421 break | |
1422 if a == '-cp' or a == '-classpath': | |
1423 assert len(argsCopy) != 0 | |
1424 cp = argsCopy.pop() | |
1425 vmArgs.append(a) | |
1426 vmArgs.append(cp) | |
1427 elif a.startswith('-'): | |
1428 vmArgs.append(a) | |
1429 else: | |
1430 mainClass = a | |
1431 appArgs = list(reversed(argsCopy)) | |
1432 break | |
1433 | |
1434 if mainClass is None: | |
1435 log('Cannot create Eclipse launch configuration without main class') | |
1436 return False | |
1437 | |
1438 if name is None: | |
1439 if mainClass == '-jar': | |
1440 name = basename(appArgs[0]) | |
1441 else: | |
1442 name = mainClass | |
1443 name = time.strftime('%Y-%m-%d-%H%M%S_' + name) | |
1444 | |
1445 slm = XML() | |
1446 slm.open('sourceLookupDirector') | |
1447 slm.open('sourceContainers', {'duplicates' : 'false'}) | |
1448 | |
1449 if cp is not None: | |
1450 for e in cp.split(os.pathsep): | |
1451 for s in suites(): | |
1452 deps += [p for p in s.projects if e == p.output_dir()] | |
1453 deps += [l for l in s.libs if e == l.get_path(False)] | |
1454 | |
1455 for dep in deps: | |
1456 if dep.isLibrary(): | |
1457 if hasattr(dep, 'eclipse.container'): | |
1458 memento = XML().element('classpathContainer', {'path' : getattr(dep, 'eclipse.container')}).xml() | |
1459 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) | |
1460 else: | |
1461 memento = XML().element('javaProject', {'name' : dep.name}).xml() | |
1462 slm.element('container', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.javaProject'}) | |
1463 | |
1464 slm.close() | |
1465 slm.close() | |
1466 launch = XML() | |
1467 launch.open('launchConfiguration', {'type' : 'org.eclipse.jdt.launching.localJavaApplication'}) | |
1468 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_id', 'value' : 'org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector'}) | |
1469 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_memento', 'value' : '%s'}) | |
1470 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.JRE_CONTAINER', 'value' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jre}) | |
1471 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.MAIN_TYPE', 'value' : mainClass}) | |
1472 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROGRAM_ARGUMENTS', 'value' : ' '.join(appArgs)}) | |
1473 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) | |
1474 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_ARGUMENTS', 'value' : ' '.join(vmArgs)}) | |
1475 launch.close() | |
1476 launch = launch.xml(newl='\n') % slm.xml(escape=True) | |
1477 | |
1478 eclipseLaunches = join('mx', 'eclipse-launches') | |
1479 if not exists(eclipseLaunches): | |
1480 os.makedirs(eclipseLaunches) | |
1481 return update_file(join(eclipseLaunches, name + '.launch'), launch) | |
1374 | 1482 |
1375 def eclipseinit(args, suite=None): | 1483 def eclipseinit(args, suite=None): |
1376 """(re)generate Eclipse project configurations""" | 1484 """(re)generate Eclipse project configurations""" |
1377 | 1485 |
1378 if suite is None: | 1486 if suite is None: |
1381 def println(out, obj): | 1489 def println(out, obj): |
1382 out.write(str(obj) + '\n') | 1490 out.write(str(obj) + '\n') |
1383 | 1491 |
1384 source_locator_memento = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<sourceLookupDirector><sourceContainers duplicates="false">' | 1492 source_locator_memento = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<sourceLookupDirector><sourceContainers duplicates="false">' |
1385 entities = { '"': """, "'": "'", '\n': ' ' } | 1493 entities = { '"': """, "'": "'", '\n': ' ' } |
1494 | |
1495 sml = XML() | |
1386 | 1496 |
1387 for p in projects(): | 1497 for p in projects(): |
1388 if p.native: | 1498 if p.native: |
1389 continue | 1499 continue |
1390 | 1500 |
1525 <mapEntry key="port" value="8000"/> | 1635 <mapEntry key="port" value="8000"/> |
1526 </mapAttribute> | 1636 </mapAttribute> |
1527 <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/> | 1637 <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/> |
1528 <stringAttribute key="org.eclipse.jdt.launching.VM_CONNECTOR_ID" value="org.eclipse.jdt.launching.socketAttachConnector"/> | 1638 <stringAttribute key="org.eclipse.jdt.launching.VM_CONNECTOR_ID" value="org.eclipse.jdt.launching.socketAttachConnector"/> |
1529 </launchConfiguration>""".format(xml.sax.saxutils.escape(source_locator_memento, entities)) | 1639 </launchConfiguration>""".format(xml.sax.saxutils.escape(source_locator_memento, entities)) |
1530 update_file(join(suite.dir, 'mx', 'attach-8000.launch'), launch) | 1640 |
1641 eclipseLaunches = join(suite.dir, 'mx', 'eclipse-launches') | |
1642 if not exists(eclipseLaunches): | |
1643 os.makedirs(eclipseLaunches) | |
1644 update_file(join(eclipseLaunches, 'attach-8000.launch'), launch) | |
1531 | 1645 |
1532 def netbeansinit(args, suite=None): | 1646 def netbeansinit(args, suite=None): |
1533 """(re)generate NetBeans project configurations""" | 1647 """(re)generate NetBeans project configurations""" |
1534 | 1648 |
1535 if suite is None: | 1649 if suite is None: |