Commit Graph

34 Commits

Author SHA1 Message Date
Philip Withnall
1757365af3 Merge branch 'dbus-codegen-tests' into 'main'
Don't skip dbus-codegen tests on Win32

Evolved from https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3857

See merge request GNOME/glib!3874
2024-02-05 10:18:28 +00:00
Jordan Petridis
9c65e9ba2d gio: tests: Use slightly more explicit assert functions
Found by using teyit [1] on the code

https://github.com/isidentical/teyit
2024-02-02 16:15:35 +02:00
Philip Withnall
5744f55c11 Revert "Don't skip dbus-codegen tests on Win32"
This reverts commit fbdc9a2d03.

It was not submitted through a merge request and broke CI. Reverting it
immediately to unbreak CI and hence the rest of the development
pipeline. The changes can be re-submitted as a merge request so they’re
properly tested in CI before being merged.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3857#note_1994336
2024-02-02 10:01:24 +00:00
John Ralls
fbdc9a2d03 Don't skip dbus-codegen tests on Win32
And coincidentally on Darwin either.
2024-02-01 15:17:26 -08:00
John Ralls
3ef742ebee Don't skip dbus-codegen tests on Win32
And coincidentally on Darwin either.
2024-01-28 20:07:44 -08:00
Philip Withnall
91c82b046e tests: Re-format codegen.py with black
This is just the result of running `black $(git ls-files '*.py')`.

For some reason, the `sh-and-py-check` CI job didn’t run on merge
request !3751, so this non-standard formatting slipped through onto
`main`.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3754#note_1939914

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-12-11 16:53:44 +00:00
Philip Withnall
b96778ee43 tests: Use textwrap.dedent to indent expected strings pleasingly
This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2023-12-11 16:52:07 +00:00
tytan652
605be9a1e9 tests: Add tests for gdbus-codegen generated RST
Those tests check if methods, signals and properties documentation are
properly generated.
2023-12-11 13:48:43 +01:00
Philip Withnall
077104e63b tests: Run processes under test with G_DEBUG=fatal-warnings
Modify all the similar Python test wrappers to set
`G_DEBUG=fatal-warnings` in the environment of the program being tested,
so we can catch unexpected warnings/criticals.

Adding this because I noticed it was missing, not because I noticed a
warning/critical was being ignored.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
2023-11-07 13:51:56 +00:00
André
9a6ca0ef75
gdbus-codegen: preserve relative indentation in doc comments
This commit also changes the generators for rst, xml and dockbook
to preserve indentation.

Closes #3032
2023-08-14 23:46:09 -03:00
Corey Berla
a1a00a3071 gdbus-codegen: Error on invalid dbus types
Introduce slightly modified (dbus specific) versions of
variant_is_signature and variant_type_string_scan in order to fail
early on bad type strings.
2023-07-12 15:33:22 -07:00
Marco Trevisan (Treviño)
27b7559c91 gdbus-codegen: Define only one marshaller per signature reusing across interfaces
Avoid generating more code than needed, so other than continuing using
the generic glib marshallers when possible, define once the custom ones
we need for each file we generate.

The marshallers are then re-used across all the interfaces defined
without duplicating the code size.
2023-06-30 23:40:03 +02:00
Marco Trevisan (Treviño)
23180d433e gdbus-codegen: Try to reuse default glib marshallers for simpler signals marshallers
If a signal signautre is simple enough we can just reuse the default
marshallers by simply creating a wrapper marshaller
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
c5d9004236 gdbus-codegen: Use direct-access GValue macros for marshallers and GValues
This is the same we're doing in code generated by glib-genmarshaller and
what gmarshal does internally.

Since the generated gdbus C code can be considered private too, this is
safe to do, and will allow faster access to GValue objects.
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
8943ceae6c gdbus-codegen: Generate marshallers for method handlers signals
Get rid completely of the usage of the generic marshaller in gdbus
generated code, using instead specific marshallers.

