aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Fs-module.md18
-rw-r--r--mesonbuild/modules/fs.py13
-rw-r--r--test cases/common/227 fs module/meson.build4
3 files changed, 33 insertions, 2 deletions
diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md
index 64883c0..274788c 100644
--- a/docs/markdown/Fs-module.md
+++ b/docs/markdown/Fs-module.md
@@ -165,6 +165,24 @@ new = fs.replace_suffix(original, '') # /opt/foo.dll
Returns the parent directory (i.e. dirname).
+```meson
+new = fs.parent('foo/bar') # foo
+new = fs.parent('foo/bar/baz.dll') # foo/bar
+```
+
### name
Returns the last component of the path (i.e. basename).
+
+```meson
+fs.name('foo/bar/baz.dll.a') # baz.dll.a
+```
+
+### stem
+
+Returns the last component of the path, dropping the last part of the suffix
+
+```meson
+fs.stem('foo/bar/baz.dll') # baz
+fs.stem('foo/bar/baz.dll.a') # baz.dll
+```
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index f006500..f4fe06f 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -165,7 +165,7 @@ class FSModule(ExtensionModule):
@noKwargs
def parent(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
if len(args) != 1:
- raise MesonException('method takes exactly one argument.')
+ raise MesonException('fs.parent takes exactly one argument.')
original = PurePath(args[0])
new = original.parent
return ModuleReturnValue(str(new), [])
@@ -174,10 +174,19 @@ class FSModule(ExtensionModule):
@noKwargs
def name(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
if len(args) != 1:
- raise MesonException('method takes exactly one argument.')
+ raise MesonException('fs.name takes exactly one argument.')
original = PurePath(args[0])
new = original.name
return ModuleReturnValue(str(new), [])
+ @stringArgs
+ @noKwargs
+ def stem(self, state: 'ModuleState', args: T.Sequence[str], kwargs: dict) -> ModuleReturnValue:
+ if len(args) != 1:
+ raise MesonException('fs.stem takes exactly one argument.')
+ original = PurePath(args[0])
+ new = original.stem
+ return ModuleReturnValue(str(new), [])
+
def initialize(*args, **kwargs) -> FSModule:
return FSModule(*args, **kwargs)
diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build
index 8a77fdf..a732768 100644
--- a/test cases/common/227 fs module/meson.build
+++ b/test cases/common/227 fs module/meson.build
@@ -107,7 +107,11 @@ if not is_windows and build_machine.system() != 'cygwin' and is_git_checkout
assert(fs.is_samepath('a_symlink', 'meson.build'), 'symlink is_samepath fail')
endif
+# parts of path
assert(fs.parent('foo/bar') == 'foo', 'failed to get dirname')
assert(fs.name('foo/bar') == 'bar', 'failed to get basename')
+assert(fs.name('foo/bar/baz.dll.a') == 'baz.dll.a', 'failed to get basename with compound suffix')
+assert(fs.stem('foo/bar/baz.dll') == 'baz', 'failed to get stem with suffix')
+assert(fs.stem('foo/bar/baz.dll.a') == 'baz.dll', 'failed to get stem with compound suffix')
subdir('subdir')