From 5a8c3f127758d2e921a08c2c3918c8fa60f00139 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 31 Jul 2023 05:16:39 -0700 Subject: [PATCH] fix using a CustomTargetIndex for vs_module_defs Because `CustomTargetIndex`es don't have a `subdir` property, but they do implement the `get_subdir()` method --- .../markdown/snippets/vs_module_defs_customtargetindex.md | 8 ++++++++ docs/yaml/functions/shared_library.yaml | 2 ++ docs/yaml/functions/shared_module.yaml | 2 ++ mesonbuild/build.py | 6 +++--- mesonbuild/interpreter/kwargs.py | 4 ++-- mesonbuild/interpreter/type_checking.py | 5 +++-- .../subdir/meson.build | 2 ++ 7 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 docs/markdown/snippets/vs_module_defs_customtargetindex.md diff --git a/docs/markdown/snippets/vs_module_defs_customtargetindex.md b/docs/markdown/snippets/vs_module_defs_customtargetindex.md new file mode 100644 index 000000000000..d50d04ecb516 --- /dev/null +++ b/docs/markdown/snippets/vs_module_defs_customtargetindex.md @@ -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]) +``` diff --git a/docs/yaml/functions/shared_library.yaml b/docs/yaml/functions/shared_library.yaml index 5076b9341b2a..f633aca966fe 100644 --- a/docs/yaml/functions/shared_library.yaml +++ b/docs/yaml/functions/shared_library.yaml @@ -45,6 +45,8 @@ kwargs: Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows). + *(Since 1.3.0)* [[@custom_idx]] are supported + rust_abi: type: str since: 1.3.0 diff --git a/docs/yaml/functions/shared_module.yaml b/docs/yaml/functions/shared_module.yaml index 46086ba3096d..6b94e56add4a 100644 --- a/docs/yaml/functions/shared_module.yaml +++ b/docs/yaml/functions/shared_module.yaml @@ -40,6 +40,8 @@ kwargs: Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows). + *(Since 1.3.0)* [[@custom_idx]] are supported + rust_abi: type: str since: 1.3.0 diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 1c8f7781ee97..e83dcab539f4 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2333,13 +2333,13 @@ 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, ' - 'a file object or a Custom Target') + 'a file object, a Custom Target, or a Custom Target Index') self.process_link_depends(path) rust_abi = kwargs.get('rust_abi') diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 30f0a36fc53a..f95820ee04ad 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -353,7 +353,7 @@ class _SharedLibMixin(TypedDict): darwin_versions: T.Optional[T.Tuple[str, str]] soversion: T.Optional[str] version: T.Optional[str] - vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget]] + vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]] class SharedLibrary(_BuildTarget, _SharedLibMixin, _LibraryMixin): @@ -362,7 +362,7 @@ class SharedLibrary(_BuildTarget, _SharedLibMixin, _LibraryMixin): class SharedModule(_BuildTarget, _LibraryMixin): - vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget]] + vs_module_defs: T.Optional[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex]] class Library(_BuildTarget, _SharedLibMixin, _LibraryMixin): diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index e5684b8869ec..8cef0562a651 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -513,9 +513,10 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus since='1.3.0', validator=in_set_validator({'rust', 'c'})) -_VS_MODULE_DEFS_KW: KwargInfo[T.Optional[T.Union[str, File, CustomTarget]]] = KwargInfo( +_VS_MODULE_DEFS_KW: KwargInfo[T.Optional[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 diff --git a/test cases/windows/10 vs module defs generated custom target/subdir/meson.build b/test cases/windows/10 vs module defs generated custom target/subdir/meson.build index c4ae33ae4c29..027769244a36 100644 --- a/test cases/windows/10 vs module defs generated custom target/subdir/meson.build +++ b/test cases/windows/10 vs module defs generated custom target/subdir/meson.build @@ -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])