Skip to content

Commit

Permalink
interpreter: handle implib/export_dynamic conflicts in the interpreter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcbaker committed Sep 29, 2023
1 parent c9bdf44 commit 937aab0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 0 additions & 4 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,10 +1938,6 @@ def __init__(
self.implib = kwargs.get('implib')
if not isinstance(self.implib, (bool, str, type(None))):
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
self.is_linkwithable = self.export_dynamic
# Remember that this exe was returned by `find_program()` through an override
Expand Down
16 changes: 16 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,7 @@ def build_target_decorator_caller(self, node, args, kwargs):
kwargs['include_directories'] = self.extract_incdirs(kwargs)

if targetclass is build.Executable:
kwargs = T.cast('kwtypes.Executable', kwargs)
if kwargs['gui_app'] is not None:
if kwargs['win_subsystem'] is not None:
raise InvalidArguments.from_node(
Expand All @@ -3337,6 +3338,21 @@ def build_target_decorator_caller(self, node, args, kwargs):
if kwargs['win_subsystem'] is None:
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,
self.environment, self.compilers[for_machine], kwargs)

Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class _LibraryMixin(TypedDict):

class Executable(_BuildTarget):

export_dynamic: bool
export_dynamic: T.Optional[bool]
gui_app: T.Optional[bool]
implib: T.Optional[T.Union[str, bool]]
pie: T.Optional[bool]
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def _convert_darwin_versions(val: T.List[T.Union[str, int]]) -> T.Optional[T.Tup
# Arguments exclusive to Executable. These are separated to make integrating
# them into build_target easier
_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('implib', (bool, str, NoneType), since='0.42.0'),
KwargInfo('pie', (bool, NoneType)),
Expand Down

0 comments on commit 937aab0

Please sign in to comment.