From f12c0f31e27ca37400c5ca8deb700af222f0bcb6 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 9 Oct 2016 05:29:11 -0400 Subject: [PATCH 11/16] Created path_join function. (cherry picked from commit c2b852c9b392059cba933b0787c1c7880af5e1ae) --- mesonbuild/interpreter.py | 10 ++++++++++ test cases/common/119 pathjoin/meson.build | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 test cases/common/119 pathjoin/meson.build diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index b3bb1f2..be19bab 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 0000000..dd1cf9c --- /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') + -- 2.10.1