Repository: mesonbuild/meson

Issue:
Incorrect handling of strings in cross file
A cross-file containing:

```
c_args = '-I /root/vlc/contrib/i686-w64-mingw32/include' 
cpp_args = '-I /root/vlc/contrib/i686-w64-mingw32/include' 
c_link_args = '-L /root/vlc/contrib/i686-w64-mingw32/lib' 
cpp_link_args =  '-L /root/vlc/contrib/i686-w64-mingw32/lib' 
```

is incorrectly handled by meson. Either it should error, because it expects an array, or treat this as one argument.

What happens instead is that meson treats the string as an array and produces a completely messed-up command line:

```
Sanity check compiler command line: i686-w64-mingw32-gcc - I   / r o o t / v l c / c o n t r i b / i 6 8 6 - w 6 4 - m i n g w 3 2 / i n c l u d e -c /root/vlc/contrib/contrib-win32/libplacebo/build/meson-private/sanitycheckc.c -o /root/vlc/contrib/contrib-win32/libplacebo/build/meson-private/sanitycheckc_cross.exe
Sanity check compile stdout:

-----
Sanity check compile stderr:
i686-w64-mingw32-gcc: error: I: No such file or directory
i686-w64-mingw32-gcc: error:  : No such file or directory
i686-w64-mingw32-gcc: error: r: No such file or directory
i686-w64-mingw32-gcc: error: o: No such file or directory
i686-w64-mingw32-gcc: error: o: No such file or directory
i686-w64-mingw32-gcc: error: t: No such file or directory
[…]
```


Discussion:
It should probably be an error as it expects an array.

Resolving patch:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1048,10 +1048,10 @@ def get_cross_extra_flags(self, environment, link):
             if 'properties' in environment.cross_info.config:
                 props = environment.cross_info.config['properties']
                 lang_args_key = self.language + '_args'
-                extra_flags += props.get(lang_args_key, [])
+                extra_flags += mesonlib.stringlistify(props.get(lang_args_key, []))
                 lang_link_args_key = self.language + '_link_args'
                 if link:
-                    extra_flags += props.get(lang_link_args_key, [])
+                    extra_flags += mesonlib.stringlistify(props.get(lang_link_args_key, []))
         return extra_flags
 
     def _get_compile_output(self, dirname, mode):


Test patch:
diff --git a/test cases/common/137 get define/meson.build b/test cases/common/137 get define/meson.build
--- a/test cases/common/137 get define/meson.build	
+++ b/test cases/common/137 get define/meson.build	
@@ -67,15 +67,9 @@ foreach lang : ['c', 'cpp']
 
   run_1665_test = false
   if meson.is_cross_build()
-    # Can't use an empty array as a fallback here because of
-    # https://github.com/mesonbuild/meson/issues/1481
-    lang_args = meson.get_cross_property(lang + '_args', [])
-    if lang_args.length() != 0
-      foreach lang_arg : lang_args
-        if lang_arg.contains('MESON_TEST_ISSUE_1665')
-          run_1665_test = true
-        endif
-      endforeach
+    lang_arg = meson.get_cross_property(lang + '_args', '')
+    if lang_arg == '-DMESON_TEST_ISSUE_1665=1'
+      run_1665_test = true
     endif
   endif