diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-05-03 09:39:26 -0400 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.com> | 2023-08-06 09:39:55 -0400 |
commit | 48c17b7ae651b5819938392502d341377cb4435a (patch) | |
tree | 1260bbe66f01fede78143500b65fbc1527ff6ce2 /mesonbuild | |
parent | 78337653fce90d6745d2ce46eaba9d25ab9e18d2 (diff) | |
download | meson-48c17b7ae651b5819938392502d341377cb4435a.zip meson-48c17b7ae651b5819938392502d341377cb4435a.tar.gz meson-48c17b7ae651b5819938392502d341377cb4435a.tar.bz2 |
UserArrayOption: Remove user_input argument
The only place it can be set to False is from optinterpreter. Better
check value there and deprecate string usage.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 4 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 17 | ||||
-rw-r--r-- | mesonbuild/mcompile.py | 2 | ||||
-rw-r--r-- | mesonbuild/optinterpreter.py | 7 |
4 files changed, 14 insertions, 16 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 7a8ae72..c7af1ca 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1380,11 +1380,11 @@ def get_global_options(lang: str, cargs = coredata.UserArrayOption( description + ' compiler', - comp_options, split_args=True, user_input=True, allow_dups=True) + comp_options, split_args=True, allow_dups=True) largs = coredata.UserArrayOption( description + ' linker', - link_options, split_args=True, user_input=True, allow_dups=True) + link_options, split_args=True, allow_dups=True) if comp.INVOKES_LINKER and comp_key == envkey: # If the compiler acts as a linker driver, and we're using the diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 54d9b1d..975719e 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -247,23 +247,16 @@ class UserComboOption(UserOption[str]): class UserArrayOption(UserOption[T.List[str]]): def __init__(self, description: str, value: T.Union[str, T.List[str]], - split_args: bool = False, user_input: bool = False, + split_args: bool = False, allow_dups: bool = False, yielding: bool = DEFAULT_YIELDING, choices: T.Optional[T.List[str]] = None, deprecated: T.Union[bool, str, T.Dict[str, str], T.List[str]] = False): super().__init__(description, choices if choices is not None else [], yielding, deprecated) self.split_args = split_args self.allow_dups = allow_dups - self.value = self.validate_value(value, user_input=user_input) - - def listify(self, value: T.Union[str, T.List[str]], user_input: bool = True) -> T.List[str]: - # User input is for options defined on the command line (via -D - # options). Users can put their input in as a comma separated - # string, but for defining options in meson_options.txt the format - # should match that of a combo - if not user_input and isinstance(value, str) and not value.startswith('['): - raise MesonException('Value does not define an array: ' + value) + self.set_value(value) + def listify(self, value: T.Union[str, T.List[str]]) -> T.List[str]: if isinstance(value, str): if value.startswith('['): try: @@ -283,8 +276,8 @@ class UserArrayOption(UserOption[T.List[str]]): raise MesonException(f'"{value}" should be a string array, but it is not') return newvalue - def validate_value(self, value: T.Union[str, T.List[str]], user_input: bool = True) -> T.List[str]: - newvalue = self.listify(value, user_input) + def validate_value(self, value: T.Union[str, T.List[str]]) -> T.List[str]: + newvalue = self.listify(value) if not self.allow_dups and len(set(newvalue)) != len(newvalue): msg = 'Duplicated values in array option is deprecated. ' \ diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py index 4e46702..950b27c 100644 --- a/mesonbuild/mcompile.py +++ b/mesonbuild/mcompile.py @@ -35,7 +35,7 @@ if T.TYPE_CHECKING: import argparse def array_arg(value: str) -> T.List[str]: - return UserArrayOption(None, value, allow_dups=True, user_input=True).value + return UserArrayOption(None, value, allow_dups=True).value def validate_builddir(builddir: Path) -> None: if not (builddir / 'meson-private' / 'coredata.dat').is_file(): diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 8377614..2756997 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -20,7 +20,7 @@ from . import coredata from . import mesonlib from . import mparser from . import mlog -from .interpreterbase import FeatureNew, typed_pos_args, typed_kwargs, ContainerTypeInfo, KwargInfo +from .interpreterbase import FeatureNew, FeatureDeprecated, typed_pos_args, typed_kwargs, ContainerTypeInfo, KwargInfo from .interpreter.type_checking import NoneType, in_set_validator if T.TYPE_CHECKING: @@ -266,6 +266,11 @@ class OptionInterpreter: def string_array_parser(self, description: str, args: T.Tuple[bool, _DEPRECATED_ARGS], kwargs: StringArrayArgs) -> coredata.UserOption: choices = kwargs['choices'] value = kwargs['value'] if kwargs['value'] is not None else choices + if isinstance(value, str): + if value.startswith('['): + FeatureDeprecated('String value for array option', '1.2.0').use(self.subproject) + else: + raise mesonlib.MesonException('Value does not define an array: ' + value) return coredata.UserArrayOption(description, value, choices=choices, yielding=args[0], |