summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hirsch, Ph.D <scivision@users.noreply.github.com>2019-12-20 06:10:25 -0500
committerMichael Hirsch, Ph.D <10931741+scivision@users.noreply.github.com>2020-02-06 12:54:38 -0500
commit5bbeab8ed461bc2464d9b590b2faf758aa854362 (patch)
treea04df538dbca87a223dc0d0aee95aaa20bfa0163
parent92534855cc11e0939f769e19d995be0605be2fb2 (diff)
downloadmeson-5bbeab8ed461bc2464d9b590b2faf758aa854362.tar.gz
add fs.stem()
-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 64883c0e2..274788c99 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 f006500a3..f4fe06fef 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 8a77fdf2e..a73276826 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')