Commit graph

50 commits

Author SHA1 Message Date
Jason Gerecke
6c5b486306 scanner: Avoid trailing full stops in regex search for protocol names
Continue to find nested ei_foo.bar.baz but avoid including a trailing
full stop, if it exists.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/336>
2025-05-29 14:35:19 -07:00
Peter Hutterer
962863cbc4 scanner: ensure 'since' doesn't exceed the interface version
See https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/327

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/328>
2025-03-31 10:00:19 +10:00
Peter Hutterer
b0deafc641 scanner: convert the 'version' and 'since' arguments to int
Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/328>
2025-03-31 10:00:05 +10:00
Peter Hutterer
dbc06510a1 scanner: switch to using dataclasses
This drops one dependency that we're not fully using anyway. Except for
the per-attribute validators that can be done in __post_init() we're not
using attrs for anything that dataclasses cannot do.
2024-09-12 00:39:09 +00:00
Peter Hutterer
87705ef97c scanner: handle the allow-null attribute for arguments
Currently unused but it's exposed, so yay...
2024-07-25 11:11:07 +10:00
Peter Hutterer
552f6dcbd0 ei-scanner: expose version_arg and version_arg_for
Points to the correspoding "version" argument, or points back to the
argument this version argument is for.
2023-05-26 16:56:13 +10:00
Ian Douglas Scott
1d8cd84c56 ei-scanner: Expose interface_arg, and also provide interface_arg_for
To make this practical to use in a template, we want relations in both
directions. And at least for consistency with other things, these fields
should contain the `Argument` instead of just its name string.

So we need to do this after are the arguments in the message have been
initially parsed. Adding these fields when parsing the request/event
close tag seems to work well enough.

Co-authored-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-26 16:55:47 +10:00
Peter Hutterer
3a9eb2d8b6 scanner: rework the main() function into something easier to test
Rename to scanner() and take an argument vector that can be passed to
ArgumentParser.parse_args(). This makes testing the scanner's CLI a lot
easier.
2023-05-25 09:51:42 +10:00
Ian Douglas Scott
091948e9ef ei-scanner: Fix --jinja-extra-data-file, and make mypy check pass 2023-05-24 11:33:12 -07:00
Peter Hutterer
f142f802f4 scanner: add the Interface.plainname property
Returns "connection" for the "ei_connection" interface, i.e. the
interface stripped of any component prefix.
2023-05-22 00:24:39 +00:00
Peter Hutterer
f15736e809 scanner: add a validator for Interface.mode
Not really needed since we currently have an assert in create but this
makes the code more obvious.
2023-04-06 14:01:07 +10:00
Peter Hutterer
3546a443a9 scanner: auto-mangle the interface name when accessed
Now that we only have one place where we need to mangle the name, let's
make this a property of the Interface instead.
2023-04-06 14:00:44 +10:00
Peter Hutterer
cfd2980ae4 scanner: look up interfaces by protocol name
Now that we have it, let's use it instead having to mangle names.
2023-04-06 13:57:20 +10:00
Peter Hutterer
5aad9fd777 scanner: add the protocol name so we can compile some #defines
The protocol name on an interface is a fixed string that is part of
the ABI since it's used in a few messages (e.g.
ei_handshake.interface_version). To avoid typos, let's expose that
string in the scanner and #define it in the generated sources.
2023-04-06 13:57:20 +10:00
Peter Hutterer
fa07430683 scanner: use mangle_name for the interface name 2023-04-06 13:57:20 +10:00
Salman Malik
8b7fb73bfd ei-scanner: Adjust annotation for list
Otherwise Python complains about:

TypeError: 'type' object is not subscriptable
2023-03-25 23:00:41 +00:00
Peter Hutterer
bba921329d proto: skip the bitmask check if on old python versions
int.bit_count() requires Python 3.10, so let's skip it where not
available.
2023-03-19 07:56:09 +00:00
Peter Hutterer
5258a559eb doc/proto: remove the embedded docs from the proto, use static pages instead 2023-03-08 11:09:58 +10:00
Peter Hutterer
56004836b9 proto: add the context-type attribute to events and requests
This allows us to mark/filter requests and events that are only
available on a given context type.
2023-03-08 09:01:03 +10:00
Peter Hutterer
b05b256fd8 scanner: expand the regex to search for protocol names
This now finds nested ei_foo.bar.baz too (though it includes the
trailing full stop, if any).
2023-03-07 15:26:36 +10:00
Peter Hutterer
eb9fa07c10 scanner: add a filter to escape ei protocol names
By default escape them with backticks for markdown
2023-03-03 11:39:03 +10:00
Peter Hutterer
2fb1ff70e3 scanner: allow '-' for loading a template from stdin 2023-03-03 11:39:03 +10:00
Peter Hutterer
ea3ada1a80 proto: make the documentation an extractable set of XML tags
Instead of hiding this in a XML comment, let's make it a proper set of
tags so we can extract it and use it in generated documentation.
2023-03-03 11:38:40 +10:00
Peter Hutterer
c350ac2ee3 src: pass the headerfile as jinja extra data
This removes another special handling of the C bindings from the
scanner.
2023-03-03 11:38:40 +10:00
Peter Hutterer
d127f02f0a scanner: add ability to pass extra data to the jinja templates
This makes generation of files with the scanner a lot more flexible -
e.g. one can run the scanner with
  --jinja-extra-data='{ "interface": "ei_connection"}'
