interpreter: use typed_kwargs for shared_library(version)

pull/12125/head
Dylan Baker 1 year ago
parent 90ce084144
commit cd676e229b
  1. 9
      mesonbuild/build.py
  2. 9
      mesonbuild/interpreter/kwargs.py
  3. 11
      mesonbuild/interpreter/type_checking.py

@ -2139,7 +2139,7 @@ class SharedLibrary(BuildTarget):
compilers: T.Dict[str, 'Compiler'],
kwargs):
self.soversion = None
self.ltversion = None
self.ltversion: T.Optional[str] = None
# Max length 2, first element is compatibility_version, second is current_version
self.darwin_versions = []
self.vs_module_defs = None
@ -2350,12 +2350,7 @@ class SharedLibrary(BuildTarget):
if not self.environment.machines[self.for_machine].is_android():
# Shared library version
if 'version' in kwargs:
self.ltversion = kwargs['version']
if not isinstance(self.ltversion, str):
raise InvalidArguments('Shared library version needs to be a string, not ' + type(self.ltversion).__name__)
if not re.fullmatch(r'[0-9]+(\.[0-9]+){0,2}', self.ltversion):
raise InvalidArguments(f'Invalid Shared library version "{self.ltversion}". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.')
self.ltversion = T.cast('T.Optional[str]', kwargs.get('version'))
# Try to extract/deduce the soversion
if 'soversion' in kwargs:
self.soversion = kwargs['soversion']

@ -338,7 +338,12 @@ class StaticLibrary(_BuildTarget):
pass
class SharedLibrary(_BuildTarget):
class _SharedLibMixin(TypedDict):
version: T.Optional[str]
class SharedLibrary(_BuildTarget, _SharedLibMixin):
pass
@ -346,7 +351,7 @@ class SharedModule(_BuildTarget):
pass
class Library(_BuildTarget):
class Library(_BuildTarget, _SharedLibMixin):
"""For library, both_library, and as a base for build_target"""

@ -119,6 +119,13 @@ def _lower_strlist(input: T.List[str]) -> T.List[str]:
return [i.lower() for i in input]
def _validate_shlib_version(val: T.Optional[str]) -> T.Optional[str]:
if val is not None and not re.fullmatch(r'[0-9]+(\.[0-9]+){0,2}', val):
return (f'Invalid Shared library version "{val}". '
'Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.')
return None
def variables_validator(contents: T.Union[str, T.List[str], T.Dict[str, str]]) -> T.Optional[str]:
if isinstance(contents, str):
contents = [contents]
@ -527,7 +534,9 @@ STATIC_LIB_KWS = [
# Arguments exclusive to SharedLibrary. These are separated to make integrating
# them into build_target easier
_EXCLUSIVE_SHARED_LIB_KWS: T.List[KwargInfo] = []
_EXCLUSIVE_SHARED_LIB_KWS: T.List[KwargInfo] = [
KwargInfo('version', (str, NoneType), validator=_validate_shlib_version)
]
# The total list of arguments used by SharedLibrary
SHARED_LIB_KWS = [

Loading…
Cancel
Save