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_host_arch. 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 9c00d21f059..9db0692685f 100644 --- a/tests/tcg/meson.build +++ b/tests/tcg/meson.build @@ -1,5 +1,6 @@ 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] @@ -20,6 +21,8 @@ tcg_tests = {} # { # 'name_of_target': { # 'cc': 'cross_compiler', +# 'cc_dockerfile': 'name_of_dockerfile', +# 'cc_docker_host_arch': ['host_arch_supported (meson cpu)', ...], # 'cc_feat_cflags': { # 'name': ['feature cflags'], # ... @@ -74,10 +77,14 @@ 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') +image_targets = {} # Finally, we can create all test executables and test targets foreach target, plan: tcg_tests # Detect duplicated executables/tests, and report an error to force user to @@ -88,8 +95,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_docker_host_arch', '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) + '])') @@ -97,6 +104,46 @@ 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'] + cc_docker_host_arch = plan['cc_docker_host_arch'] + allowed = ['aarch64', 'x86_64'] + foreach arch: cc_docker_host_arch + if arch not in allowed + error('incorrect docker arch ' + arch + ' for target ' + + target + ' (possible: [' + ', '.join(allowed) + '])') + endif + endforeach + docker_host_arch_supported = host_machine.cpu_family() in cc_docker_host_arch + dockerfile = files('..'/'docker'/'dockerfiles'/cc_dockerfile + '.docker') + image_name = 'image-' + cc_dockerfile + has_docker = docker_host_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 + folder = plan['folder'] gdb_arch = plan['gdb_arch'] qemu = plan['qemu'] @@ -190,11 +237,15 @@ 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, '-xc', '/dev/null', '-o', '/dev/null', '-c', 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 @@ -206,7 +257,7 @@ 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 @@ -223,6 +274,8 @@ foreach target, plan: tcg_tests cflags], depfile: exe_name + '.d', output: exe_name + '.test', + depends: build_test_depends, + depend_files: build_test_depend_files, build_by_default: false) built_tests += {exe_name: exe} endif -- 2.47.3
