diff --git a/docs/markdown/Fs-module.md b/docs/markdown/Fs-module.md index 9a3ab1040..45cb589da 100644 --- a/docs/markdown/Fs-module.md +++ b/docs/markdown/Fs-module.md @@ -73,7 +73,7 @@ fs.samefile(x, z) # true The `replace_suffix` method is a *string manipulation* convenient for filename modifications. It allows changing the filename suffix like: -## swap suffix +#### swap suffix ```meson original = '/opt/foo.ini' diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index 0c8ed8e1b..86861ae08 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -114,7 +114,7 @@ class FSModule(ExtensionModule): def replace_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: if len(args) != 2: MesonException('method takes exactly two arguments.') - original = PurePath(state.source_root) / state.subdir / args[0] + original = PurePath(args[0]) new = original.with_suffix(args[1]) return ModuleReturnValue(str(new), []) diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index ec9ca935a..3c452d08c 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -25,19 +25,19 @@ assert(not fs.is_file('~'), 'expanduser not working') original = 'foo.txt' new = fs.replace_suffix(original, '.ini') -assert(new.endswith('foo.ini') and not new.contains('.txt'), 'replace_suffix failed') +assert(new == 'foo.ini', 'replace_suffix failed') original = 'foo' new = fs.replace_suffix(original, '.ini') -assert(new.endswith('foo.ini'), 'replace_suffix did not add suffix to suffixless file') +assert(new == 'foo.ini', 'replace_suffix did not add suffix to suffixless file') original = 'foo.dll.a' new = fs.replace_suffix(original, '.so') -assert(new.endswith('foo.dll.so'), 'replace_suffix did not only modify last suffix') +assert(new == 'foo.dll.so', 'replace_suffix did not only modify last suffix') original = 'foo.dll' new = fs.replace_suffix(original, '') -assert(new.endswith('foo'), 'replace_suffix did not only delete last suffix') +assert(new == 'foo', 'replace_suffix did not only delete last suffix') # `/` on windows is interpreted like `.drive` which in general may not be `c:/` # the files need not exist for fs.replace_suffix()