From f485a8cf1678b5303e38fc5940ef76a30fbea6a2 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 11 Aug 2023 16:00:44 -0700 Subject: [PATCH] interpreter: use typed_kwargs for static_library(pic) --- mesonbuild/build.py | 6 +++--- mesonbuild/interpreter/kwargs.py | 1 + mesonbuild/interpreter/type_checking.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 1db78ff90..4152be778 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1240,7 +1240,7 @@ class BuildTarget(Target): raise InvalidArguments(f'Invalid rust_dependency_map "{rust_dependency_map}": must be a dictionary with string values.') self.rust_dependency_map = rust_dependency_map - def _extract_pic_pie(self, kwargs, arg: str, option: str): + def _extract_pic_pie(self, kwargs: T.Dict[str, T.Any], arg: str, option: str) -> bool: # Check if we have -fPIC, -fpic, -fPIE, or -fpie in cflags all_flags = self.extra_args['c'] + self.extra_args['cpp'] if '-f' + arg.lower() in all_flags or '-f' + arg.upper() in all_flags: @@ -1248,8 +1248,8 @@ class BuildTarget(Target): return True k = OptionKey(option) - if arg in kwargs: - val = kwargs[arg] + if kwargs.get(arg) is not None: + val = T.cast('bool', kwargs[arg]) elif k in self.environment.coredata.options: val = self.environment.coredata.options[k].value else: diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 839771279..bf0c64cc9 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -347,6 +347,7 @@ class Executable(_BuildTarget): class _StaticLibMixin(TypedDict): prelink: bool + pic: T.Optional[bool] class StaticLibrary(_BuildTarget, _StaticLibMixin, _LibraryMixin): diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index aaa71daf5..286bdcab3 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -606,6 +606,7 @@ _EXCLUSIVE_LIB_KWS: T.List[KwargInfo] = [ # them into build_target easier _EXCLUSIVE_STATIC_LIB_KWS: T.List[KwargInfo] = [ KwargInfo('prelink', bool, default=False, since='0.57.0'), + KwargInfo('pic', (bool, NoneType), since='0.36.0'), ] # The total list of arguments used by StaticLibrary