Skip to content

Commit f5d81d0

Browse files
committed
interpreter: Robustly covert executable arguments to shared_library arguments
This extends the code that strips executable keyword arguments to also default populate shared_library exclusive arguments. Fixes: #15238
1 parent ee76b3c commit f5d81d0

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

mesonbuild/interpreter/interpreter.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
CT_BUILD_BY_DEFAULT,
5555
CT_INPUT_KW,
5656
CT_INSTALL_DIR_KW,
57-
_EXCLUSIVE_EXECUTABLE_KWS,
57+
EXCLUSIVE_EXECUTABLE_KWS,
5858
EXECUTABLE_KWS,
5959
JAR_KWS,
6060
LIBRARY_KWS,
@@ -1813,22 +1813,26 @@ def func_dependency(self, node: mparser.BaseNode, args: T.Tuple[T.List[str]], kw
18131813
def func_disabler(self, node, args, kwargs):
18141814
return Disabler()
18151815

1816-
def _strip_exe_specific_kwargs(self, kwargs: kwtypes.Executable) -> kwtypes._BuildTarget:
1817-
kwargs = kwargs.copy()
1818-
for exe_kwarg in _EXCLUSIVE_EXECUTABLE_KWS:
1819-
del kwargs[exe_kwarg.name]
1820-
return kwargs
1816+
def _exe_to_shlib_kwargs(self, kwargs: kwtypes.Executable) -> kwtypes.SharedLibrary:
1817+
nkwargs = T.cast('kwtypes.SharedLibrary', kwargs.copy())
1818+
for exe_kwarg in EXCLUSIVE_EXECUTABLE_KWS:
1819+
del nkwargs[exe_kwarg.name] # type: ignore[misc]
1820+
for sh_kwarg in SHARED_LIB_KWS:
1821+
nkwargs.setdefault(sh_kwarg.name, sh_kwarg.default) # type: ignore[misc]
1822+
nkwargs['rust_abi'] = None
1823+
nkwargs['rust_crate_type'] = 'cdylib'
1824+
return nkwargs
18211825

18221826
@permittedKwargs(build.known_exe_kwargs)
18231827
@typed_pos_args('executable', str, varargs=SOURCES_VARARGS)
18241828
@typed_kwargs('executable', *EXECUTABLE_KWS, allow_unknown=True)
18251829
def func_executable(self, node: mparser.BaseNode,
18261830
args: T.Tuple[str, SourcesVarargsType],
1827-
kwargs: kwtypes.Executable) -> build.Executable:
1831+
kwargs: kwtypes.Executable) -> T.Union[build.Executable, build.SharedLibrary]:
18281832
for_machine = kwargs['native']
18291833
m = self.environment.machines[for_machine]
18301834
if m.is_android() and kwargs.get('android_exe_type') == 'application':
1831-
holder = self.build_target(node, args, self._strip_exe_specific_kwargs(kwargs), build.SharedLibrary)
1835+
holder = self.build_target(node, args, self._exe_to_shlib_kwargs(kwargs), build.SharedLibrary)
18321836
holder.shared_library_only = True
18331837
return holder
18341838
return self.build_target(node, args, kwargs, build.Executable)

mesonbuild/interpreter/type_checking.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
808808

809809
# Arguments exclusive to Executable. These are separated to make integrating
810810
# them into build_target easier
811-
_EXCLUSIVE_EXECUTABLE_KWS: T.List[KwargInfo] = [
811+
EXCLUSIVE_EXECUTABLE_KWS: T.List[KwargInfo] = [
812812
KwargInfo('export_dynamic', (bool, NoneType), since='0.45.0'),
813813
KwargInfo('gui_app', (bool, NoneType), deprecated='0.56.0', deprecated_message="Use 'win_subsystem' instead"),
814814
KwargInfo(
@@ -837,7 +837,7 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
837837
# The total list of arguments used by Executable
838838
EXECUTABLE_KWS = [
839839
*_BUILD_TARGET_KWS,
840-
*_EXCLUSIVE_EXECUTABLE_KWS,
840+
*EXCLUSIVE_EXECUTABLE_KWS,
841841
_VS_MODULE_DEFS_KW.evolve(since='1.3.0', since_values=None),
842842
_JAVA_LANG_KW,
843843
]
@@ -877,7 +877,7 @@ def _shortname_validator(shortname: T.Optional[str]) -> T.Optional[str]:
877877
]
878878

879879
# The total list of arguments used by SharedLibrary
880-
SHARED_LIB_KWS = [
880+
SHARED_LIB_KWS: T.List[KwargInfo] = [
881881
*_BUILD_TARGET_KWS,
882882
*_EXCLUSIVE_SHARED_LIB_KWS,
883883
*_EXCLUSIVE_LIB_KWS,
@@ -945,7 +945,7 @@ def _shortname_validator(shortname: T.Optional[str]) -> T.Optional[str]:
945945
*_EXCLUSIVE_SHARED_LIB_KWS,
946946
*_EXCLUSIVE_SHARED_MOD_KWS,
947947
*_EXCLUSIVE_STATIC_LIB_KWS,
948-
*_EXCLUSIVE_EXECUTABLE_KWS,
948+
*EXCLUSIVE_EXECUTABLE_KWS,
949949
*_SHARED_STATIC_ARGS,
950950
RUST_ABI_KW.evolve(since='1.10.0'),
951951
*[a.evolve(deprecated='1.3.0', deprecated_message='The use of "jar" in "build_target()" is deprecated, and this argument is only used by jar()')

0 commit comments

Comments
 (0)