Hi Pierrick,

On 7/7/26 00:32, Pierrick Bouvier wrote:
We allow target to declare a dockerfile containing required cc. We reuse
tests/docker/docker.py, and correctly set dependencies for tests on
original dockerfile.

We specify list of hosts for which image can be built and contains
required cc, using cc_docker_arch.

In case we rely on docker, we do not build tests by default anymore.

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

diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build
index 0d2fefe8f51..57e7c3f8801 100644
--- a/tests/tcg/meson.build
+++ b/tests/tcg/meson.build
@@ -1,6 +1,7 @@
  cc_check_args = ['-xc', '/dev/null', '-o', '/dev/null', '-c']
  env = find_program('env')
+docker_wrapper = find_program('../docker/docker.py')
  gdb_progs = ['gdb-multiarch', 'gdb']
  if config_host.has_key('GDB')
    gdb_progs = [config_host['GDB'], gdb_progs]
@@ -21,6 +22,8 @@ tcg_tests = {}
  # {
  #   'name_of_target': {
  #     'cc': 'cross_compiler',
+#     'cc_dockerfile': 'name_of_dockerfile',
+#     'cc_docker_arch': ['host_arch_supported (meson cpu)', ...],

This variable confuses me while reviewing the other patches in this
series. What about naming explicitly as 'cc_docker_host_arch'?


    cc = find_program(plan['cc'], required : false)
+  cc_from_system = cc.found()
+  has_cc = cc.found()
+  build_test_depends = []
+  build_test_depend_files = []
+
+  if 'cc_dockerfile' in plan
+    cc_dockerfile = plan['cc_dockerfile']
+    cc_docker_arch = plan['cc_docker_arch']
+    allowed = ['aarch64', 'x86_64']
+    foreach arch: cc_docker_arch
+      if arch not in allowed
+        error('incorrect docker arch ' + arch + ' for target ' +
+              target + ' (possible: [' + ', '.join(allowed) + '])')
+      endif
+    endforeach
+    docker_arch_supported = host_machine.cpu_family() in cc_docker_arch
+    dockerfile = files('..'/'docker'/'dockerfiles'/cc_dockerfile + '.docker')
+    image_name = 'image-' + cc_dockerfile
+    has_docker = docker_arch_supported and docker_supported
+    if cc_dockerfile not in image_targets and has_docker
+      cmd = [docker_wrapper, 'build', '-f', dockerfile, '-t', cc_dockerfile]
+      t = custom_target(image_name, command: cmd,
+                        build_by_default: false,
+                        output: 'no_output_' + image_name)
+      image_targets += {cc_dockerfile: t}
+    endif
+
+    if not has_cc and has_docker
+      build_test_depends = image_targets[cc_dockerfile]
+      build_test_depend_files = dockerfile
+      mount = meson.project_source_root()
+      mount = mount + ':' + mount
+      here = meson.project_build_root()
+      cc = [docker_wrapper, 'run', '--run-as-current-user',
+            '-w', here, '-v', mount,
+            cc_dockerfile, plan['cc']]
+      has_cc = true
+    endif
+  endif

Reply via email to