interpreter: handle implib/export_dynamic conflicts in the interpreter

This differentiates export_dynamic being explicitly set to False from it
being unset. This allows us to deprecate explicitly setting
export_dynamic to false, but setting implib. This is already the case in
the other direction, if implib is False but export_dynamic is enabled
then we get a hard error.

This also moves the validation up to the Interpreter and out of the
build level.
pull/12315/head
Dylan Baker 1 year ago
parent c9bdf441dd
commit 937aab09c0
  1. 4
      mesonbuild/build.py
  2. 16
      mesonbuild/interpreter/interpreter.py
  3. 2
      mesonbuild/interpreter/kwargs.py
  4. 2
      mesonbuild/interpreter/type_checking.py

@ -1938,10 +1938,6 @@ class Executable(BuildTarget):
self.implib = kwargs.get('implib') self.implib = kwargs.get('implib')
if not isinstance(self.implib, (bool, str, type(None))): if not isinstance(self.implib, (bool, str, type(None))):
raise InvalidArguments('"export_dynamic" keyword argument must be a boolean or string') raise InvalidArguments('"export_dynamic" keyword argument must be a boolean or string')
if self.implib:
self.export_dynamic = True
if self.export_dynamic and self.implib is False:
raise InvalidArguments('"implib" keyword argument must not be false for if "export_dynamic" is true')
# Only linkwithable if using export_dynamic # Only linkwithable if using export_dynamic
self.is_linkwithable = self.export_dynamic self.is_linkwithable = self.export_dynamic
# Remember that this exe was returned by `find_program()` through an override # Remember that this exe was returned by `find_program()` through an override

@ -3327,6 +3327,7 @@ class Interpreter(InterpreterBase, HoldableObject):
kwargs['include_directories'] = self.extract_incdirs(kwargs) kwargs['include_directories'] = self.extract_incdirs(kwargs)
if targetclass is build.Executable: if targetclass is build.Executable:
kwargs = T.cast('kwtypes.Executable', kwargs)
if kwargs['gui_app'] is not None: if kwargs['gui_app'] is not None:
if kwargs['win_subsystem'] is not None: if kwargs['win_subsystem'] is not None:
raise InvalidArguments.from_node( raise InvalidArguments.from_node(
@ -3337,6 +3338,21 @@ class Interpreter(InterpreterBase, HoldableObject):
if kwargs['win_subsystem'] is None: if kwargs['win_subsystem'] is None:
kwargs['win_subsystem'] = 'console' kwargs['win_subsystem'] = 'console'
if kwargs['implib']:
if kwargs['export_dynamic'] is False:
FeatureDeprecated.single_use('implib overrides explict export_dynamic off', '1.3.0', self.subprojct,
'Do not set ths if want export_dynamic disabled if implib is enabled',
location=node)
kwargs['export_dynamic'] = True
elif kwargs['export_dynamic']:
if kwargs['implib'] is False:
raise InvalidArguments('"implib" keyword" must not be false if "export_dynamic" is set and not false.')
kwargs['implib'] = True
if kwargs['export_dynamic'] is None:
kwargs['export_dynamic'] = False
if kwargs['implib'] is None:
kwargs['implib'] = False
target = targetclass(name, self.subdir, self.subproject, for_machine, srcs, struct, objs, target = targetclass(name, self.subdir, self.subproject, for_machine, srcs, struct, objs,
self.environment, self.compilers[for_machine], kwargs) self.environment, self.compilers[for_machine], kwargs)

@ -340,7 +340,7 @@ class _LibraryMixin(TypedDict):
class Executable(_BuildTarget): class Executable(_BuildTarget):
export_dynamic: bool export_dynamic: T.Optional[bool]
gui_app: T.Optional[bool] gui_app: T.Optional[bool]
implib: T.Optional[T.Union[str, bool]] implib: T.Optional[T.Union[str, bool]]
pie: T.Optional[bool] pie: T.Optional[bool]

@ -588,7 +588,7 @@ _DARWIN_VERSIONS_KW: KwargInfo[T.List[T.Union[str, int]]] = KwargInfo(
# Arguments exclusive to Executable. These are separated to make integrating # Arguments exclusive to Executable. These are separated to make integrating
# them into build_target easier # them into build_target easier
_EXCLUSIVE_EXECUTABLE_KWS: T.List[KwargInfo] = [ _EXCLUSIVE_EXECUTABLE_KWS: T.List[KwargInfo] = [
KwargInfo('export_dynamic', bool, default=False, since='0.45.0'), KwargInfo('export_dynamic', (bool, NoneType), since='0.45.0'),
KwargInfo('gui_app', (bool, NoneType), deprecated='0.56.0', deprecated_message="Use 'win_subsystem' instead"), KwargInfo('gui_app', (bool, NoneType), deprecated='0.56.0', deprecated_message="Use 'win_subsystem' instead"),
KwargInfo('implib', (bool, str, NoneType), since='0.42.0'), KwargInfo('implib', (bool, str, NoneType), since='0.42.0'),
KwargInfo('pie', (bool, NoneType)), KwargInfo('pie', (bool, NoneType)),

Loading…
Cancel
Save