Mercurial > hg > graal-jvmci-8
comparison mxtool/mx.py @ 22030:5b4a974d9ae6
mx: added support for overridden commands to be available via a qualified name
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 19 Jun 2015 15:59:22 +0200 |
parents | e942083c0fcc |
children | 434fbaaf53d7 |
comparison
equal
deleted
inserted
replaced
22029:0eedd37f45ba | 22030:5b4a974d9ae6 |
---|---|
1842 def _handle_conflict_resolve(self, action, conflicting_actions): | 1842 def _handle_conflict_resolve(self, action, conflicting_actions): |
1843 self._handle_conflict_error(action, conflicting_actions) | 1843 self._handle_conflict_error(action, conflicting_actions) |
1844 | 1844 |
1845 def _format_commands(): | 1845 def _format_commands(): |
1846 msg = '\navailable commands:\n\n' | 1846 msg = '\navailable commands:\n\n' |
1847 for cmd in sorted(_commands.iterkeys()): | 1847 for cmd in sorted([k for k in _commands.iterkeys() if ':' not in k]) + sorted([k for k in _commands.iterkeys() if ':' in k]): |
1848 c, _ = _commands[cmd][:2] | 1848 c, _ = _commands[cmd][:2] |
1849 doc = c.__doc__ | 1849 doc = c.__doc__ |
1850 if doc is None: | 1850 if doc is None: |
1851 doc = '' | 1851 doc = '' |
1852 msg += ' {0:<20} {1}\n'.format(cmd, doc.split('\n', 1)[0]) | 1852 msg += ' {0:<20} {1}\n'.format(cmd, doc.split('\n', 1)[0]) |
5670 assert _argParser is not None | 5670 assert _argParser is not None |
5671 _argParser.add_argument(*args, **kwargs) | 5671 _argParser.add_argument(*args, **kwargs) |
5672 | 5672 |
5673 def update_commands(suite, new_commands): | 5673 def update_commands(suite, new_commands): |
5674 for key, value in new_commands.iteritems(): | 5674 for key, value in new_commands.iteritems(): |
5675 if _commands.has_key(key): | 5675 assert ':' not in key |
5676 warn("redefining command '" + key + "' in suite " + suite.name) | 5676 old = _commands.get(key) |
5677 if old is not None: | |
5678 oldSuite = _commandsToSuite.get(key) | |
5679 if not oldSuite: | |
5680 # Core mx command is overridden by first suite | |
5681 # defining command of same name. The core mx | |
5682 # command has its name prefixed with ':'. | |
5683 _commands[':' + key] = old | |
5684 else: | |
5685 # Previously specified command from another suite | |
5686 # is not overridden. Instead, the new command | |
5687 # has a name qualified by the suite name. | |
5688 key = suite.name + ':' + key | |
5677 _commands[key] = value | 5689 _commands[key] = value |
5690 _commandsToSuite[key] = suite | |
5678 | 5691 |
5679 def warn(msg): | 5692 def warn(msg): |
5680 if _warn: | 5693 if _warn: |
5681 print 'WARNING: ' + msg | 5694 print 'WARNING: ' + msg |
5682 | 5695 |
5683 # Table of commands in alphabetical order. | 5696 # Table of commands in alphabetical order. |
5684 # Keys are command names, value are lists: [<function>, <usage msg>, <format args to doc string of function>...] | 5697 # Keys are command names, value are lists: [<function>, <usage msg>, <format args to doc string of function>...] |
5685 # If any of the format args are instances of Callable, then they are called with an 'env' are before being | 5698 # If any of the format args are instances of Callable, then they are called before being |
5686 # used in the call to str.format(). | 5699 # used in the call to str.format(). |
5687 # Suite extensions should not update this table directly, but use update_commands | 5700 # Suite extensions should not update this table directly, but use update_commands |
5688 _commands = { | 5701 _commands = { |
5689 'about': [about, ''], | 5702 'about': [about, ''], |
5690 'build': [build, '[options]'], | 5703 'build': [build, '[options]'], |
5710 'netbeansinit': [netbeansinit, ''], | 5723 'netbeansinit': [netbeansinit, ''], |
5711 'suites': [show_suites, ''], | 5724 'suites': [show_suites, ''], |
5712 'projects': [show_projects, ''], | 5725 'projects': [show_projects, ''], |
5713 'unittest' : [mx_unittest.unittest, '[unittest options] [--] [VM options] [filters...]', mx_unittest.unittestHelpSuffix], | 5726 'unittest' : [mx_unittest.unittest, '[unittest options] [--] [VM options] [filters...]', mx_unittest.unittestHelpSuffix], |
5714 } | 5727 } |
5728 _commandsToSuite = {} | |
5715 | 5729 |
5716 _argParser = ArgParser() | 5730 _argParser = ArgParser() |
5717 | 5731 |
5718 def _suitename(mxDir): | 5732 def _suitename(mxDir): |
5719 base = os.path.basename(mxDir) | 5733 base = os.path.basename(mxDir) |