On 6/26/2026 4:39 PM, 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. > > In case we rely on docker, we do not build tests by default anymore. >
Added (coming in v3) cc_docker_arch to specify host architecture for which the image supports the given cc. > Signed-off-by: Pierrick Bouvier <[email protected]> > --- > tests/tcg/meson.build | 52 ++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 47 insertions(+), 5 deletions(-) > > diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build > index 2a308d8ad32..eb6b65c0021 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,7 @@ tcg_tests = {} > # { > # 'name_of_target': { > # 'cc': 'cross_compiler', > +# 'cc_dockerfile': 'name_of_dockerfile', > # 'cc_feat_cflags': { > # 'name': ['feature cflags'], > # ... > @@ -75,6 +77,9 @@ if gdb.found() > endforeach > endif > > +docker_supported = run_command(docker_wrapper, 'probe', > + check: false).returncode() == 0 > + > # plugins come first, as we need to build the list > test_plugins = {} > subdir('plugins') > @@ -120,6 +125,7 @@ endforeach > # Now let's go through all architectures > subdir('aarch64') > > +image_targets = {} > # Finally, we can create all test executables and test targets > foreach target, plan: tcg_tests > if target.startswith('multiarch-') > @@ -135,8 +141,8 @@ foreach target, plan: tcg_tests > > # return a clear error if user misspell a target entry > foreach key, _ : plan > - allowed = ['cc', 'cc_feat_cflags', 'folder', 'gdb_arch', > 'gdb_feat_version', > - 'qemu', 'tests'] > + allowed = ['cc', '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 + > ' (possible: [' + ', '.join(allowed) + '])') > @@ -144,6 +150,35 @@ foreach target, plan: tcg_tests > endforeach > > 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'] > + dockerfile = files('..'/'docker'/'dockerfiles'/cc_dockerfile + '.docker') > + image_name = 'image-' + cc_dockerfile > + if cc_dockerfile not in image_targets > + cmd = [docker_wrapper, 'build', '-f', dockerfile, '-t', cc_dockerfile] > + t = custom_target(image_name, command: cmd, > + build_by_default: false, > + output: 'none') > + image_targets += {cc_dockerfile: t} > + endif > + > + if docker_supported and not has_cc > + 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', '-w', here, '-v', mount, > + cc_dockerfile, plan['cc']] > + has_cc = true > + endif > + endif > + > folder = plan['folder'] > gdb_arch = plan['gdb_arch'] > qemu = plan['qemu'] > @@ -237,10 +272,14 @@ foreach target, plan: tcg_tests > cc_feat = setup['cc_feat'] > if cc_feat not in cc_has_feat > avail = false > - if cc.found() > + if cc_from_system > + # check flag for host cc > cmd = run_command([cc, cc_check_args, cc_feat_cflags[cc_feat]], > check: false) > avail = cmd.returncode() == 0 > + elif has_cc > + # docker cc always have feature > + avail = true > endif > cc_has_feat += {cc_feat: avail} > endif > @@ -252,12 +291,13 @@ foreach target, plan: tcg_tests > cflags += cc_feat_cflags[cc_feat] > endif > > - if not cc.found() > + if not has_cc > skip_test = 'compiler ' + plan['cc'] + ' not available' > built_tests += {exe_name: exe_name} > endif > > # build executable if needed > + # build by default only if cc comes from system > if exe_name not in built_tests > exe = custom_target(exe_name, > input: file, > @@ -269,7 +309,9 @@ foreach target, plan: tcg_tests > cflags], > depfile: exe_name + '.d', > output: exe_name + '.test', > - build_by_default: true) > + depends: build_test_depends, > + depend_files: build_test_depend_files, > + build_by_default: cc_from_system) > built_tests += {exe_name: exe} > endif >
