From 8b8e4e5c5c32a955e011f814d74f9b7e2fce3fcc Mon Sep 17 00:00:00 2001 From: Joaquim Monteiro Date: Tue, 15 Oct 2024 08:51:04 +0100 Subject: [PATCH] wayland-protocols: fix tests on older versions of wayland-scanner wayland-protocols 1.38 adds a `deprecated-since` attribute to some protocols. This attribute is only supported in wayland-scanner 1.23. The current version of wayland-scanner on CI is older than 1.23, so the tests fail to build. To fix this, this commit disables wayland-scanner's strict mode for the affected protocols if its version is older than 1.23. --- .../wayland-protocols/tests/meson.build | 158 ++++++++++++++++++ subprojects/wayland-protocols.wrap | 1 + 2 files changed, 159 insertions(+) create mode 100644 subprojects/packagefiles/wayland-protocols/tests/meson.build diff --git a/subprojects/packagefiles/wayland-protocols/tests/meson.build b/subprojects/packagefiles/wayland-protocols/tests/meson.build new file mode 100644 index 000000000..1119b1054 --- /dev/null +++ b/subprojects/packagefiles/wayland-protocols/tests/meson.build @@ -0,0 +1,158 @@ +prog_scan_sh = find_program('scan.sh') + +libwayland = [ + dependency('wayland-client'), + dependency('wayland-server'), +] + +dep_scanner_version_parts = dep_scanner.version().split('.') +dep_scanner_version_major = dep_scanner_version_parts[0].to_int() +dep_scanner_version_minor = dep_scanner_version_parts[1].to_int() + +supports_deprecated_since = true +if dep_scanner_version_major == 1 and dep_scanner_version_minor < 23 + supports_deprecated_since = false +endif + +# Check that each protocol passes through the scanner +foreach protocol_file : protocol_files + if not supports_deprecated_since and fs.name(protocol_file).split('.')[0] in ['linux-dmabuf-v1', 'xdg-output-unstable-v1']: + continue + endif + + protocol_path = join_paths(wayland_protocols_srcdir, protocol_file) + test_name = 'scan-@0@'.format(protocol_file.underscorify()) + test(test_name, prog_scan_sh, + args: protocol_path, + env: [ + 'SCANNER=@0@'.format(prog_scanner.full_path()), + ] + ) +endforeach + +# Check buildability + +add_languages('c', 'cpp', native: false) +replace = find_program('replace.py') + +extra_linker_flags = meson.get_compiler('c').get_supported_link_arguments([ + '-Wl,--unresolved-symbols=ignore-all', +]) + +foreach protocol_file : protocol_files + xml_file = fs.name(protocol_file) + xml_components = xml_file.split('.') + protocol_base_file_name = xml_components[0] + + strict = true + if not supports_deprecated_since and protocol_base_file_name in ['linux-dmabuf-v1', 'xdg-output-unstable-v1'] + strict = false + endif + + protocol_path = files(join_paths(wayland_protocols_srcdir, protocol_file)) + client_header_path = '@0@-client.h'.format(protocol_base_file_name) + server_header_path = '@0@-server.h'.format(protocol_base_file_name) + code_path = '@0@-code.c'.format(protocol_base_file_name) + client_header = custom_target( + client_header_path, + output: client_header_path, + input: protocol_path, + command: [ + prog_scanner, + 'client-header', + '@INPUT@', + '@OUTPUT@', + ] + (strict ? ['--strict'] : []), + install: false, + ) + server_header = custom_target( + server_header_path, + output: server_header_path, + input: protocol_path, + command: [ + prog_scanner, + 'server-header', + '@INPUT@', + '@OUTPUT@', + ] + (strict ? ['--strict'] : []), + install: false, + ) + code = custom_target( + code_path, + output: code_path, + input: protocol_path, + command: [ + prog_scanner, + 'private-code', + '@INPUT@', + '@OUTPUT@', + ] + (strict ? ['--strict'] : []), + install: false, + ) + + replace_command = [ + replace, + '@INPUT@', + '@OUTPUT@', + 'PROTOCOL_CLIENT_INCLUDE_FILE', + client_header.full_path(), + 'PROTOCOL_SERVER_INCLUDE_FILE', + server_header.full_path(), + ] + + # Check that header can be included by a pedantic C99 compiler + test_name = 'test-build-pedantic-@0@'.format(protocol_file.underscorify()) + test_name_source = '@0@.c'.format(test_name) + test_source = custom_target( + test_name_source, + input: 'build-pedantic.c.in', + output: test_name_source, + command: replace_command, + ) + pedantic_test_executable = executable( + test_name, + [ + test_source, + client_header, + server_header, + code + ], + link_args: extra_linker_flags, + dependencies: libwayland, + c_args: [ + '-std=c99', + '-pedantic', + '-Wall', + '-Werror' ], + install: false, + ) + test(test_name, pedantic_test_executable) + + # Check that the header + if not protocol_file.contains('xdg-foreign-unstable-v1') + test_name = 'test-build-cxx-@0@'.format(protocol_file.underscorify()) + test_name_source = '@0@.cc'.format(test_name) + test_source = custom_target( + test_name_source, + input: 'build-cxx.cc.in', + output: test_name_source, + command: replace_command, + ) + cxx_test_executable = executable( + test_name, + [ + test_source, + client_header, + server_header, + ], + link_args: extra_linker_flags, + dependencies: libwayland, + cpp_args: [ + '-Wall', + '-Werror', + ], + install: false, + ) + test(test_name, cxx_test_executable) + endif +endforeach diff --git a/subprojects/wayland-protocols.wrap b/subprojects/wayland-protocols.wrap index 61f306bdf..1baa782ae 100644 --- a/subprojects/wayland-protocols.wrap +++ b/subprojects/wayland-protocols.wrap @@ -3,6 +3,7 @@ directory = wayland-protocols-1.38 source_url = https://gitlab.freedesktop.org/wayland/wayland-protocols/-/releases/1.38/downloads/wayland-protocols-1.38.tar.xz source_filename = wayland-protocols-1.38.tar.xz source_hash = ff17292c05159d2b20ce6cacfe42d7e31a28198fa1429a769b03af7c38581dbe +patch_directory = wayland-protocols [provide] wayland-protocols = wayland_protocols