diff --git a/docs/markdown/Wayland-module.md b/docs/markdown/Wayland-module.md index d30627c2b..345c4e347 100644 --- a/docs/markdown/Wayland-module.md +++ b/docs/markdown/Wayland-module.md @@ -26,7 +26,6 @@ executable('hw', 'main.c', xdg_shell, dependencies : wl_dep) ## Methods ### find_protocol - ```meson xml = wl_mod.find_protocol( 'xdg-decoration', @@ -35,28 +34,37 @@ xml = wl_mod.find_protocol( ) ``` This function requires one positional argument: the protocol base name. + +It takes the following keyword arguments: - `state` Optional arg that specifies the current state of the protocol. -Either stable, staging, or unstable. -The default is stable. -- `version` The backwards incompatible version number. -Required for staging or unstable. An error is raised for stable. + Either `'stable'`, `'staging'`, or `'unstable'`. The default is `'stable'`. +- `version` The backwards incompatible version number as integer. + Required for staging and unstable, but not allowed for stable. + +**Returns**: a [[@file]] that can be passed to [scan_xml](#scan_xml) ### scan_xml ```meson generated = wl_mod.scan_xml( 'my-protocol.xml', - side : 'client', - scope : 'private', + client : true, + server : true, + public : false, ) ``` This function accepts one or more arguments of either string or file type. -- `side` Optional arg that specifies if client or server side code is generated. -The default is client side. -- `scope` Optional arg that specifies the scope of the generated code. -Either public or private. -The default is private. +It takes the following keyword arguments: +- `public` Optional arg that specifies the scope of the generated code. + The default is false. +- `client` Optional arg that specifies if client side header file is + generated. The default is true. +- `server` Optional arg that specifies if server side header file is + generated. The default is false. +**Returns**: a list of [[@custom_tgt]] in the order source, client side header, +server side header. Generated header files have the name +`--protocol.h`. ## Links - [Official Wayland Documentation](https://wayland.freedesktop.org/docs/html/) diff --git a/mesonbuild/modules/unstable_wayland.py b/mesonbuild/modules/unstable_wayland.py index 85da2b790..a7653d917 100644 --- a/mesonbuild/modules/unstable_wayland.py +++ b/mesonbuild/modules/unstable_wayland.py @@ -39,15 +39,18 @@ class WaylandModule(ExtensionModule): @typed_pos_args('wayland.scan_xml', varargs=(str, File), min_varargs=1) @typed_kwargs( 'wayland.scan_xml', - KwargInfo('side', str, default='client', validator=in_set_validator({'client', 'server'})), - KwargInfo('scope', str, default='private', validator=in_set_validator({'private', 'public'})), + KwargInfo('public', bool, default=False), + KwargInfo('client', bool, default=True), + KwargInfo('server', bool, default=False), ) def scan_xml(self, state, args, kwargs): if self.scanner_bin is None: self.scanner_bin = state.find_program('wayland-scanner', for_machine=MachineChoice.BUILD) - scope = kwargs['scope'] - side = kwargs['side'] + scope = 'public' if kwargs['public'] else 'private' + sides = [i for i in ['client', 'server'] if kwargs[i]] + if not sides: + raise MesonException('At least one of client or server keyword argument must be set to true.') xml_files = self.interpreter.source_strings_to_files(args[0]) targets = [] @@ -65,16 +68,17 @@ class WaylandModule(ExtensionModule): ) targets.append(code) - header = CustomTarget( - f'{name}-{side}-protocol', - state.subdir, - state.subproject, - [self.scanner_bin, f'{side}-header', '@INPUT@', '@OUTPUT@'], - [xml_file], - [f'{name}-{side}-protocol.h'], - backend=state.backend, - ) - targets.append(header) + for side in sides: + header = CustomTarget( + f'{name}-{side}-protocol', + state.subdir, + state.subproject, + [self.scanner_bin, f'{side}-header', '@INPUT@', '@OUTPUT@'], + [xml_file], + [f'{name}-{side}-protocol.h'], + backend=state.backend, + ) + targets.append(header) return ModuleReturnValue(targets, targets) diff --git a/test cases/wayland/1 client/both.c b/test cases/wayland/1 client/both.c new file mode 100644 index 000000000..b6e1bab17 --- /dev/null +++ b/test cases/wayland/1 client/both.c @@ -0,0 +1,11 @@ +#include "viewporter-client-protocol.h" +#include "viewporter-server-protocol.h" + +int main() { +#if defined(VIEWPORTER_CLIENT_PROTOCOL_H) && \ + defined(VIEWPORTER_SERVER_PROTOCOL_H) + return 0; +#else + return 1; +#endif +} diff --git a/test cases/wayland/1 client/main.c b/test cases/wayland/1 client/client.c similarity index 78% rename from test cases/wayland/1 client/main.c rename to test cases/wayland/1 client/client.c index 6aca80d98..4966721ff 100644 --- a/test cases/wayland/1 client/main.c +++ b/test cases/wayland/1 client/client.c @@ -2,8 +2,8 @@ int main() { #ifdef XDG_SHELL_CLIENT_PROTOCOL_H - return 0; + return 0; #else - return 1; + return 1; #endif } diff --git a/test cases/wayland/3 local/main.c b/test cases/wayland/1 client/local.c similarity index 100% rename from test cases/wayland/3 local/main.c rename to test cases/wayland/1 client/local.c diff --git a/test cases/wayland/1 client/meson.build b/test cases/wayland/1 client/meson.build index 7ca868b87..cb13db287 100644 --- a/test cases/wayland/1 client/meson.build +++ b/test cases/wayland/1 client/meson.build @@ -5,12 +5,44 @@ if not wl_protocols_dep.found() error('MESON_SKIP_TEST: wayland-protocols not installed') endif -wl_dep = dependency('wayland-client') +wl_client_dep = dependency('wayland-client') +wl_server_dep = dependency('wayland-server') wl_mod = import('unstable-wayland') +fs = import('fs') +# Client side only xdg_shell_xml = wl_mod.find_protocol('xdg-shell') xdg_shell = wl_mod.scan_xml(xdg_shell_xml) +assert(xdg_shell.length() == 2) +assert(fs.name(xdg_shell[0].full_path()) == 'xdg-shell-protocol.c') +assert(fs.name(xdg_shell[1].full_path()) == 'xdg-shell-client-protocol.h') +exe = executable('client', 'client.c', xdg_shell, dependencies : wl_client_dep) +test('client', exe) -exe = executable('client', 'main.c', xdg_shell, dependencies : wl_dep) +# Server side only +presentation_time_xml = wl_mod.find_protocol('presentation-time') +presentation_time = wl_mod.scan_xml(presentation_time_xml, client : false, server : true) +assert(presentation_time.length() == 2) +assert(fs.name(presentation_time[0].full_path()) == 'presentation-time-protocol.c') +assert(fs.name(presentation_time[1].full_path()) == 'presentation-time-server-protocol.h') +exe = executable('server', 'server.c', presentation_time, dependencies : wl_server_dep) +test('server', exe) -test('client', exe) +# Both sides +viewporter_xml = wl_mod.find_protocol('viewporter') +viewporter = wl_mod.scan_xml(viewporter_xml, client : true, server : true) +assert(viewporter.length() == 3) +assert(fs.name(viewporter[0].full_path()) == 'viewporter-protocol.c') +assert(fs.name(viewporter[1].full_path()) == 'viewporter-client-protocol.h') +assert(fs.name(viewporter[2].full_path()) == 'viewporter-server-protocol.h') +exe = executable('both', 'both.c', viewporter, dependencies : [wl_client_dep, wl_server_dep]) +test('both', exe) + +# Local xml +xmls = files('test.xml') +gen = wl_mod.scan_xml(xmls) +assert(gen.length() == 2) +assert(fs.name(gen[0].full_path()) == 'test-protocol.c') +assert(fs.name(gen[1].full_path()) == 'test-client-protocol.h') +exe = executable('local', 'local.c', gen, dependencies : wl_client_dep) +test('local', exe) diff --git a/test cases/wayland/1 client/server.c b/test cases/wayland/1 client/server.c new file mode 100644 index 000000000..e073a7be9 --- /dev/null +++ b/test cases/wayland/1 client/server.c @@ -0,0 +1,9 @@ +#include "presentation-time-server-protocol.h" + +int main() { +#ifdef PRESENTATION_TIME_SERVER_PROTOCOL_H + return 0; +#else + return 1; +#endif +} diff --git a/test cases/wayland/3 local/test.xml b/test cases/wayland/1 client/test.xml similarity index 100% rename from test cases/wayland/3 local/test.xml rename to test cases/wayland/1 client/test.xml diff --git a/test cases/wayland/2 server/main.c b/test cases/wayland/2 server/main.c deleted file mode 100644 index 3307499fa..000000000 --- a/test cases/wayland/2 server/main.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "xdg-shell-server-protocol.h" - -int main() { -#ifdef XDG_SHELL_SERVER_PROTOCOL_H - return 0; -#else - return 1; -#endif -} diff --git a/test cases/wayland/2 server/meson.build b/test cases/wayland/2 server/meson.build deleted file mode 100644 index c93ff119c..000000000 --- a/test cases/wayland/2 server/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -project('wayland-test-server', 'c') - -wl_protocols_dep = dependency('wayland-protocols', required : false) -if not wl_protocols_dep.found() - error('MESON_SKIP_TEST: wayland-protocols not installed') -endif - -wl_dep = dependency('wayland-server') -wl_mod = import('unstable-wayland') - -xdg_shell_xml = wl_mod.find_protocol('xdg-shell') -xdg_shell = wl_mod.scan_xml(xdg_shell_xml, side : 'server') - -exe = executable('server', 'main.c', xdg_shell, dependencies : wl_dep) - -test('client', exe) diff --git a/test cases/wayland/3 local/meson.build b/test cases/wayland/3 local/meson.build deleted file mode 100644 index 7a470d603..000000000 --- a/test cases/wayland/3 local/meson.build +++ /dev/null @@ -1,11 +0,0 @@ -project('wayland-test-local', 'c') - -wl_dep = dependency('wayland-client') -wl_mod = import('unstable-wayland') - -xmls = files('test.xml') -gen = wl_mod.scan_xml(xmls) - -exe = executable('local', 'main.c', gen, dependencies : wl_dep) - -test('local', exe)