diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-03-15 14:52:56 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-04-17 11:32:26 -0700 |
commit | 8120ff9cf75bf35bed049f0624314967f35bae51 (patch) | |
tree | aa33bfa81fe027500231d584bede3834d7bcb6ea | |
parent | 78e37c495326325ae003683411971779291f8324 (diff) | |
download | meson-8120ff9cf75bf35bed049f0624314967f35bae51.zip meson-8120ff9cf75bf35bed049f0624314967f35bae51.tar.gz meson-8120ff9cf75bf35bed049f0624314967f35bae51.tar.bz2 |
Move builtin_argument_registration to coredata
We're going to want to use these functions in meson configure as well to
make the command line options the same between `meson` and `meson
configure`.
-rw-r--r-- | mesonbuild/coredata.py | 24 | ||||
-rw-r--r-- | mesonbuild/mesonmain.py | 22 |
2 files changed, 25 insertions, 21 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 1ca6fbf..ba4f495 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -20,6 +20,7 @@ from collections import OrderedDict from .mesonlib import MesonException from .mesonlib import default_libdir, default_libexecdir, default_prefix import ast +import argparse version = '0.46.0.dev1' backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'xcode'] @@ -390,6 +391,29 @@ def get_builtin_option_default(optname, prefix='', noneIfSuppress=False): else: raise RuntimeError('Tried to get the default value for an unknown builtin option \'%s\'.' % optname) +def add_builtin_argument(p, name): + kwargs = {} + k = get_builtin_option_destination(name) + c = get_builtin_option_choices(k) + b = get_builtin_option_action(k) + h = get_builtin_option_description(k) + if not b: + h = h.rstrip('.') + ' (default: %s).' % get_builtin_option_default(k) + else: + kwargs['action'] = b + if c and not b: + kwargs['choices'] = c + default = get_builtin_option_default(k, noneIfSuppress=True) + if default is not None: + kwargs['default'] = default + else: + kwargs['default'] = argparse.SUPPRESS + p.add_argument('--' + name.replace('_', '-'), help=h, **kwargs) + +def register_builtin_arguments(parser): + for n in builtin_options: + add_builtin_argument(parser, n) + builtin_options = { 'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'], 'strip': [UserBooleanOption, 'Strip targets on install.', False], diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index e02c17e..613e953 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -25,29 +25,9 @@ from .wrap import WrapMode, wraptool default_warning = '1' -def add_builtin_argument(p, name): - kwargs = {} - k = coredata.get_builtin_option_destination(name) - c = coredata.get_builtin_option_choices(k) - b = coredata.get_builtin_option_action(k) - h = coredata.get_builtin_option_description(k) - if not b: - h = h.rstrip('.') + ' (default: %s).' % coredata.get_builtin_option_default(k) - else: - kwargs['action'] = b - if c and not b: - kwargs['choices'] = c - default = coredata.get_builtin_option_default(k, noneIfSuppress=True) - if default is not None: - kwargs['default'] = default - else: - kwargs['default'] = argparse.SUPPRESS - p.add_argument('--' + name, help=h, **kwargs) - def create_parser(): p = argparse.ArgumentParser(prog='meson') - for n in coredata.builtin_options: - add_builtin_argument(p, n) + coredata.register_builtin_arguments(p) p.add_argument('--cross-file', default=None, help='File describing cross compilation environment.') p.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option", |