diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-03-14 14:10:46 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2018-04-17 11:32:26 -0700 |
commit | 78e37c495326325ae003683411971779291f8324 (patch) | |
tree | 5aa9420ce830d04c075fd447bb2ad0568f3b432d /mesonbuild/mesonmain.py | |
parent | cdefc152852cbed2a88dd6ea9ad71facb1fbe0e8 (diff) | |
download | meson-78e37c495326325ae003683411971779291f8324.zip meson-78e37c495326325ae003683411971779291f8324.tar.gz meson-78e37c495326325ae003683411971779291f8324.tar.bz2 |
Accept builtin options with -D when making initial meson call
Currently meson only accepts `-Dopt=value` for builtin options when
calling `meson configure` and `--opt=value` for builtin options when
calling `meson` initially. This is a confusing behavior, and users only
get a small warning at the top of a potentially long configuration
summary to catch this.
This has confused end users and developers alike, there are at least 5
duplicates of the bug this fixes, and I have personally been asked about
this more times than I can count. The help documentation doesn't make
it clear that -D cannot be used to set options like prefix and bindir.
This adds support for -D options to the initial meson call, but not --
options to the meson configure call. I think it's better to have one way
to do things, and -- options are kinda one off while -D is used
everywhere else, so lets stick with that.
Related #969
Diffstat (limited to 'mesonbuild/mesonmain.py')
-rw-r--r-- | mesonbuild/mesonmain.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 7b87843f..e02c17e 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -69,6 +69,25 @@ def wrapmodetype(string): msg = 'invalid argument {!r}, use one of {}'.format(string, msg) raise argparse.ArgumentTypeError(msg) +def filter_builtin_options(args, original_args): + """Filter out any builtin arguments passed as -D options. + + Error if an argument is passed with -- and -D + """ + arguments = dict(p.split('=', 1) for p in args.projectoptions) + meson_opts = set(arguments).intersection(set(coredata.builtin_options)) + if meson_opts: + for arg in meson_opts: + value = arguments[arg] + if any([a.startswith('--{}'.format(arg)) for a in original_args]): + raise MesonException( + 'Argument "{0}" passed as both --{0} and -D{0}, but only ' + 'one is allowed'.format(arg)) + setattr(args, coredata.get_builtin_option_destination(arg), value) + + # Remove the builtin option from the project args values + args.projectoptions.remove('{}={}'.format(arg, value)) + class MesonApp: def __init__(self, dir1, dir2, script_launcher, handshake, options, original_cmd_line_args): @@ -320,6 +339,7 @@ def run(original_args, mainfile=None): args = mesonlib.expand_arguments(args) options = parser.parse_args(args) + filter_builtin_options(options, args) args = options.directories if not args or len(args) > 2: # if there's a meson.build in the dir above, and not in the current |