Skip to content

modules/gnome: Allow to generate markdown and reStructuredText dbus doc #14478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/markdown/Gnome-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.xml` reStructuredTexts
* `markdown`: *(Added 1.9.0)* prefix to generate `'PREFIX'-NAME.xml` 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
Expand All @@ -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
Expand Down
66 changes: 66 additions & 0 deletions mesonbuild/modules/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class GdbusCodegen(TypedDict):
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):
Expand Down Expand Up @@ -1619,6 +1621,8 @@ def gtkdoc_html_dir(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'TYP
),
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'})),
Expand Down Expand Up @@ -1675,6 +1679,26 @@ def gdbus_codegen(self, state: 'ModuleState', args: T.Tuple[str, T.Optional[T.Un

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@']
Expand Down Expand Up @@ -1750,6 +1774,48 @@ def gdbus_codegen(self, state: 'ModuleState', args: T.Tuple[str, T.Optional[T.Un
)
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)
Expand Down
17 changes: 17 additions & 0 deletions test cases/frameworks/7 gnome/gdbus/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test cases/frameworks/7 gnome/meson.build
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading