wayland module: Allow building both client and server sides

- Change `scope` kwarg to `public` boolean default to false.
- Change `side`  kwarg to `client` and `server` booleans.
- Document returned values
- Aggregate in a single unit test because have lots of small tests
  increases CI time.

Fixes: #10040.
pull/10076/head
Xavier Claessens 3 years ago committed by Xavier Claessens
parent af9af219d8
commit e80a9c2cba
  1. 32
      docs/markdown/Wayland-module.md
  2. 12
      mesonbuild/modules/unstable_wayland.py
  3. 11
      test cases/wayland/1 client/both.c
  4. 0
      test cases/wayland/1 client/client.c
  5. 0
      test cases/wayland/1 client/local.c
  6. 38
      test cases/wayland/1 client/meson.build
  7. 9
      test cases/wayland/1 client/server.c
  8. 0
      test cases/wayland/1 client/test.xml
  9. 9
      test cases/wayland/2 server/main.c
  10. 16
      test cases/wayland/2 server/meson.build
  11. 11
      test cases/wayland/3 local/meson.build

@ -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
`<name>-<client|server>-protocol.h`.
## Links
- [Official Wayland Documentation](https://wayland.freedesktop.org/docs/html/)

@ -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,6 +68,7 @@ class WaylandModule(ExtensionModule):
)
targets.append(code)
for side in sides:
header = CustomTarget(
f'{name}-{side}-protocol',
state.subdir,

@ -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
}

@ -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)

@ -0,0 +1,9 @@
#include "presentation-time-server-protocol.h"
int main() {
#ifdef PRESENTATION_TIME_SERVER_PROTOCOL_H
return 0;
#else
return 1;
#endif
}

@ -1,9 +0,0 @@
#include "xdg-shell-server-protocol.h"
int main() {
#ifdef XDG_SHELL_SERVER_PROTOCOL_H
return 0;
#else
return 1;
#endif
}

@ -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)

@ -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)
Loading…
Cancel
Save