Skip to content

Commit

Permalink
RFC: warn when specifying nonsense soversion that doesn't match versi…
Browse files Browse the repository at this point in the history
…on conventions somehow
  • Loading branch information
eli-schwartz committed Aug 20, 2024
1 parent 18f4a05 commit eabc51b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
20 changes: 17 additions & 3 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,21 @@ 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]:
def _validate_shlib_version(val: T.Optional[str], weak: bool = False) -> T.Optional[str]:
term = 'Should' if weak else 'Must'
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.')
f'{term} be of the form X.Y.Z where all three are numbers. Y and Z are optional')
return None

def _validate_shlib_soversion(val: T.Optional[T.Union[str, int]]) -> T.Optional[str]:
val2: T.Optional[str]
if isinstance(val, int):
val2 = str(val)
else:
val2 = val
return _validate_shlib_version(val2, weak=True)


def variables_validator(contents: T.Union[str, T.List[str], T.Dict[str, str]]) -> T.Optional[str]:
if isinstance(contents, str):
Expand Down Expand Up @@ -744,7 +753,12 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
# them into build_target easier
_EXCLUSIVE_SHARED_LIB_KWS: T.List[KwargInfo] = [
_DARWIN_VERSIONS_KW,
KwargInfo('soversion', (str, int, NoneType), convertor=lambda x: str(x) if x is not None else None),
KwargInfo(
'soversion',
(str, int, NoneType),
convertor=lambda x: str(x) if x is not None else None,
deprecated_values={_validate_shlib_soversion: '1.6.0'}
),
KwargInfo('version', (str, NoneType), validator=_validate_shlib_version),
]

Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/interpreterbase/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ def emit_feature_change(values: T.Dict[_T, T.Union[str, T.Tuple[str, str]]], fea
elif isinstance(n, type):
if isinstance(value, n):
warning = f'of type {n.__name__}'
elif callable(n):
warning = n(value)
elif isinstance(value, list):
if n in value:
warning = f'value "{n}" in list'
Expand Down
6 changes: 5 additions & 1 deletion test cases/linuxlike/7 library versions/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('library versions', 'c')
project('library versions', 'c', meson_version: '>=0.37.0')

if host_machine.system() == 'cygwin'
error('MESON_SKIP_TEST linuxlike soversions not supported on Cygwin.')
Expand All @@ -21,6 +21,10 @@ onlysoversion = shared_library('onlysoversion', 'lib.c',
soversion : 5,
install : true)

warn_soversion = shared_library('warn_soversion', 'lib.c',
soversion: '1_2_3',
install: true)

# Hack to make the executables below depend on the shared libraries above
# without actually adding them as `link_with` dependencies since we want to try
# linking to them with -lfoo linker arguments.
Expand Down
10 changes: 9 additions & 1 deletion test cases/linuxlike/7 library versions/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
{"type": "file", "file": "usr/lib/libonlyversion.so.1.4.5"},
{"type": "file", "file": "usr/lib/libonlysoversion.so"},
{"type": "file", "file": "usr/lib/libonlysoversion.so.5"},
{"type": "file", "file": "usr/lib/libmodule.so"}
{"type": "file", "file": "usr/lib/libmodule.so"},
{"type": "file", "file": "usr/lib/libwarn_soversion.so"},
{"type": "file", "file": "usr/lib/libwarn_soversion.so.1_2_3"}
],
"stdout": [
{
"line": ".*\"shared_library\" keyword argument \"soversion\" Invalid Shared library version \"1_2_3\"\\. Should be of the form X\\.Y\\.Z where all three are numbers\\..*",
"match": "re"
}
]
}

0 comments on commit eabc51b

Please sign in to comment.