diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 23f590747..2bcf198a2 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2335,6 +2335,7 @@ class Interpreter(InterpreterBase): else: if not isinstance(envlist, list): envlist = [envlist] + # Convert from array to environment object env = EnvironmentVariablesHolder() for e in envlist: if '=' not in e: @@ -2344,7 +2345,7 @@ class Interpreter(InterpreterBase): val = val.strip() if ' ' in k: raise InterpreterException('Env var key must not have spaces in it.') - env.add_var(env.held_object.set, [k, val], kwargs) + env.set_method([k, val], {}) env = env.held_object return env diff --git a/test cases/common/48 test args/copyfile.py b/test cases/common/48 test args/copyfile.py new file mode 100644 index 000000000..ff42ac359 --- /dev/null +++ b/test cases/common/48 test args/copyfile.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +import sys +import shutil + +shutil.copyfile(sys.argv[1], sys.argv[2]) diff --git a/test cases/common/48 test args/meson.build b/test cases/common/48 test args/meson.build index f599bf7e2..81d34915a 100644 --- a/test cases/common/48 test args/meson.build +++ b/test cases/common/48 test args/meson.build @@ -18,4 +18,18 @@ env2.set('first', 'something-else') test('command line arguments', e1, args : ['first', 'second']) test('environment variables', e2, env : env) test('environment variables 2', e3, env : env2) -test('file arg', find_program('tester.py'), args : files('testfile.txt')) + +# https://github.com/mesonbuild/meson/issues/2211#issuecomment-327741571 +env_array = ['MESONTESTING=picklerror'] +testfile = files('testfile.txt') +testerpy = find_program('tester.py') +test('file arg', testerpy, args : testfile, env : env_array) + +copy = find_program('copyfile.py') +tester = executable('tester', 'tester.c') +testfilect = custom_target('testfile', + input : testfile, + output : 'outfile.txt', + build_by_default : true, + command : [copy, '@INPUT@', '@OUTPUT@']) +test('custom target arg', tester, args : testfilect, env : env_array) diff --git a/test cases/common/48 test args/tester.c b/test cases/common/48 test args/tester.c new file mode 100644 index 000000000..28aa0dbfb --- /dev/null +++ b/test cases/common/48 test args/tester.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#ifndef _MSC_VER +#include +#endif + +int main(int argc, char **argv) { + char data[10]; + int fd, size; + + if (argc != 2) { + fprintf(stderr, "Incorrect number of arguments, got %i\n", argc); + return 1; + } + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "First argument is wrong.\n"); + return 1; + } + + size = read(fd, data, 10); + if (size < 0) { + fprintf(stderr, "Failed to read: %s\n", strerror(errno)); + return 1; + } + if (strcmp(data, "contents\n") != 0) { + fprintf(stderr, "Contents don't match, got %s\n", data); + return 1; + } + return 0; +}