diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2014-04-16 19:09:19 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2014-04-16 19:09:19 +0300 |
commit | ac2d7e3440156805003b0a059d20384294a4972e (patch) | |
tree | eb4d22b12ff0064ff8698260c51e9fec7d24e23f | |
parent | 52084bdf8856f5955da4e70df7ea7bf53aea1d96 (diff) | |
download | meson-ac2d7e3440156805003b0a059d20384294a4972e.zip meson-ac2d7e3440156805003b0a059d20384294a4972e.tar.gz meson-ac2d7e3440156805003b0a059d20384294a4972e.tar.bz2 |
Added string splitting and with that a file grabber test case.
-rw-r--r-- | interpreter.py | 42 | ||||
-rw-r--r-- | test cases/common/55 file grabber/a.c | 1 | ||||
-rw-r--r-- | test cases/common/55 file grabber/b.c | 1 | ||||
-rw-r--r-- | test cases/common/55 file grabber/c.c | 1 | ||||
-rw-r--r-- | test cases/common/55 file grabber/grabber.bat | 5 | ||||
-rwxr-xr-x | test cases/common/55 file grabber/grabber.sh | 5 | ||||
-rw-r--r-- | test cases/common/55 file grabber/meson.build | 28 | ||||
-rw-r--r-- | test cases/common/55 file grabber/prog.c | 7 |
8 files changed, 80 insertions, 10 deletions
diff --git a/interpreter.py b/interpreter.py index d81b47e..d09622a 100644 --- a/interpreter.py +++ b/interpreter.py @@ -63,9 +63,9 @@ class TryRunResultHolder(InterpreterObject): class RunProcess(InterpreterObject): - def __init__(self, command_array, curdir): + def __init__(self, command_array, source_dir, build_dir, subdir): super().__init__() - pc = self.run_command(command_array, curdir) + pc = self.run_command(command_array, source_dir, build_dir, subdir) (stdout, stderr) = pc.communicate() self.returncode = pc.returncode self.stdout = stdout.decode() @@ -75,22 +75,31 @@ class RunProcess(InterpreterObject): 'stderr' : self.stderr_method, }) - def run_command(self, command_array, curdir): + def run_command(self, command_array, source_dir, build_dir, subdir): cmd_name = command_array[0] + env = {'MESON_SOURCE_ROOT' : source_dir, + 'MESON_BUILD_ROOT' : build_dir, + 'MESON_SUBDIR' : subdir} + cwd = os.path.join(source_dir, subdir) + child_env = os.environ.copy() + child_env.update(env) try: - return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=child_env, cwd=cwd) except FileNotFoundError: pass # Was not a command, is a program in path? exe = shutil.which(cmd_name) if exe is not None: command_array = [exe] + command_array[1:] - return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=child_env, cwd=cwd) # No? Maybe it is a script in the source tree. - fullpath = os.path.join(curdir, cmd_name) + fullpath = os.path.join(source_dir, subdir, cmd_name) command_array = [fullpath] + command_array[1:] try: - return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=child_env, cwd=cwd) except FileNotFoundError: raise InterpreterException('Could not execute command "%s".' % cmd_name) @@ -748,7 +757,7 @@ class Interpreter(): for i in args: if not isinstance(i, str): raise InterpreterObject('Run_command arguments must be strings.') - return RunProcess(args, os.path.join(self.environment.source_dir, self.subdir)) + return RunProcess(args, self.environment.source_dir, self.environment.build_dir, self.subdir) def func_gettext(self, nodes, args, kwargs): if len(args) != 1: @@ -1244,10 +1253,23 @@ class Interpreter(): return (reduced_pos, reduced_kw) def string_method_call(self, obj, method_name, args): + obj = self.to_native(obj) if method_name == 'strip': - return self.to_native(obj).strip() - if method_name == 'format': + return obj.strip() + elif method_name == 'format': return self.format_string(obj, args) + elif method_name == 'split': + (posargs, _) = self.reduce_arguments(args) + if len(posargs) > 1: + raise InterpreterException('Split() must have at most one argument.') + elif len(posargs) == 1: + s = posargs[0] + if not isinstance(s, str): + raise InterpreterException('Split() argument must be a string') + print(obj.split(s)) + return obj.split(s) + else: + return obj.split() raise InterpreterException('Unknown method "%s" for a string.' % method_name) def to_native(self, arg): diff --git a/test cases/common/55 file grabber/a.c b/test cases/common/55 file grabber/a.c new file mode 100644 index 0000000..bee8ad7 --- /dev/null +++ b/test cases/common/55 file grabber/a.c @@ -0,0 +1 @@ +int funca() { return 0; } diff --git a/test cases/common/55 file grabber/b.c b/test cases/common/55 file grabber/b.c new file mode 100644 index 0000000..0fdd162 --- /dev/null +++ b/test cases/common/55 file grabber/b.c @@ -0,0 +1 @@ +int funcb() { return 0; } diff --git a/test cases/common/55 file grabber/c.c b/test cases/common/55 file grabber/c.c new file mode 100644 index 0000000..63f951c --- /dev/null +++ b/test cases/common/55 file grabber/c.c @@ -0,0 +1 @@ +int funcc() { return 0; } diff --git a/test cases/common/55 file grabber/grabber.bat b/test cases/common/55 file grabber/grabber.bat new file mode 100644 index 0000000..5c95762 --- /dev/null +++ b/test cases/common/55 file grabber/grabber.bat @@ -0,0 +1,5 @@ +@echo off +echo a.c +echo b.c +echo c.c +echo prog.c diff --git a/test cases/common/55 file grabber/grabber.sh b/test cases/common/55 file grabber/grabber.sh new file mode 100755 index 0000000..5e8f4b9 --- /dev/null +++ b/test cases/common/55 file grabber/grabber.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +for i in *.c; do + echo $i +done diff --git a/test cases/common/55 file grabber/meson.build b/test cases/common/55 file grabber/meson.build new file mode 100644 index 0000000..c0c11b9 --- /dev/null +++ b/test cases/common/55 file grabber/meson.build @@ -0,0 +1,28 @@ +project('grabber', 'c') + +# What this script does is NOT reliable. Simply adding a file in this directory +# will NOT make it automatically appear in the build. You have to manually +# re-invoke Meson (not just Ninja) for that to happen. The simplest way +# is to touch meson-private/coredata.dat. + +# This is not the recommended way to do things, but if the tradeoffs are +# acceptable to you, then we're certainly not going to stop you. Just don't +# file bugs when it fails. :) + +if build.name() == 'windows' + c = run_command('grabber.bat') +else + c = run_command('grabber.sh') +endif + +if c.returncode() != 0 + error('Executing script failed.') +endif + +newline = ''' +''' + +sources = c.stdout().strip().split(newline) + +e = executable('prog', sources) +test('grabtest', e) diff --git a/test cases/common/55 file grabber/prog.c b/test cases/common/55 file grabber/prog.c new file mode 100644 index 0000000..3524f60 --- /dev/null +++ b/test cases/common/55 file grabber/prog.c @@ -0,0 +1,7 @@ +int funca(); +int funcb(); +int funcc(); + +int main(int argc, char **argv) { + return funca() + funcb() + funcc(); +} |