and then in the jinja template use an if condition to match on this
interface.
2023-03-03 11:38:40 +10:00
Peter Hutterer
2fa7792a33 scanner: drop duplicate import
We already import dedent globally
2023-03-03 11:27:01 +10:00
Peter Hutterer
2550a0b54d scanner: raise SystemExit instead of calling sys.exit
Bit nicer (no import sys required for that call) and that's what sys.exit
does that anyway.
2023-03-03 11:27:01 +10:00
Peter Hutterer
1db37c33d5 scanner: allow for cross-referencing enums
Add another run to the XML parser so we parse enums before Arguments
that cross-reference enums from other interfaces.

This also fixes a type bug - the enum name string was passed to
Argument.create() as Enum and no-one noticed.
2023-03-03 11:27:01 +10:00
Jonas Ådahl
03c0ab73dd protocol: Add support for 64 bit integers on the wire
This is useful for e.g. not having to split timestamps.
2023-03-03 11:27:01 +10:00
Jonas Ådahl
cad5bc81bb protocol: Make integer explicitly sized
This means 'int' is explicitly 'int32' and 'uint' is explicitly
'uint32' in the protocol XML files.
2023-03-03 11:27:01 +10:00
Peter Hutterer
b7ac763241 protocol: change type=bitmask to use the wayland protocol's bitfield=true 2023-03-03 11:27:01 +10:00
Peter Hutterer
2227690287 scanner: parse the copyright tag 2023-03-03 11:27:01 +10:00
Peter Hutterer
8692e2592a scanner: use the proper SAXException class
The one we get is an internal subclass, let's not do that.
2023-03-03 11:27:01 +10:00
Peter Hutterer
7ad74b9886 scanner: fix mypy errors 2023-03-03 11:27:01 +10:00
Peter Hutterer
e592a3d85a scanner: fix a few black complaints 2023-03-03 11:27:01 +10:00
Peter Hutterer
c8986b88ba scanner: parse the descriptions as well 2023-03-03 11:27:01 +10:00
Peter Hutterer
cc0a06aed6 scanner: rename to as_c_arg and c_type for the c-specific functions 2023-03-03 11:27:01 +10:00
Peter Hutterer
4293f2f040 scanner: factor out the protocol type mapping to be global 2023-03-03 11:27:01 +10:00
Peter Hutterer
5e6e4d8fc9 scanner: separate the parser from the actual protocol
Let's not leak anything related to XML parsing into the class
we use as the actual protocol description.
2023-03-03 11:27:01 +10:00
Peter Hutterer
4414c91fca scanner: rename run to run_counter 2023-03-03 11:27:01 +10:00
Peter Hutterer
3499d26300 scanner: slightly clean up the XML error handling
Slight improvement in the code, nothing more.
2023-03-03 11:27:01 +10:00
Peter Hutterer
381bc9222a scanner: don't allow incoming/outgoing for modes other than ei/eis
We support mode "brei" now but that doesn't have a definition of incoming or
outgoing.
2023-03-03 11:27:01 +10:00
Peter Hutterer
0e70d06706 scanner: comments and some more type annotations 2023-03-03 11:27:01 +10:00
Peter Hutterer
72c570e096 scanner: pass the Enum to the Entry class
So we can compose the fqdn (and possibly do value checks and whatnot)
2023-03-03 11:27:01 +10:00
Peter Hutterer
579f0d07d2 Add a brei-proto.h generated header file
This will be needed to have access to the various disconnect reasons in
brei-shared.c.
2023-03-03 11:21:26 +10:00
Peter Hutterer
8a52cbbe10 scanner: detect duplicates in the XML file 2023-03-03 11:21:26 +10:00
Peter Hutterer
e07d4638d5 scanner: drop the Argument.argtype in favour of DBus-type bindings
This was a brei-specifc implementation detail that is not really needed,
we can use the single-character dbus-style bindings.
2023-03-03 11:21:26 +10:00
Peter Hutterer
f500a1cd43 scanner: expand the help description 2023-03-03 11:21:26 +10:00
Peter Hutterer
1e4d273cd4 scanner: add the "camel" jinja filter
For conversion into CamelCase
2023-03-03 11:21:26 +10:00
Peter Hutterer
8979802893 scanner: rename to ei-scanner 2023-03-03 11:21:26 +10:00
Renamed from proto/scanner.py (Browse further)