Repository: mesonbuild/meson (Python)

Issue:
[0.58.0] test() fails with nested environment variables
**Describe the bug**
Regressed by 598e968993da58 (found [downstream](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255550#c2)). At least [libglvnd](http://www.ipv6proxy.net/go.php?u=http://package18.nyi.freebsd.org/data/122amd64-default-foo/2021-05-03_09h14m29s/logs/libglvnd-1.3.2.log), [libvirt](http://www.ipv6proxy.net/go.php?u=http://package18.nyi.freebsd.org/data/122amd64-default-foo/2021-05-03_09h14m29s/logs/libvirt-7.2.0.log), [nautilus](http://www.ipv6proxy.net/go.php?u=http://package18.nyi.freebsd.org/data/122amd64-default-foo/2021-05-03_09h14m29s/logs/nautilus-3.36.3.log) fail with `ERROR: List item must be one of <class 'str'>, not <class 'list'>`

**To Reproduce**
```meson
project('test', 'c')

runutf8 = [ 'LC_ALL=', 'LANG=C', 'LC_CTYPE=en_US.UTF-8' ]

add_test_setup(
  'access',
  env: [
    'VIR_TEST_FILE_ACCESS=1',
    runutf8,
  ],
  exe_wrapper: [ 'true' ],
)
```

**Expected behavior**
Build passes or maybe docs updated.

**system parameters**
* native build
* FreeBSD 11.4 / 12.2 / 13.0 / -CURRENT
* Python 3.8.9 / 3.9.4
* Meson 0.58.0
* Ninja 1.10.2



Discussion:
@xclaesse 
Should be fixed by https://github.com/mesonbuild/meson/pull/8761.



Patch:
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index 7d43752cfcf4..10e681aeb46f 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -165,7 +165,9 @@ def __init__(self, initial_values=None, subproject: str = ''):
             for k, v in initial_values.items():
                 self.set_method([k, v], {})
         elif initial_values is not None:
-            for e in mesonlib.stringlistify(initial_values):
+            for e in mesonlib.listify(initial_values):
+                if not isinstance(e, str):
+                    raise InterpreterException('Env var definition must be a list of strings.')
                 if '=' not in e:
                     raise InterpreterException('Env var definition must be of type key=val.')
                 (k, val) = e.split('=', 1)


Test patch:
diff --git a/test cases/common/41 test args/meson.build b/test cases/common/41 test args/meson.build
index 81d34915abec..b21f1ad00b12 100644
--- a/test cases/common/41 test args/meson.build
+++ b/test cases/common/41 test args/meson.build
@@ -23,7 +23,7 @@ test('environment variables 2', e3, env : env2)
 env_array = ['MESONTESTING=picklerror']
 testfile = files('testfile.txt')
 testerpy = find_program('tester.py')
-test('file arg', testerpy, args : testfile, env : env_array)
+test('file arg', testerpy, args : testfile, env : [env_array, 'TEST_LIST_FLATTENING=1'])
 
 copy = find_program('copyfile.py')
 tester = executable('tester', 'tester.c')
diff --git a/test cases/common/41 test args/tester.py b/test cases/common/41 test args/tester.py
index 0b4010ab9093..b5884cc61a2f 100755
--- a/test cases/common/41 test args/tester.py
+++ b/test cases/common/41 test args/tester.py
@@ -1,6 +1,10 @@
 #!/usr/bin/env python3
 
 import sys
+import os
+
+assert os.environ['MESONTESTING'] == 'picklerror'
+assert os.environ['TEST_LIST_FLATTENING'] == '1'
 
 with open(sys.argv[1]) as f:
     if f.read() != 'contents\n':