diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-08-15 16:56:23 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-09-18 13:51:27 -0400 |
commit | 30d7f506c7ffe4af52feab1a68263a4bd8d78c8a (patch) | |
tree | 132587c0d6c69e4cb066ac8c862bf8e75703f25e /mesonbuild/interpreter | |
parent | e0c4cffd70761c9b8176724145fb42d11e5313c4 (diff) | |
download | meson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.zip meson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.tar.gz meson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.tar.bz2 |
Remove get_pkgconfig_variable()
Make sure that pkgconfig_define is a pair of strings and not a list with
more than 2 strings.
Diffstat (limited to 'mesonbuild/interpreter')
-rw-r--r-- | mesonbuild/interpreter/interpreterobjects.py | 23 | ||||
-rw-r--r-- | mesonbuild/interpreter/kwargs.py | 6 | ||||
-rw-r--r-- | mesonbuild/interpreter/type_checking.py | 9 |
3 files changed, 24 insertions, 14 deletions
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index f1f8ea8..a76a0cb 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -21,7 +21,7 @@ from ..interpreterbase import ( typed_pos_args, typed_kwargs, typed_operator, noArgsFlattening, noPosargs, noKwargs, unholder_return, flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode) -from ..interpreter.type_checking import NoneType, ENV_SEPARATOR_KW +from ..interpreter.type_checking import NoneType, ENV_SEPARATOR_KW, PKGCONFIG_DEFINE_KW from ..dependencies import Dependency, ExternalLibrary, InternalDependency from ..programs import ExternalProgram from ..mesonlib import HoldableObject, OptionKey, listify, Popen_safe @@ -487,17 +487,18 @@ class DependencyHolder(ObjectHolder[Dependency]): @typed_pos_args('dependency.get_pkgconfig_variable', str) @typed_kwargs( 'dependency.get_pkgconfig_variable', - KwargInfo('default', (str, NoneType)), - KwargInfo( - 'define_variable', - ContainerTypeInfo(list, str, pairs=True), - default=[], - listify=True, - validator=lambda x: 'must be of length 2 or empty' if len(x) not in {0, 2} else None, - ), + KwargInfo('default', str, default=''), + PKGCONFIG_DEFINE_KW.evolve(name='define_variable') ) def pkgconfig_method(self, args: T.Tuple[str], kwargs: 'kwargs.DependencyPkgConfigVar') -> str: - return self.held_object.get_pkgconfig_variable(args[0], **kwargs) + from ..dependencies.pkgconfig import PkgConfigDependency + if not isinstance(self.held_object, PkgConfigDependency): + raise InvalidArguments(f'{self.held_object.get_name()!r} is not a pkgconfig dependency') + return self.held_object.get_variable( + pkgconfig=args[0], + default_value=kwargs['default'], + pkgconfig_define=kwargs['define_variable'], + ) @FeatureNew('dependency.get_configtool_variable', '0.44.0') @FeatureDeprecated('dependency.get_configtool_variable', '0.56.0', @@ -523,7 +524,7 @@ class DependencyHolder(ObjectHolder[Dependency]): KwargInfo('configtool', (str, NoneType)), KwargInfo('internal', (str, NoneType), since='0.54.0'), KwargInfo('default_value', (str, NoneType)), - KwargInfo('pkgconfig_define', ContainerTypeInfo(list, str, pairs=True), default=[], listify=True), + PKGCONFIG_DEFINE_KW, ) def variable_method(self, args: T.Tuple[T.Optional[str]], kwargs: 'kwargs.DependencyGetVariable') -> str: default_varname = args[0] diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index e67ebf0..35b8fb6 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -16,7 +16,7 @@ from ..dependencies.base import Dependency from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString, OptionKey from ..modules.cmake import CMakeSubprojectOptions from ..programs import ExternalProgram - +from .type_checking import PkgConfigDefineType class FuncAddProjectArgs(TypedDict): @@ -256,7 +256,7 @@ class FeatureOptionRequire(TypedDict): class DependencyPkgConfigVar(TypedDict): default: T.Optional[str] - define_variable: T.List[str] + define_variable: PkgConfigDefineType class DependencyGetVariable(TypedDict): @@ -266,7 +266,7 @@ class DependencyGetVariable(TypedDict): configtool: T.Optional[str] internal: T.Optional[str] default_value: T.Optional[str] - pkgconfig_define: T.List[str] + pkgconfig_define: PkgConfigDefineType class ConfigurationDataSet(TypedDict): diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 047aff8..645b273 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -29,6 +29,7 @@ if T.TYPE_CHECKING: from ..mesonlib import EnvInitValueType _FullEnvInitValueType = T.Union[EnvironmentVariables, T.List[str], T.List[T.List[str]], EnvInitValueType, str, None] + PkgConfigDefineType = T.Optional[T.Tuple[str, str]] def in_set_validator(choices: T.Set[str]) -> T.Callable[[str], T.Optional[str]]: @@ -648,3 +649,11 @@ BUILD_TARGET_KWS = [ } ) ] + +PKGCONFIG_DEFINE_KW: KwargInfo = KwargInfo( + 'pkgconfig_define', + ContainerTypeInfo(list, str, pairs=True), + default=[], + validator=lambda x: 'must be of length 2 or empty' if len(x) not in {0, 2} else None, + convertor=lambda x: tuple(x) if x else None +) |