aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/optinterpreter.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2018-05-13 10:36:58 -0400
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-06 20:02:37 +0000
commit7c4736d27f4c5d7844a44addc0305e4354440074 (patch)
tree19aa2290f1f9b40c4ef543bda84285a96d9db45c /mesonbuild/optinterpreter.py
parentb38452636cc25ffd38d379645607f1563de59d80 (diff)
downloadmeson-7c4736d27f4c5d7844a44addc0305e4354440074.zip
meson-7c4736d27f4c5d7844a44addc0305e4354440074.tar.gz
meson-7c4736d27f4c5d7844a44addc0305e4354440074.tar.bz2
Convert args.projectoptions into a dict
This simplifies a lot of code, and centralize "key=value" parsing in a single place. Unknown command line options becomes an hard error instead of merely printing warning message. It has been warning it would become an hard error for a while now. This has exceptions though, any unknown option starting with "<lang>_" or "b_" are ignored because they depend on which languages gets added and which compiler gets selected. Also any option for unknown subproject are ignored because they depend on which subproject actually gets built. Also write more command line parsing tests. "19 bad command line options" is removed because bad cmd line option became hard error and it's covered with new tests in "30 command line".
Diffstat (limited to 'mesonbuild/optinterpreter.py')
-rw-r--r--mesonbuild/optinterpreter.py45
1 files changed, 1 insertions, 44 deletions
diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py
index 7455c48..4207f45 100644
--- a/mesonbuild/optinterpreter.py
+++ b/mesonbuild/optinterpreter.py
@@ -15,7 +15,6 @@
import os, re
import functools
-from . import mlog
from . import mparser
from . import coredata
from . import mesonlib
@@ -125,48 +124,9 @@ option_types = {'string': StringParser,
}
class OptionInterpreter:
- def __init__(self, subproject, command_line_options):
+ def __init__(self, subproject):
self.options = {}
self.subproject = subproject
- self.sbprefix = subproject + ':'
- self.cmd_line_options = {}
- for o in command_line_options:
- if self.subproject != '': # Strip the beginning.
- # Ignore options that aren't for this subproject
- if not o.startswith(self.sbprefix):
- continue
- try:
- (key, value) = o.split('=', 1)
- except ValueError:
- raise OptionException('Option {!r} must have a value separated by equals sign.'.format(o))
- # Ignore subproject options if not fetching subproject options
- if self.subproject == '' and ':' in key:
- continue
- self.cmd_line_options[key] = value
-
- def get_bad_options(self):
- subproj_len = len(self.subproject)
- if subproj_len > 0:
- subproj_len += 1
- retval = []
- # The options need to be sorted (e.g. here) to get consistent
- # error messages (on all platforms) which is required by some test
- # cases that check (also) the order of these options.
- for option in sorted(self.cmd_line_options):
- if option in list(self.options) + forbidden_option_names:
- continue
- if any(option[subproj_len:].startswith(p) for p in forbidden_prefixes):
- continue
- retval += [option]
- return retval
-
- def check_for_bad_options(self):
- bad = self.get_bad_options()
- if bad:
- sub = 'In subproject {}: '.format(self.subproject) if self.subproject else ''
- mlog.warning(
- '{}Unknown command line options: "{}"\n'
- 'This will become a hard error in a future Meson release.'.format(sub, ', '.join(bad)))
def process(self, option_file):
try:
@@ -187,7 +147,6 @@ class OptionInterpreter:
e.colno = cur.colno
e.file = os.path.join('meson_options.txt')
raise e
- self.check_for_bad_options()
def reduce_single(self, arg):
if isinstance(arg, str):
@@ -243,6 +202,4 @@ class OptionInterpreter:
opt = option_types[opt_type](opt_name, kwargs.pop('description', ''), kwargs)
if opt.description == '':
opt.description = opt_name
- if opt_name in self.cmd_line_options:
- opt.set_value(self.cmd_line_options[opt_name])
self.options[opt_name] = opt