Mercurial > hg > truffle
comparison mx/mx_graal.py @ 13509:a8831418ff04
mx: add completion support for hotspot options (GRAAL-297)
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Sat, 04 Jan 2014 01:43:37 +0200 |
parents | 8a5b39d0bfb5 |
children | 51e16c7a5685 |
comparison
equal
deleted
inserted
replaced
13508:8a5b39d0bfb5 | 13509:a8831418ff04 |
---|---|
1411 for cmd in sorted(mx._commands.iterkeys()): | 1411 for cmd in sorted(mx._commands.iterkeys()): |
1412 c, _ = mx._commands[cmd][:2] | 1412 c, _ = mx._commands[cmd][:2] |
1413 doc = c.__doc__ | 1413 doc = c.__doc__ |
1414 complt += '\t\t\t"{0}'.format(cmd) | 1414 complt += '\t\t\t"{0}'.format(cmd) |
1415 if doc: | 1415 if doc: |
1416 complt += ':{0}'.format(doc.split('\n', 1)[0].replace('\"', '').replace("\'", "")) | 1416 complt += ':{0}'.format(_fixQuotes(doc.split('\n', 1)[0])) |
1417 complt += '"\n' | 1417 complt += '"\n' |
1418 complt += '\t\t)\n' | 1418 complt += '\t\t)\n' |
1419 complt += '\t\t_describe -t main_commands command main_commands && ret=0\n' | 1419 complt += '\t\t_describe -t main_commands command main_commands && ret=0\n' |
1420 complt += '\t\t;;\n' | 1420 complt += '\t\t;;\n' |
1421 | 1421 |
1422 complt += '\t(args)\n' | 1422 complt += '\t(args)\n' |
1423 # TODO: improve matcher: if mx args are given, this doesn't work | |
1423 complt += '\t\tcase $line[1] in\n' | 1424 complt += '\t\tcase $line[1] in\n' |
1424 complt += '\t\t\t(vm)\n' | 1425 complt += '\t\t\t(vm)\n' |
1425 complt += '\t\t\t\tnoglob \\\n' | 1426 complt += '\t\t\t\tnoglob \\\n' |
1426 complt += '\t\t\t\t\t_arguments -s -S \\\n' | 1427 complt += '\t\t\t\t\t_arguments -s -S \\\n' |
1427 for vmap in _parseVMOptions(): | 1428 complt += _appendOptions("graal", r"G\:") |
1428 complt += '\t\t\t\t\t' | 1429 # TODO: fix -XX:{-,+}Use* flags |
1429 if vmap['optType'] == 'Boolean': | 1430 complt += _appendOptions("hotspot", r"XX\:") |
1430 complt += '{-,+}' | |
1431 else: | |
1432 complt += '-' | |
1433 complt += '"G\:' + vmap['optName'] | |
1434 if vmap['optType'] != 'Boolean': | |
1435 complt += '=' | |
1436 if vmap['optDefault'] or vmap['optDoc']: | |
1437 complt += "[" | |
1438 if vmap['optDefault']: | |
1439 complt += "(default\: " + vmap['optDefault'] + ")" | |
1440 if vmap['optDoc']: | |
1441 complt += vmap['optDoc'] | |
1442 if vmap['optDefault'] or vmap['optDoc']: | |
1443 complt += "]" | |
1444 complt += '" \\\n' | |
1445 complt += '\t\t\t\t\t"-version" && ret=0 \n' | 1431 complt += '\t\t\t\t\t"-version" && ret=0 \n' |
1446 complt += '\t\t\t\t;;\n' | 1432 complt += '\t\t\t\t;;\n' |
1447 complt += '\t\tesac\n' | 1433 complt += '\t\tesac\n' |
1448 complt += '\t\t;;\n' | 1434 complt += '\t\t;;\n' |
1449 complt += 'esac\n' | 1435 complt += 'esac\n' |
1450 complt += '\n' | 1436 complt += '\n' |
1451 complt += 'return $ret' | 1437 complt += 'return $ret' |
1452 print complt | 1438 print complt |
1453 | 1439 |
1454 def _parseVMOptions(): | 1440 def _fixQuotes(arg): |
1441 return arg.replace('\"', '').replace('\'', '').replace('`', '').replace('{', '\\{').replace('}', '\\}').replace('[', '\\[').replace(']', '\\]') | |
1442 | |
1443 def _appendOptions(optionType, optionPrefix): | |
1444 def isBoolean(vmap, field): | |
1445 return vmap[field] == "Boolean" or vmap[field] == "bool" | |
1446 | |
1447 def hasDescription(vmap): | |
1448 return vmap['optDefault'] or vmap['optDoc'] | |
1449 | |
1450 complt = "" | |
1451 for vmap in _parseVMOptions(optionType): | |
1452 complt += '\t\t\t\t\t-"' | |
1453 complt += optionPrefix | |
1454 if isBoolean(vmap, 'optType'): | |
1455 complt += '"{-,+}"' | |
1456 complt += vmap['optName'] | |
1457 if not isBoolean(vmap, 'optType'): | |
1458 complt += '=' | |
1459 if hasDescription(vmap): | |
1460 complt += "[" | |
1461 if vmap['optDefault']: | |
1462 complt += r"(default\: " + vmap['optDefault'] + ")" | |
1463 if vmap['optDoc']: | |
1464 complt += _fixQuotes(vmap['optDoc']) | |
1465 if hasDescription(vmap): | |
1466 complt += "]" | |
1467 complt += '" \\\n' | |
1468 return complt | |
1469 | |
1470 def _parseVMOptions(optionType): | |
1455 parser = OutputParser() | 1471 parser = OutputParser() |
1456 # TODO: the optDoc part can wrapped accross multiple lines, currently only the first line will be captured | 1472 # TODO: the optDoc part can wrapped accross multiple lines, currently only the first line will be captured |
1473 # TODO: fix matching for float literals | |
1457 jvmOptions = re.compile( | 1474 jvmOptions = re.compile( |
1458 r"^[ \t]*" | 1475 r"^[ \t]*" |
1459 "(?P<optType>(Boolean|Integer|Float|Double|String|ccstr|uintx)) " | 1476 r"(?P<optType>(Boolean|Integer|Float|Double|String|bool|intx|uintx|ccstr|double)) " |
1460 "(?P<optName>[a-zA-Z0-9]+)" | 1477 r"(?P<optName>[a-zA-Z0-9]+)" |
1461 "[ \t]+=[ \t]*" | 1478 r"[ \t]+=[ \t]*" |
1462 "(?P<optDefault>([\-0-9]+(\.[0-9]+(\.[0-9]+\.[0-9]+))?|false|true|null|Name|sun\.boot\.class\.path))?" | 1479 r"(?P<optDefault>([\-0-9]+(\.[0-9]+(\.[0-9]+\.[0-9]+))?|false|true|null|Name|sun\.boot\.class\.path))?" |
1463 "[ \t]*" | 1480 r"[ \t]*" |
1464 "(?P<optDoc>.+)?", | 1481 r"(?P<optDoc>.+)?", |
1465 re.MULTILINE) | 1482 re.MULTILINE) |
1466 parser.addMatcher(ValuesMatcher(jvmOptions, { | 1483 parser.addMatcher(ValuesMatcher(jvmOptions, { |
1467 'optType' : '<optType>', | 1484 'optType' : '<optType>', |
1468 'optName' : '<optName>', | 1485 'optName' : '<optName>', |
1469 'optDefault' : '<optDefault>', | 1486 'optDefault' : '<optDefault>', |
1470 'optDoc' : '<optDoc>', | 1487 'optDoc' : '<optDoc>', |
1471 })) | 1488 })) |
1472 | 1489 |
1473 # gather graal options | 1490 # gather graal options |
1474 output = StringIO.StringIO() | 1491 output = StringIO.StringIO() |
1475 vm(['-XX:-BootstrapGraal', '-G:+PrintFlags'], | 1492 vm(['-XX:-BootstrapGraal', '-G:+PrintFlags' if optionType == "graal" else '-XX:+PrintFlagsWithComments'], |
1476 vm = "graal", | 1493 vm = "graal", |
1477 vmbuild = "optimized", | 1494 vmbuild = "optimized", |
1478 nonZeroIsFatal = False, | 1495 nonZeroIsFatal = False, |
1479 out = output.write, | 1496 out = output.write, |
1480 err = subprocess.STDOUT) | 1497 err = subprocess.STDOUT) |
1481 | 1498 |
1482 valueMap = parser.parse(output.getvalue()) | 1499 valueMap = parser.parse(output.getvalue()) |
1483 return valueMap | 1500 return valueMap |
1484 # TODO: hotspot -XX: options | |
1485 # vm(['-XX:-BootstrapGraal', '-XX:+PrintFlagsWithComments'], vm="graal", vmbuild="optimized") | |
1486 | 1501 |
1487 | 1502 |
1488 def mx_init(suite): | 1503 def mx_init(suite): |
1489 commands = { | 1504 commands = { |
1490 'build': [build, ''], | 1505 'build': [build, ''], |