comparison mx/mx_graal.py @ 13508:8a5b39d0bfb5

mx: add completion support for graal options (GRAAL-297)
author Bernhard Urban <bernhard.urban@jku.at>
date Sat, 04 Jan 2014 00:33:49 +0200
parents d3ec6003856d
children a8831418ff04
comparison
equal deleted inserted replaced
13507:d3ec6003856d 13508:8a5b39d0bfb5
24 # or visit www.oracle.com if you need additional information or have any 24 # or visit www.oracle.com if you need additional information or have any
25 # questions. 25 # questions.
26 # 26 #
27 # ---------------------------------------------------------------------------------------------------- 27 # ----------------------------------------------------------------------------------------------------
28 28
29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing 29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing, StringIO
30 from os.path import join, exists, dirname, basename, getmtime 30 from os.path import join, exists, dirname, basename, getmtime
31 from argparse import ArgumentParser, REMAINDER 31 from argparse import ArgumentParser, REMAINDER
32 from outputparser import OutputParser, ValuesMatcher
32 import mx 33 import mx
33 import xml.dom.minidom 34 import xml.dom.minidom
34 import sanitycheck 35 import sanitycheck
35 import itertools 36 import itertools
36 import json, textwrap 37 import json, textwrap
1399 # strip last line and define local variable "ret" 1400 # strip last line and define local variable "ret"
1400 complt = "\n".join(generator.get().split('\n')[0:-1]).replace('context state line', 'context state line ret=1') 1401 complt = "\n".join(generator.get().split('\n')[0:-1]).replace('context state line', 'context state line ret=1')
1401 1402
1402 # add array of possible subcommands (as they are not part of the argument parser) 1403 # add array of possible subcommands (as they are not part of the argument parser)
1403 complt += '\n ": :->command" \\\n' 1404 complt += '\n ": :->command" \\\n'
1404 complt += ' "*::args:_files" && ret=0\n' 1405 complt += ' "*::args:->args" && ret=0\n'
1405 complt += '\n' 1406 complt += '\n'
1406 complt += 'case $state in\n' 1407 complt += 'case $state in\n'
1407 complt += ' (command)\n' 1408 complt += '\t(command)\n'
1408 complt += ' local -a main_commands\n' 1409 complt += '\t\tlocal -a main_commands\n'
1409 complt += ' main_commands=(\n' 1410 complt += '\t\tmain_commands=(\n'
1410 for cmd in sorted(mx._commands.iterkeys()): 1411 for cmd in sorted(mx._commands.iterkeys()):
1411 c, _ = mx._commands[cmd][:2] 1412 c, _ = mx._commands[cmd][:2]
1412 doc = c.__doc__ 1413 doc = c.__doc__
1413 complt += ' "{0}'.format(cmd) 1414 complt += '\t\t\t"{0}'.format(cmd)
1414 if doc: 1415 if doc:
1415 complt += ':{0}'.format(doc.split('\n', 1)[0].replace('\"', '').replace("\'", "")) 1416 complt += ':{0}'.format(doc.split('\n', 1)[0].replace('\"', '').replace("\'", ""))
1416 complt += '"\n' 1417 complt += '"\n'
1417 complt += ' )\n' 1418 complt += '\t\t)\n'
1418 complt += ' _describe -t main_commands command main_commands && ret=0\n' 1419 complt += '\t\t_describe -t main_commands command main_commands && ret=0\n'
1419 complt += ' ;;\n' 1420 complt += '\t\t;;\n'
1421
1422 complt += '\t(args)\n'
1423 complt += '\t\tcase $line[1] in\n'
1424 complt += '\t\t\t(vm)\n'
1425 complt += '\t\t\t\tnoglob \\\n'
1426 complt += '\t\t\t\t\t_arguments -s -S \\\n'
1427 for vmap in _parseVMOptions():
1428 complt += '\t\t\t\t\t'
1429 if vmap['optType'] == 'Boolean':
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'
1446 complt += '\t\t\t\t;;\n'
1447 complt += '\t\tesac\n'
1448 complt += '\t\t;;\n'
1420 complt += 'esac\n' 1449 complt += 'esac\n'
1421 complt += '\n' 1450 complt += '\n'
1422 complt += 'return $ret' 1451 complt += 'return $ret'
1423 print complt 1452 print complt
1453
1454 def _parseVMOptions():
1455 parser = OutputParser()
1456 # TODO: the optDoc part can wrapped accross multiple lines, currently only the first line will be captured
1457 jvmOptions = re.compile(
1458 r"^[ \t]*"
1459 "(?P<optType>(Boolean|Integer|Float|Double|String|ccstr|uintx)) "
1460 "(?P<optName>[a-zA-Z0-9]+)"
1461 "[ \t]+=[ \t]*"
1462 "(?P<optDefault>([\-0-9]+(\.[0-9]+(\.[0-9]+\.[0-9]+))?|false|true|null|Name|sun\.boot\.class\.path))?"
1463 "[ \t]*"
1464 "(?P<optDoc>.+)?",
1465 re.MULTILINE)
1466 parser.addMatcher(ValuesMatcher(jvmOptions, {
1467 'optType' : '<optType>',
1468 'optName' : '<optName>',
1469 'optDefault' : '<optDefault>',
1470 'optDoc' : '<optDoc>',
1471 }))
1472
1473 # gather graal options
1474 output = StringIO.StringIO()
1475 vm(['-XX:-BootstrapGraal', '-G:+PrintFlags'],
1476 vm = "graal",
1477 vmbuild = "optimized",
1478 nonZeroIsFatal = False,
1479 out = output.write,
1480 err = subprocess.STDOUT)
1481
1482 valueMap = parser.parse(output.getvalue())
1483 return valueMap
1484 # TODO: hotspot -XX: options
1485 # vm(['-XX:-BootstrapGraal', '-XX:+PrintFlagsWithComments'], vm="graal", vmbuild="optimized")
1424 1486
1425 1487
1426 def mx_init(suite): 1488 def mx_init(suite):
1427 commands = { 1489 commands = {
1428 'build': [build, ''], 1490 'build': [build, ''],