Commit Graph

164 Commits

Author SHA1 Message Date
Emmanuele Bassi
5f8af01b8b Generate RST anchors for methods, signals, and properties
Don't rely on the titles.
2023-08-28 16:59:32 +01:00
Emmanuele Bassi
5f33ae8901 Generate missing docs for out arguments
The reStructuredText generator is missing the documentation blocks for
out arguments.
2023-08-28 16:59:32 +01: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)
4b05e06e1c gdbus-codegen: Address more black cleanups 2023-06-30 22:17:46 +02:00
Marco Trevisan (Treviño)
88d48a7a22 codegen: Use g_signal_emit to emit signals
We were using emit_by_name which implies looking up for the signal name,
while the generated code can easily remember the signal ID and use it
instead, allowing direct access to the signal emission.
2023-06-29 22:20:05 +02:00
Alynx Zhou
b16201390b codegen: Check parameter before calling its interface method 2022-12-30 13:44:20 +00:00
Guido Günther
4cb945d780 codegen: Support markdown suitable for gi-docgen 2022-12-29 12:42:12 +00:00
Philip Withnall
b4231844a2 Revert "build: Use fs.copyfile() instead of configure_file()"
This reverts commit 19353017a7.

The freedesktop SDK, which is used by gnome-build-meta, only has Meson
0.63. Bumping GLib’s Meson dependency to 0.64 means that, at the moment,
GLib is not buildable in gnome-build-meta and hence can’t be tested in
nightly pipelines against other projects, etc.

That’s bad for testing GLib.

It’s arguably bad that we’re restricted to using an older version of
Meson than shipped by Debian Testing, but that’s a separate discussion
to be had.

Revert the Meson 0.64 dependency until the freedesktop SDK ships Meson ≥
0.64. This also means reverting the simplifications to use of
`gnome.mkenum_simple()`.

See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3077#note_1601064
2022-11-24 12:09:55 +00:00
Philip Withnall
19353017a7 build: Use fs.copyfile() instead of configure_file()
Because Meson complains about using `configure_file(copy: true)`.

Includes improvements by Xavier Claessens.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-11-23 10:40:32 +00:00
Xavier Claessens
a73ca336aa meson: Set install_tag on remaining installed files 2022-09-20 11:30:12 -04:00
Xavier Claessens
a1c78d63ef meson: Set install_tag on all tools
Those tools are not needed at runtime for typical applications,
distributions typically package them separately.

This makes `meson install --tag runtime` skip installation of those
tools. Omitting `--tag` argument will still install them, as well as
with `--tag bin,bin-devel`.

See https://mesonbuild.com/Installing.html#installation-tags.
2022-09-12 09:50:31 -04:00
Philip Withnall
f300e883e7 codegen: Reformat parser.py according to black
This fixes the `style-check-diff` CI job.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-18 01:45:10 +00:00
Emmanuele Bassi
17f38affa2 codegen: Add missing closing angular bracket
We are matching `<parameter>` as well as `<para>`, and we
end up with broken XML in case the (expanded) description
starts with `<parameter>`.

Fixes: #2601
2022-02-15 11:51:11 +00:00
Emmanuele Bassi
6ddf760507 codegen: Remove flake8 lint rule
Using `flake8: noqa` disables ALL linting on a file. Adding
an error code does not limit the linter to that error.
2022-02-15 11:48:58 +00:00
Emmanuele Bassi
128ae2b5f5 codegen: Fix whitespace
This is Python, not C.
2022-02-15 11:48:28 +00:00
Emmanuele Bassi
fe3f699371 Add .flake8 file
The flake8 validation tool prefers an actual configuration
file to inline comments to disable the lint.
2022-02-15 11:47:30 +00:00
Emmanuele Bassi
66e4ba806a Add reStructuredText generator to gdbus-codegen
The gdbus-codegen tool generates documentation from the XML introspection
description of a D-Bus interface. Currently, only DocBook is supported at
the moment, but not every modern documentation generator can handle that
format. The reStructuredText format is a bit more well-supported,
especially in documentation generators for non-C languages.

Unlike DocBook, we get to make our own structure and conventions for how
we structure the documentation when using reStructuredText.
2022-01-22 01:30:16 +00:00
Emmanuele Bassi
5013d08315 codegen: Do not add extra paragraph elements while parsing
When parsing a comment we're adding <para> elements ourselves, but the
DocBook generator already wraps any block of text that does not start
with a <para> element with one.
2022-01-22 01:30:16 +00:00
Phaedrus Leeds
6342922d27 gdbus-codegen: Fix a typo in a comment 2022-01-11 20:03:13 -08:00
Frederic Martinsons
16dfd2033f Annotate function parameters with G_GNUC_UNUSED when necessary
(Tweaked by Philip Withnall to reformat code with `black`)

Closes #1105

Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>
2021-01-06 18:35:17 +00:00
Philip Withnall
b207965697 gdbus-codegen: Ignore some flake8 warnings
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-15 09:43:35 +00:00
Philip Withnall
39f33412db python: Reformat some files to keep style-check-diff happy
The version of `black` on the CI server wanted these changes. Make them
to keep the `style-check-diff` CI job from constantly failing.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-12 18:40:57 +00: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
Simon McVittie
d65c8c30a9 GDBus: Add G_DBUS_METHOD_INVOCATION_HANDLED, _UNHANDLED
Like G_SOURCE_REMOVE and G_SOURCE_CONTINUE, these make it clearer what
it means to return TRUE or FALSE.

