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.
This commit is contained in:
parent
78337653fc
commit
48c17b7ae6
|
@ -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
|
||||
|
|
|
@ -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. ' \
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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],
|
||||
|
|
Loading…
Reference in New Issue