Skip to content

Commit

Permalink
Add FS module support for CustomTarget, CustomTargetIndex, and BuildT…
Browse files Browse the repository at this point in the history
…arget

This adds functionality for stem, name, parent and replace_suffix.
  • Loading branch information
tristan957 committed Oct 22, 2023
1 parent c82f51d commit 3159245
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
9 changes: 9 additions & 0 deletions docs/markdown/snippets/additional_types_for_fs_module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 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`
- `fs.stem`
24 changes: 16 additions & 8 deletions mesonbuild/modules/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3159245

Please sign in to comment.