In particular, in GDBus methods that fail, the failure case still needs
to return TRUE (unlike the typical GError pattern), leading to comments
like this:

    g_dbus_method_invocation_return_error (invocation, ...);
    return TRUE;    /* handled */

which can now be replaced by:

    g_dbus_method_invocation_return_error (invocation, ...);
    return G_DUS_METHOD_INVOCATION_HANDLED;

G_DBUS_METHOD_INVOCATION_UNHANDLED is added for symmetry, but is very
rarely (perhaps never?) useful in practice.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-10-01 16:32:50 +01:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Chun-wei Fan
d955719f04 gdbus-codegen: Allow decorating symbols in headers
This adds three options to gdbus-codegen so that we may be able to
use a self-defined symbol decorator, such as _GLIB_EXTERN, to decorate
the generated prototypes, to be used possibly to export the symbols, if
needed.

The other two options allows including headers that are required for the
specified symbol decorator to be usable and preprocessor macros that are
required for the symbol decorator to be defined appropriately, also when
needed.
2020-05-28 17:20:22 +08:00
Philip Withnall
65be80c3ed build: Rework path construction to reliably add prefix
There were a couple of custom paths which could end up being relative,
rather than absolute, due to not properly prefixing them with
`get_option('prefix')`.

The use of `join_paths()` here correctly drops all path components
before the final absolute path in the list of arguments. So if someone
configures GLib with an absolute path for `gio_module_dir`, that will be
used unprefixed; but if someone configures with a relative path, it will
be prefixed by `get_option('prefix)`.

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

Fixes: #1919
2020-02-07 17:12:35 +00:00
Philip Withnall
087b9829f4 gdbus-codegen: Tidy up version comparisons
Python tuple comparisons actually do what we want for comparing major
and minor versions, so tidy things up by using that.

This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-01-31 12:23:50 +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
Emmanuele Bassi
a172aa3662 Merge branch '1130-codegen-docs' into 'master'
Resolve "gdbus-codegen: Add an option to strictly generate markdown in source comments"

Closes #1130

See merge request GNOME/glib!1264
2019-12-16 12:39:23 +00: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
a6c1ee22c1 gdbus-codegen: Drop DocBook warning tags from generated code
gtk-doc switched from DocBook to Markdown ages ago. There is no Markdown
equivalent for `<warning>`, so just drop it. It wasn’t adding anything
particularly valuable to the documentation.

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

Fixes: #1130
2019-12-02 16:48:32 +00:00
Philip Withnall
9a93fd93f0 gdbus-codegen: Remove DocBook link tags from generated code
gtk-doc long since switched to Markdown, so we shouldn’t be emitting
DocBook `<link>` tags.

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

Helps: #1130
2019-12-02 16:47:44 +00:00
Philip Withnall
8f4155c124 codegen: Require at least one interface file to be specified
Previously, running `gdbus-codegen` with no arguments would exit
successfully with no output. While technically correct, that seems
unhelpful.

Require at least one interface file to be specified, so the user gets an
error message if they don’t specify any.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-12-02 14:09:45 +00:00
Philip Withnall
921e6d1245 codegen: Drop gdbus-codegen version and input filename from output
It’s not particularly useful to put the gdbus-codegen version or the
name of the input file into the output from `gdbus-codegen`, and it
makes the output less reproducible. Drop it.

Also clarify the licensing.

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

Helps: #1612
2019-12-02 14:09:45 +00:00
Philip Withnall
9b8ff414c1 Merge branch 'no-more-automatic-GUnixFDList' into 'master'
Revert "gdbus-codegen: emit GUnixFDLists if an arg has type 'h'"

See merge request GNOME/glib!1171
2019-10-31 13:42:55 +00:00
Mattias Bengtsson
4aaeac5b3c gdbus-codegen: Safer header guards
Whitelist a safe set of characters for use in header guards instead of
maintaining a (growing) blacklist.

The whitelist is intentionally short since reading up on all
peculiarities of the C and C++ standard for identifiers is not my idea
of fun. :)

Fixes #1379
2019-10-31 12:50:30 +00:00
Will Thompson
43697d6b99 Revert "gdbus-codegen: emit GUnixFDLists if an arg has type 'h'"
This reverts commit 4aba03562b, preserving
the new tests but adjusting them to assert that the old behaviour is
restored.

As expected, there were a few projects which broke because of this.
Unfortunately, in one case the breakage crosses a project boundary:
sysprof ships D-Bus introspection XML, which is consumed by mutter and
passed through gdbus-codegen.

Since sysprof cannot add this annotation without breaking its existing
users, a warning is also not appropriate.

https://gitlab.gnome.org/GNOME/jhbuild/issues/41
https://gitlab.gnome.org/GNOME/sysprof/issues/17
https://gitlab.gnome.org/GNOME/glib/issues/1726
2019-10-18 10:30:00 +01:00
Will Thompson
4aba03562b gdbus-codegen: emit GUnixFDLists if an arg has type 'h'
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.

This change will break any existing code which refers to the (useless)
wrappers for such methods. The workaround for such code is to add the
org.gtk.GDBus.C.UnixFD annotation, which will cause the same generated
code to be emitted before and after this change.

If this is found to cause widespread problems, we can explore a
different approach (perhaps emitting a warning from the code generator,
or annotating the symbols as deprecated).

https://gitlab.gnome.org/GNOME/glib/issues/1726
2019-09-02 20:47:20 +01:00
Will Thompson
9b827e5674 gdbus-codegen: process C.UnixFD annotation in one place
This will make it simpler to enable this behaviour based on the method
signature.

https://gitlab.gnome.org/GNOME/glib/issues/1726
2019-09-02 06:54:37 +01:00