Skip to content

Commit

Permalink
fix using a CustomTargetIndex for vs_module_defs
Browse files Browse the repository at this point in the history
Because `CustomTargetIndex`es don't have a `subdir` property, but they do
implement the `get_subdir()` method
  • Loading branch information
dcbaker committed Jul 31, 2023
1 parent 4573c02 commit 7127baa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/markdown/snippets/vs_module_defs_customtargetindex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## vs_module_defs keyword now supports indexes of custom_target

This means you can do something like:
```meson
defs = custom_target('generate_module_defs', ...)
shared_library('lib1', vs_module_defs : defs[0])
shared_library('lib2', vs_module_defs : defs[2])
```
4 changes: 2 additions & 2 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2383,9 +2383,9 @@ def process_kwargs(self, kwargs):
elif isinstance(path, File):
# When passing a generated file.
self.vs_module_defs = path
elif isinstance(path, CustomTarget):
elif isinstance(path, (CustomTarget, CustomTargetIndex)):
# When passing output of a Custom Target
self.vs_module_defs = File.from_built_file(path.subdir, path.get_filename())
self.vs_module_defs = File.from_built_file(path.get_subdir(), path.get_filename())
else:
raise InvalidArguments(
'Shared library vs_module_defs must be either a string, '
Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,19 @@ class StaticLibrary(_BuildTarget):

class SharedLibrary(_BuildTarget):

vs_module_def: T.Optional[T.Union[str, File, build.CustomTarget]]
vs_module_def: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]]


class SharedModule(_BuildTarget):

vs_module_def: T.Optional[T.Union[str, File, build.CustomTarget]]
vs_module_def: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]]


class Library(_BuildTarget):

"""For library, both_library, and as a base for build_target"""

vs_module_def: T.Optional[T.Union[str, File, build.CustomTarget]]
vs_module_def: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]]


class BuildTarget(Library):
Expand Down
5 changes: 3 additions & 2 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,10 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
KwargInfo('verbose', bool, default=False, since='0.62.0'),
]

_VS_MODULE_DEF_KW: KwargInfo[T.Union[str, File, CustomTarget]] = KwargInfo(
_VS_MODULE_DEF_KW: KwargInfo[T.Union[str, File, CustomTarget, CustomTargetIndex]] = KwargInfo(
'vs_module_defs',
(str, File, CustomTarget, NoneType),
(str, File, CustomTarget, CustomTargetIndex, NoneType),
since_values={CustomTargetIndex: '1.3.0'}
)

# Applies to all build_target like classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ def_file = custom_target('gen_def',
output: 'somedll.def')

shlib = shared_library('somedll', 'somedll.c', vs_module_defs: def_file)

shared_library('somedll2', 'somedll.c', vs_module_defs: def_file[0])

0 comments on commit 7127baa

Please sign in to comment.