diff --git a/docs/markdown/snippets/additional_types_for_fs_module.md b/docs/markdown/snippets/additional_types_for_fs_module.md new file mode 100644 index 000000000000..cb5945886e71 --- /dev/null +++ b/docs/markdown/snippets/additional_types_for_fs_module.md @@ -0,0 +1,8 @@ +## Added support for `[[@build_tgt]]`, `[[@custom_tgt]]`, and `[[@custom_idx]]` to certain FS module functions + +Support for `[[@build_tgt]]`, `[[@custom_tgt]]`, and `[[@custom_idx]]` was +added to the following FS module APIs: + +- `fs.name` +- `fs.parent` +- `fs.replace_suffix` diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 8e48d29b16e9..9170ba382314 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -189,38 +189,46 @@ def is_samepath(self, state: 'ModuleState', args: T.Tuple['FileOrString', 'FileO return False @noKwargs - @typed_pos_args('fs.replace_suffix', (str, File), str) - def replace_suffix(self, state: 'ModuleState', args: T.Tuple['FileOrString', str], kwargs: T.Dict[str, T.Any]) -> str: + @typed_pos_args('fs.replace_suffix', (str, File, CustomTarget, CustomTargetIndex, BuildTarget), str) + def replace_suffix(self, state: 'ModuleState', args: T.Tuple[T.Union[FileOrString, BuildTargetTypes], str], kwargs: T.Dict[str, T.Any]) -> str: if isinstance(args[0], File): FeatureNew('fs.replace_suffix(file)', '0.59.0').use(state.subproject, location=state.current_node) + elif isinstance(args[0], (CustomTarget, CustomTargetIndex, BuildTarget)): + FeatureNew('fs.replace_suffix(build_tgt, custom_tgt, custom_idx)', '1.3.0').use(state.subproject, location=state.current_node) original = PurePath(str(args[0])) new = original.with_suffix(args[1]) return str(new) @noKwargs - @typed_pos_args('fs.parent', (str, File)) - def parent(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: T.Dict[str, T.Any]) -> str: + @typed_pos_args('fs.parent', (str, File, CustomTarget, CustomTargetIndex, BuildTarget)) + def parent(self, state: 'ModuleState', args: T.Tuple[T.Union[FileOrString, BuildTargetTypes]], kwargs: T.Dict[str, T.Any]) -> str: if isinstance(args[0], File): FeatureNew('fs.parent(file)', '0.59.0').use(state.subproject, location=state.current_node) + elif isinstance(args[0], (CustomTarget, CustomTargetIndex, BuildTarget)): + FeatureNew('fs.parent(build_tgt | custom_tgt | custom_idx)', '1.3.0').use(state.subproject, location=state.current_node) original = PurePath(str(args[0])) new = original.parent return str(new) @noKwargs - @typed_pos_args('fs.name', (str, File)) - def name(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: T.Dict[str, T.Any]) -> str: + @typed_pos_args('fs.name', (str, File, CustomTarget, CustomTargetIndex, BuildTarget)) + def name(self, state: 'ModuleState', args: T.Tuple[T.Union[FileOrString, BuildTargetTypes]], kwargs: T.Dict[str, T.Any]) -> str: if isinstance(args[0], File): FeatureNew('fs.name(file)', '0.59.0').use(state.subproject, location=state.current_node) + elif isinstance(args[0], (CustomTarget, CustomTargetIndex, BuildTarget)): + FeatureNew('fs.name(build_tgt | custom_tgt | custom_idx)', '1.3.0').use(state.subproject, location=state.current_node) original = PurePath(str(args[0])) new = original.name return str(new) @noKwargs - @typed_pos_args('fs.stem', (str, File)) + @typed_pos_args('fs.stem', (str, File, CustomTarget, CustomTargetIndex, BuildTarget)) @FeatureNew('fs.stem', '0.54.0') - def stem(self, state: 'ModuleState', args: T.Tuple['FileOrString'], kwargs: T.Dict[str, T.Any]) -> str: + def stem(self, state: 'ModuleState', args: T.Tuple[T.Union[FileOrString, BuildTargetTypes]], kwargs: T.Dict[str, T.Any]) -> str: if isinstance(args[0], File): FeatureNew('fs.stem(file)', '0.59.0').use(state.subproject, location=state.current_node) + elif isinstance(args[0], (CustomTarget, CustomTargetIndex, BuildTarget)): + FeatureNew('fs.stem(build_tgt | custom_tgt | custom_idx)', '1.3.0').use(state.subproject, location=state.current_node) original = PurePath(str(args[0])) new = original.stem return str(new)