diff options
| author | Corentin Noël <corentin.noel@collabora.com> | 2025-04-14 16:55:49 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jussi.pakkanen@mailbox.org> | 2025-06-09 01:33:23 +0300 |
| commit | a3f43cbc5b3738bd26f421d00c1b53736364954c (patch) | |
| tree | 1576ed61145032e2a5b860dde86b8d60468bbf17 | |
| parent | f3c29ecbab2fa9fd05f38a99b0d7ade68673be72 (diff) | |
| download | meson-a3f43cbc5b3738bd26f421d00c1b53736364954c.tar.gz | |
modules/gnome: Allow to generate markdown and reStructuredText dbus doc
gdbus-docgen supports reStructuredText output since 2.71.1 and markdown
since 2.75.2, allow to simply generate it.
| -rw-r--r-- | docs/markdown/Gnome-module.md | 7 | ||||
| -rw-r--r-- | mesonbuild/modules/gnome.py | 66 | ||||
| -rw-r--r-- | test cases/frameworks/7 gnome/gdbus/meson.build | 17 | ||||
| -rw-r--r-- | test cases/frameworks/7 gnome/meson.build | 2 |
4 files changed, 89 insertions, 3 deletions
diff --git a/docs/markdown/Gnome-module.md b/docs/markdown/Gnome-module.md index e8953efc9..84bcc6172 100644 --- a/docs/markdown/Gnome-module.md +++ b/docs/markdown/Gnome-module.md @@ -280,6 +280,8 @@ one XML file. * `object_manager`: *(Added 0.40.0)* if true generates object manager code * `annotations`: *(Added 0.43.0)* list of lists of 3 strings for the annotation for `'ELEMENT', 'KEY', 'VALUE'` * `docbook`: *(Added 0.43.0)* prefix to generate `'PREFIX'-NAME.xml` docbooks +* `rst`: *(Added 1.9.0)* prefix to generate `'PREFIX'-NAME.rst` reStructuredTexts +* `markdown`: *(Added 1.9.0)* prefix to generate `'PREFIX'-NAME.md` markdowns * `build_by_default`: causes, when set to true, to have this target be built by default, that is, when invoking plain `meson compile`, the default value is true for all built target types @@ -289,8 +291,9 @@ one XML file. Starting *0.46.0*, this function returns a list of at least two custom targets (in order): one for the source code and one for the header. -The list will contain a third custom target for the generated docbook -files if that keyword argument is passed. +The list can then contain other custom targets for the generated documentation +files depending if the keyword argument is passed (in order): the docbook +target, the reStructuredText target and the markdown target. Earlier versions return a single custom target representing all the outputs. Generally, you should just add this list of targets to a top diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 3edf07062..17826c7d0 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -137,6 +137,8 @@ if T.TYPE_CHECKING: install_header: bool install_dir: T.Optional[str] docbook: T.Optional[str] + rst: T.Optional[str] + markdown: T.Optional[str] autocleanup: Literal['all', 'none', 'objects', 'default'] class GenMarshal(TypedDict): @@ -1619,6 +1621,8 @@ class GnomeModule(ExtensionModule): ), KwargInfo('install_header', bool, default=False, since='0.46.0'), KwargInfo('docbook', (str, NoneType)), + KwargInfo('rst', (str, NoneType), since='1.9.0'), + KwargInfo('markdown', (str, NoneType), since='1.9.0'), KwargInfo( 'autocleanup', str, default='default', since='0.47.0', validator=in_set_validator({'all', 'none', 'objects'})), @@ -1675,6 +1679,26 @@ class GnomeModule(ExtensionModule): cmd += ['--generate-docbook', docbook] + if kwargs['rst'] is not None: + if not mesonlib.version_compare(glib_version, '>= 2.71.1'): + mlog.error(f'Glib version ({glib_version}) is too old to ' + 'support the \'rst\' kwarg, need 2.71.1 or ' + 'newer') + + rst = kwargs['rst'] + + cmd += ['--generate-rst', rst] + + if kwargs['markdown'] is not None: + if not mesonlib.version_compare(glib_version, '>= 2.75.2'): + mlog.error(f'Glib version ({glib_version}) is too old to ' + 'support the \'markdown\' kwarg, need 2.75.2 ' + 'or newer') + + markdown = kwargs['markdown'] + + cmd += ['--generate-md', markdown] + # https://git.gnome.org/browse/glib/commit/?id=ee09bb704fe9ccb24d92dd86696a0e6bb8f0dc1a if mesonlib.version_compare(glib_version, '>= 2.51.3'): cmd += ['--output-directory', '@OUTDIR@', '--generate-c-code', namebase, '@INPUT@'] @@ -1750,6 +1774,48 @@ class GnomeModule(ExtensionModule): ) targets.append(docbook_custom_target) + if kwargs['rst'] is not None: + rst = kwargs['rst'] + # The rst output is always ${rst}-${name_of_xml_file} + output = namebase + '-rst' + outputs = [] + for f in xml_files: + outputs.append('{}-{}'.format(rst, os.path.basename(str(f)))) + + rst_custom_target = CustomTarget( + output, + state.subdir, + state.subproject, + state.environment, + cmd + ['--output-directory', '@OUTDIR@', '--generate-rst', rst, '@INPUT@'], + xml_files, + outputs, + build_by_default=build_by_default, + description='Generating gdbus reStructuredText {}', + ) + targets.append(rst_custom_target) + + if kwargs['markdown'] is not None: + markdown = kwargs['markdown'] + # The markdown output is always ${markdown}-${name_of_xml_file} + output = namebase + '-markdown' + outputs = [] + for f in xml_files: + outputs.append('{}-{}'.format(markdown, os.path.basename(str(f)))) + + markdown_custom_target = CustomTarget( + output, + state.subdir, + state.subproject, + state.environment, + cmd + ['--output-directory', '@OUTDIR@', '--generate-md', markdown, '@INPUT@'], + xml_files, + outputs, + build_by_default=build_by_default, + description='Generating gdbus markdown {}', + ) + targets.append(markdown_custom_target) + return ModuleReturnValue(targets, targets) @typed_pos_args('gnome.mkenums', str) diff --git a/test cases/frameworks/7 gnome/gdbus/meson.build b/test cases/frameworks/7 gnome/gdbus/meson.build index fdb3896ca..22896e08c 100644 --- a/test cases/frameworks/7 gnome/gdbus/meson.build +++ b/test cases/frameworks/7 gnome/gdbus/meson.build @@ -52,6 +52,23 @@ assert(gdbus_src.length() == 3, 'expected 3 targets') assert(gdbus_src[0].full_path().endswith('.c'), 'expected 1 c source file') assert(gdbus_src[1].full_path().endswith('.h'), 'expected 1 c header file') +if not pretend_glib_old and glib.version().version_compare('>=2.75.2') + gdbus_src_docs = gnome.gdbus_codegen('generated-gdbus-docs', + sources : files('data/com.example.Sample.xml'), + interface_prefix : 'com.example.', + namespace : 'Sample', + docbook : 'generated-gdbus-docs-doc', + rst : 'generated-gdbus-docs-rst', + markdown : 'generated-gdbus-docs-md', + ) + assert(gdbus_src_docs.length() == 5, 'expected 5 targets') + assert(gdbus_src_docs[0].full_path().endswith('.c'), 'expected 1 c source file') + assert(gdbus_src_docs[1].full_path().endswith('.h'), 'expected 1 c header file') + assert('generated-gdbus-docs-doc' in gdbus_src_docs[2].full_path(), 'expected 1 docbook file') + assert('generated-gdbus-docs-rst' in gdbus_src_docs[3].full_path(), 'expected 1 reStructuredText file') + assert('generated-gdbus-docs-md' in gdbus_src_docs[4].full_path(), 'expected 1 markdown file') +endif + if not pretend_glib_old and glib.version().version_compare('>=2.51.3') includes = [] else diff --git a/test cases/frameworks/7 gnome/meson.build b/test cases/frameworks/7 gnome/meson.build index f75ca93a1..37934b77a 100644 --- a/test cases/frameworks/7 gnome/meson.build +++ b/test cases/frameworks/7 gnome/meson.build @@ -1,4 +1,4 @@ -project('gobject-introspection', 'c', meson_version: '>= 1.2.0') +project('gobject-introspection', 'c', meson_version: '>= 1.9.0') copyfile = find_program('copyfile.py') copyfile_gen = generator(copyfile, |