Code is not yet optimized fully since we may still have duplicated
functions to be generated.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3028
2023-06-30 22:59:37 +02:00
Marco Trevisan (Treviño)
1cd5c5678a gdbus-codegen: Generate signal marshallers for each interface signal
We relied on g_cclosure_marshal_generic() to easily generate signal
marshallers, but this relies on inspecting each parameter type with ffi
and this implies a performance hit, other than breaking the stack-frame
unwinder used by Linux perf and so by sysprof.

Given that we know the types we work on, it's easy enough to generate
the marshallers ourself.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/3028
2023-06-30 22:17:46 +02:00
Marco Trevisan (Treviño)
51c023f189 tests/codegen: Add checks for signal emission enums
These are checked to be correct by code compilation, but let's ensure we
also have some kind of forma check on the expected syntax.
2023-06-30 22:17:46 +02:00
Guido Günther
4cb945d780 codegen: Support markdown suitable for gi-docgen 2022-12-29 12:42:12 +00:00
Ray Strode
4a00ac91c6 tests: Shorten internal codegen test timeout
the gio dbus codegen test has 10 test cases in it.
Each test case is given 100 seconds to complete.

That is far longer than they should need.

Furthermore, the entire test is only given 60s
to complete.

This commit makes the internal timeout more consistent
with the external timeout, by giving each of the 10
test cases 6 seconds instead of 100s.
2022-11-08 13:08:53 -05:00
Philip Withnall
26409f19cd Add SPDX license headers for LGPL-2.1-or-later to various files
These have all been added manually, as I’ve finished all the files which
I can automatically detect.

All the license headers in this commit are for LGPL-2.1-or-later, and
all have been double-checked against the license paragraph in the file
header.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-06-01 12:44:23 +01:00
TestingPlant
a5e7156a9b Replace single quotes in gio/tests/codegen.py
This makes the formatting more consistent.
2022-05-12 00:29:44 +00:00
Marc-André Lureau
e38e92e37b gio/tests/codegen: skip tests that require /dev/stdout on win32
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-03-18 00:20:14 +04:00
Emmanuele Bassi
47ce6432f3 codegen: Verify that we're generating valid XML
We should output valid XML even when getting an iffy annotation.
2022-02-15 12:14:49 +00:00
Emmanuele Bassi
ba2725f263 tests: Check "gdbus-codegen --generate-docbook"
Verify that the command line argument works, by checking it's not writing
to stdout/stderr, and that the generated file isn't empty.
2022-01-22 01:30:16 +00:00
Emmanuele Bassi
4db9d43f1a tests: Check "gdbus-codegen --generate-rst"
Verify that the command line argument works, by checking it's not writing
to stdout/stderr, and that the generate file isn't empty.
2022-01-22 01:30:16 +00:00
Alexander Kanavin
e161c62292 gio/tests/codegen.py: bump timeout to 100 seconds
This may be necessary on overloaded CI systems.
2021-11-18 14:07:11 +01:00
Philip Withnall
d270b6c3db py: Various flake8 cleanups
None of these are particularly significant, but they do get the CI
output clean.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Philip Withnall
905b22a17e py: Reformat all Python files consistently
This commit is the unmodified results of running
```
black $(git ls-files '*.py')
```
with black version 19.10b0. See #2046.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-11-17 15:50:07 +00:00
Philip Withnall
9734e4854e gdbus-codegen: Add --glib-max-allowed argument
This complements the `--glib-min-required` argument, just like the
`GLIB_MIN_REQUIRED` and `GLIB_MAX_ALLOWED` preprocessor defines which
control access to APIs in C.

Currently, it doesn’t affect code generation at all. When we next change
code generation, we will need to gate any new API usage on this
argument.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1993
2020-01-27 10:42:26 +00:00
Philip Withnall
4d1c3e15f9 gdbus-codegen: Rename --glib-min-version to --glib-min-required
This makes it consistent with the `GLIB_MIN_REQUIRED` defines which are
used for API stability/versioning in C code.

