Skip to content

Commit

Permalink
modules/cmake: use typed_kwargs instead of permittedKwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Aug 27, 2024
1 parent 9e804a4 commit 6041a75
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions mesonbuild/modules/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ..interpreterbase import (
FeatureNew,

permittedKwargs,
noPosargs,
noKwargs,

Expand All @@ -34,7 +33,7 @@
from typing_extensions import TypedDict

from . import ModuleState
from ..cmake import SingleTargetOptions
from ..cmake.common import SingleTargetOptions
from ..environment import Environment
from ..interpreter import Interpreter, kwargs
from ..interpreterbase import TYPE_kwargs, TYPE_var, InterpreterObject
Expand All @@ -60,6 +59,12 @@ class Subproject(kwargs.ExtractRequired):
options: T.Optional[CMakeSubprojectOptions]
cmake_options: T.List[str]

class TargetKW(TypedDict):

target: T.Optional[str]


_TARGET_KW = KwargInfo('target', (str, NoneType))

COMPATIBILITIES = ['AnyNewerVersion', 'SameMajorVersion', 'SameMinorVersion', 'ExactVersion']

Expand Down Expand Up @@ -195,8 +200,8 @@ def __init__(self) -> None:
}
)

def _get_opts(self, kwargs: dict) -> SingleTargetOptions:
if 'target' in kwargs:
def _get_opts(self, kwargs: TargetKW) -> SingleTargetOptions:
if kwargs['target'] is not None:
return self.target_options[kwargs['target']]
return self.target_options.global_options

Expand All @@ -206,23 +211,23 @@ def add_cmake_defines(self, state: ModuleState, args: T.Tuple[T.List[T.Dict[str,
self.cmake_options += cmake_defines_to_args(args[0])

@typed_pos_args('subproject_options.set_override_option', str, str)
@permittedKwargs({'target'})
def set_override_option(self, state: ModuleState, args: T.Tuple[str, str], kwargs: TYPE_kwargs) -> None:
@typed_kwargs('subproject_options.set_override_option', _TARGET_KW)
def set_override_option(self, state: ModuleState, args: T.Tuple[str, str], kwargs: TargetKW) -> None:
self._get_opts(kwargs).set_opt(args[0], args[1])

@typed_pos_args('subproject_options.set_install', bool)
@permittedKwargs({'target'})
def set_install(self, state: ModuleState, args: T.Tuple[bool], kwargs: TYPE_kwargs) -> None:
@typed_kwargs('subproject_options.set_install', _TARGET_KW)
def set_install(self, state: ModuleState, args: T.Tuple[bool], kwargs: TargetKW) -> None:
self._get_opts(kwargs).set_install(args[0])

@typed_pos_args('subproject_options.append_compile_args', str, varargs=str, min_varargs=1)
@permittedKwargs({'target'})
def append_compile_args(self, state: ModuleState, args: T.Tuple[str, T.List[str]], kwargs: TYPE_kwargs) -> None:
@typed_kwargs('subproject_options.append_compile_args', _TARGET_KW)
def append_compile_args(self, state: ModuleState, args: T.Tuple[str, T.List[str]], kwargs: TargetKW) -> None:
self._get_opts(kwargs).append_args(args[0], args[1])

@typed_pos_args('subproject_options.append_link_args', varargs=str, min_varargs=1)
@permittedKwargs({'target'})
def append_link_args(self, state: ModuleState, args: T.Tuple[T.List[str]], kwargs: TYPE_kwargs) -> None:
@typed_kwargs('subproject_options.append_link_args', _TARGET_KW)
def append_link_args(self, state: ModuleState, args: T.Tuple[T.List[str]], kwargs: TargetKW) -> None:
self._get_opts(kwargs).append_link_args(args[0])

@noPosargs
Expand Down

0 comments on commit 6041a75

Please sign in to comment.