This allows each target to provide an additional list of cross
compilers to check. With this, we can detect default cc for common
setups (debian/fedora/macos) without user having to provide a
--cross-cc-* option.

In addition, it allows us to pick up host compilers for various hosts.
(debian and archlinux have $arch-linux-gnu-gcc installed
with gcc package by default, but not fedora).

Signed-off-by: Pierrick Bouvier <[email protected]>
---
 tests/tcg/meson.build | 46 +++++++++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build
index 0006d192cab..59ab73e1d10 100644
--- a/tests/tcg/meson.build
+++ b/tests/tcg/meson.build
@@ -21,6 +21,7 @@ tcg_tests = {}
 # {
 #   'name_of_target': {
 #     'cc': 'cross_compiler',
+#     'cc_alt': ['list of alternative cross compilers', ...]
 #     'cc_dockerfile': 'name_of_dockerfile',
 #     'cc_feat_cflags': {
 #       'name': ['feature cflags'],
@@ -210,7 +211,7 @@ foreach target, plan: tcg_tests
 
   # return a clear error if user misspell a target entry
   foreach key, _ : plan
-    allowed = ['cc', 'cc_dockerfile', 'cc_feat_cflags',
+    allowed = ['cc', 'cc_alt', 'cc_dockerfile', 'cc_feat_cflags',
                'folder', 'gdb_arch', 'gdb_feat_version', 'qemu', 'tests']
     if key not in allowed
       error('unknown tcg test plan entry \'' + key + '\' for target ' + target 
+
@@ -218,15 +219,18 @@ foreach target, plan: tcg_tests
     endif
   endforeach
 
-  cc = find_program(plan['cc'], required : false)
+  cc_list = [plan['cc']]
+  if 'cc_alt' in plan
+    cc_list += plan['cc_alt']
+  endif
+
   cc_cflags = []
-
   check_flags = []
   check_required = false
   cross_cc = get_option('tcg_tests_cross_cc_' + cc_arch)
   if cross_cc != ''
-    # we make sure cross cc exists
-    cc = find_program(cross_cc, required: true)
+    # prepend requested cross_cc
+    cc_list = [cross_cc, cc_list]
     check_required = true
   endif
   cross_cflags = get_option('tcg_tests_cross_cflags_' + cc_arch)
@@ -236,22 +240,26 @@ foreach target, plan: tcg_tests
     check_flags = cc_cflags
     check_required = true
   endif
-
-  cc_from_system = cc.found()
-  has_cc = cc.found()
-  if has_cc
-    if target.endswith('softmmu')
-      check_flags += ['-nostdlib', '-ffreestanding', '-r']
-    else
-      check_flags += ['-static']
-    endif
-
-    cmd = run_command([cc, files('test_cc.c'), check_flags, '-o', '/dev/null'],
-                      check: check_required)
-    has_cc = cmd.returncode() == 0
-    cc_from_system = has_cc
+  if target.endswith('softmmu')
+    check_flags += ['-nostdlib', '-ffreestanding', '-r']
+  else
+    check_flags += ['-static']
   endif
 
+  has_cc = false
+  foreach possible_cc: cc_list
+    cc = find_program(possible_cc, required: check_required)
+    if cc.found()
+      cmd = run_command([cc, files('test_cc.c'), check_flags, '-o', 
'/dev/null'],
+                        check: check_required)
+      if cmd.returncode() == 0
+        has_cc = true
+        break
+      endif
+    endif
+  endforeach
+
+  cc_from_system = has_cc
   build_test_depends = []
   build_test_depend_files = []
 
-- 
2.43.0


Reply via email to