It doesn’t otherwise change the behaviour of the `--glib-min-version`
argument.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1993
2020-01-27 10:11:46 +00:00
Matthew Leeds
2a605f6e15 gdbus-codegen: Add call_flags and timeout_msec args
Currently the code generated by gdbus-codegen uses
G_DBUS_CALL_FLAGS_NONE in its D-Bus calls, which occur for each method
defined by the input XML, and for proxy_set_property functions. This
means that if the daemon which implements the methods checks for
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION and only does interactive
authorization if that flag is present, users of the generated code have
no way to cause the daemon to use interactive authorization (e.g. polkit
dialogs).

If we simply changed the generated code to always use
G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, its users would have no
way to disallow interactive authorization (except for manually calling
the D-Bus method themselves).

So instead, this commit adds a GDBusCallFlags argument to method call
functions. Since this is an API break which will require changes in
projects using gdbus-codegen code, the change is conditional on the
command line argument --glib-min-version having the value 2.64 or
higher.

The impetus for this change is that I'm changing accountsservice to
properly respect G_DBUS_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, and
libaccountsservice uses generated code for D-Bus method calls. So
these changes will allow libaccountsservice to continue allowing
interactive authorization, and avoid breaking any users of it which
expect that. See
https://gitlab.freedesktop.org/accountsservice/accountsservice/merge_requests/46

It might make sense to also let GDBusCallFlags be specified for property
set operations, but that is not needed in the case of accountsservice,
and would require significant work and breaking API in multiple places.

Similarly, the generated code currently hard codes -1 as the timeout
value when calling g_dbus_proxy_call*(). Add a timeout_msec argument so
the user of the generated code can specify the timeout as well.

Also, test this new API. In gio/tests/codegen.py we test that the new
arguments are generated if and only of --glib-min-version is used with a
value greater than or equal to 2.64, and in gio/tests/meson.build we
test that the generated code with the new API can be linked against.

The test_unix_fd_list() test also needed modification to continue
working now that we're using gdbus-test-codegen.c with code generated
with --glib-min-version=2.64 in one test.

Finally, update the docs for gdbus-codegen to explain the effect of
using --glib-min-version 2.64, both from this commit and from
"gdbus-codegen: Emit GUnixFDLists if an arg has type `h` w/
min-version".
2020-01-15 09:37:41 -08:00
Philip Withnall
e3f80b9254 gdbus-codegen: Emit GUnixFDLists if an arg has type h w/ min-version
This is a reimplementation of commit
4aba03562b from Will Thompson, but
conditional on the caller passing `--glib-min-version 2.64` to
`gdbus-codegen` to explicitly opt-in to the new behaviour.

From the commit message for that commit:

Previously, if a method was not annotated with org.gtk.GDBus.C.UnixFD
then the generated code would never contain GUnixFDList parameters, even
if the method has 'h' (file descriptor) parameters. However, in this
case, the generated code is essentially useless: the method cannot be
called or handled except in degenerate cases where the file descriptors
are missing or ignored.

Check the argument types for 'h', and if present, generate code as if
org.gtk.GDBus.C.UnixFD annotation were specified.

Includes a unit test too.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1726
2019-12-11 10:40:07 +00:00
Philip Withnall
90f0733858 gdbus-codegen: Add a --glib-min-version argument
This can be used by callers to opt-in to backwards-incompatible changes
to the behaviour or output of `gdbus-codegen` in future. This commit
doesn’t introduce any such changes, though.

Documentation and unit tests included.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1726
2019-12-11 10:40:07 +00:00
Philip Withnall
41cabfaa98 tests: Add tests for the gdbus-codegen executable
Add a Python-based test wrapper for the `gdbus-codegen` executable,
similar to the existing tests for `glib-mkenums` and friends.

Add a few basic tests to begin with, but this doesn’t approach anywhere
near full coverage.

The next step is to move the existing Meson-based `gdbus-codegen` tests
from `gio/tests/meson.build` into the Python test suite.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1612
2019-12-02 14:27:11 +00:00