Skip to content

Commit a3f43cb

Browse files
tintoujpakkane
authored andcommitted
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.
1 parent f3c29ec commit a3f43cb

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

docs/markdown/Gnome-module.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ one XML file.
280280
* `object_manager`: *(Added 0.40.0)* if true generates object manager code
281281
* `annotations`: *(Added 0.43.0)* list of lists of 3 strings for the annotation for `'ELEMENT', 'KEY', 'VALUE'`
282282
* `docbook`: *(Added 0.43.0)* prefix to generate `'PREFIX'-NAME.xml` docbooks
283+
* `rst`: *(Added 1.9.0)* prefix to generate `'PREFIX'-NAME.rst` reStructuredTexts
284+
* `markdown`: *(Added 1.9.0)* prefix to generate `'PREFIX'-NAME.md` markdowns
283285
* `build_by_default`: causes, when set to true, to have this target be
284286
built by default, that is, when invoking plain `meson compile`, the default
285287
value is true for all built target types
@@ -289,8 +291,9 @@ one XML file.
289291

290292
Starting *0.46.0*, this function returns a list of at least two custom
291293
targets (in order): one for the source code and one for the header.
292-
The list will contain a third custom target for the generated docbook
293-
files if that keyword argument is passed.
294+
The list can then contain other custom targets for the generated documentation
295+
files depending if the keyword argument is passed (in order): the docbook
296+
target, the reStructuredText target and the markdown target.
294297

295298
Earlier versions return a single custom target representing all the
296299
outputs. Generally, you should just add this list of targets to a top

mesonbuild/modules/gnome.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class GdbusCodegen(TypedDict):
137137
install_header: bool
138138
install_dir: T.Optional[str]
139139
docbook: T.Optional[str]
140+
rst: T.Optional[str]
141+
markdown: T.Optional[str]
140142
autocleanup: Literal['all', 'none', 'objects', 'default']
141143

