diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index b3bb1f2e7..be19babf0 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1196,6 +1196,7 @@ class Interpreter(): 'declare_dependency': self.func_declare_dependency, 'assert': self.func_assert, 'environment' : self.func_environment, + 'path_join' : self.func_path_join, } def parse_project(self): @@ -2237,6 +2238,15 @@ class Interpreter(): def func_environment(self, node, args, kwargs): return EnvironmentVariablesHolder() + @stringArgs + @noKwargs + def func_path_join(self, node, args, kwargs): + if isinstance(args, str): + st = (args,) + else: + st = tuple(args) + return os.path.join(*args).replace('\\', '/') + def flatten(self, args): if isinstance(args, mparser.StringNode): return args.value diff --git a/test cases/common/119 pathjoin/meson.build b/test cases/common/119 pathjoin/meson.build new file mode 100644 index 000000000..dd1cf9c9d --- /dev/null +++ b/test cases/common/119 pathjoin/meson.build @@ -0,0 +1,9 @@ +project('pathjoin', 'c') + +assert(path_join('foo') == 'foo', 'Single argument join is broken') +assert(path_join('foo', 'bar') == 'foo/bar', 'Path joining is broken') +assert(path_join('foo', 'bar', 'baz') == 'foo/bar/baz', 'Path joining is broken') +assert(path_join('/foo', 'bar') == '/foo/bar', 'Path joining is broken') +assert(path_join('foo', '/bar') == '/bar', 'Absolute path joining is broken') +assert(path_join('/foo', '/bar') == '/bar', 'Absolute path joining is broken') +