142144
class GenMarshal(TypedDict):
@@ -1619,6 +1621,8 @@ def gtkdoc_html_dir(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'TYP
16191621
),
16201622
KwargInfo('install_header', bool, default=False, since='0.46.0'),
16211623
KwargInfo('docbook', (str, NoneType)),
1624+
KwargInfo('rst', (str, NoneType), since='1.9.0'),
1625+
KwargInfo('markdown', (str, NoneType), since='1.9.0'),
16221626
KwargInfo(
16231627
'autocleanup', str, default='default', since='0.47.0',
16241628
validator=in_set_validator({'all', 'none', 'objects'})),
@@ -1675,6 +1679,26 @@ def gdbus_codegen(self, state: 'ModuleState', args: T.Tuple[str, T.Optional[T.Un
16751679

16761680
cmd += ['--generate-docbook', docbook]
16771681

1682+
if kwargs['rst'] is not None:
1683+
if not mesonlib.version_compare(glib_version, '>= 2.71.1'):
1684+
mlog.error(f'Glib version ({glib_version}) is too old to '
1685+
'support the \'rst\' kwarg, need 2.71.1 or '
1686+
'newer')
1687+
1688+
rst = kwargs['rst']
1689+
1690+
cmd += ['--generate-rst', rst]
1691+
1692+
if kwargs['markdown'] is not None:
1693+
if not mesonlib.version_compare(glib_version, '>= 2.75.2'):
1694+
mlog.error(f'Glib version ({glib_version}) is too old to '
1695+
'support the \'markdown\' kwarg, need 2.75.2 '
1696+
'or newer')
1697+
1698+
markdown = kwargs['markdown']
1699+
1700+
cmd += ['--generate-md', markdown]
1701+
16781702
# https://git.gnome.org/browse/glib/commit/?id=ee09bb704fe9ccb24d92dd86696a0e6bb8f0dc1a
16791703
if mesonlib.version_compare(glib_version, '>= 2.51.3'):
16801704
cmd += ['--output-directory', '@OUTDIR@', '--generate-c-code', namebase, '@INPUT@']
@@ -1750,6 +1774,48 @@ def gdbus_codegen(self, state: 'ModuleState', args: T.Tuple[str, T.Optional[T.Un
17501774
)
17511775
targets.append(docbook_custom_target)
17521776

1777+
if kwargs['rst'] is not None:
1778+
rst = kwargs['rst']
1779+
# The rst output is always ${rst}-${name_of_xml_file}
1780+
output = namebase + '-rst'
1781+
outputs = []
1782+
for f in xml_files:
1783+
outputs.append('{}-{}'.format(rst, os.path.basename(str(f))))
1784+
1785+
rst_custom_target = CustomTarget(
1786+
output,
1787+
state.subdir,
1788+
state.subproject,
1789+
state.environment,
1790+
cmd + ['--output-directory', '@OUTDIR@', '--generate-rst', rst, '@INPUT@'],
1791+
xml_files,
1792+
outputs,
1793+
build_by_default=build_by_default,
1794+
description='Generating gdbus reStructuredText {}',
1795+
)
1796+
targets.append(rst_custom_target)
1797+
1798+
if kwargs['markdown'] is not None:
1799+
markdown = kwargs['markdown']
1800+
# The markdown output is always ${markdown}-${name_of_xml_file}
1801+
output = namebase + '-markdown'
1802+
outputs = []
1803+
for f in xml_files:
1804+
outputs.append('{}-{}'.format(markdown, os.path.basename(str(f))))
1805+
1806+
markdown_custom_target = CustomTarget(
1807+
output,
1808+
state.subdir,
1809+
state.subproject,
1810+
state.environment,
1811+
cmd + ['--output-directory', '@OUTDIR@', '--generate-md', markdown, '@INPUT@'],
1812+
xml_files,
1813+
outputs,
1814+
build_by_default=build_by_default,
1815+
description='Generating gdbus markdown {}',
1816+
)
1817+
targets.append(markdown_custom_target)
1818+
17531819
return ModuleReturnValue(targets, targets)
17541820

17551821
@typed_pos_args('gnome.mkenums', str)

test cases/frameworks/7 gnome/gdbus/meson.build

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ assert(gdbus_src.length() == 3, 'expected 3 targets')
5252
assert(gdbus_src[0].full_path().endswith('.c'), 'expected 1 c source file')
5353
assert(gdbus_src[1].full_path().endswith('.h'), 'expected 1 c header file')
5454

55+
if not pretend_glib_old and glib.version().version_compare('>=2.75.2')
56+
gdbus_src_docs = gnome.gdbus_codegen('generated-gdbus-docs',
57+
sources : files('data/com.example.Sample.xml'),
58+
interface_prefix : 'com.example.',
59+
namespace : 'Sample',
60+
docbook : 'generated-gdbus-docs-doc',
61+
rst : 'generated-gdbus-docs-rst',
62+
markdown : 'generated-gdbus-docs-md',
63+
)
64+
assert(gdbus_src_docs.length() == 5, 'expected 5 targets')
65+
assert(gdbus_src_docs[0].full_path().endswith('.c'), 'expected 1 c source file')
66+
assert(gdbus_src_docs[1].full_path().endswith('.h'), 'expected 1 c header file')
67+
assert('generated-gdbus-docs-doc' in gdbus_src_docs[2].full_path(), 'expected 1 docbook file')
68+
assert('generated-gdbus-docs-rst' in gdbus_src_docs[3].full_path(), 'expected 1 reStructuredText file')
69+
assert('generated-gdbus-docs-md' in gdbus_src_docs[4].full_path(), 'expected 1 markdown file')
70+
endif
71+
5572
if not pretend_glib_old and glib.version().version_compare('>=2.51.3')
5673
includes = []
5774
else

test cases/frameworks/7 gnome/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('gobject-introspection', 'c', meson_version: '>= 1.2.0')
1+
project('gobject-introspection', 'c', meson_version: '>= 1.9.0')
22

33
copyfile = find_program('copyfile.py')
44
copyfile_gen = generator(copyfile,

0 commit comments

Comments
 (0)