docs: fix gobject-introspection data generation

Let g-ir-scanner parse the original headers for the C signatures
and just add the gtk-doc comments in the generated wp-gtkdoc.h file

Also cleanup a bit gen-api-gtkdoc.py and make it omit printing most of the
whitespace clutter that it used to print inside the gtk-doc comments
This commit is contained in:
George Kiagiadakis
2021-05-24 15:42:55 +03:00
parent 4dfb4e1780
commit c3ee52506b
3 changed files with 28 additions and 52 deletions

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright 2015 The Geany contributors # Copyright 2015 The Geany contributors
# Copyright 2021 Collabora Ltd.
# @author George Kiagiadakis <george.kiagiadakis@collabora.com>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -129,7 +130,7 @@ class DoxygenProcess(object):
def __process_element(self, xml): def __process_element(self, xml):
s = "" s = ""
if xml.text: if xml.text and re.search('\S', xml.text):
s += xml.text s += xml.text
for n in xml.getchildren(): for n in xml.getchildren():
if n.tag == "emphasis": if n.tag == "emphasis":
@@ -141,7 +142,9 @@ class DoxygenProcess(object):
if n.tag == "listitem": if n.tag == "listitem":
s += " - " + self.__process_element(n) s += " - " + self.__process_element(n)
if n.tag == "para": if n.tag == "para":
s += self.__process_element(n) + "\n" p = self.__process_element(n)
if re.search('\S', p):
s += p + "\n"
if n.tag == "ref": if n.tag == "ref":
s += n.text if n.text else "" s += n.text if n.text else ""
if n.tag == "simplesect": if n.tag == "simplesect":
@@ -165,6 +168,7 @@ class DoxygenProcess(object):
if n.tag == "htmlonly": if n.tag == "htmlonly":
s += "" s += ""
if n.tail: if n.tail:
if re.search('\S', n.tail):
s += n.tail s += n.tail
if n.tag.startswith("param"): if n.tag.startswith("param"):
pass # parameters are handled separately in DoxyFunction::from_memberdef() pass # parameters are handled separately in DoxyFunction::from_memberdef()
@@ -328,10 +332,6 @@ def main(args):
outfile = None outfile = None
parser = OptionParser(usage="usage: %prog [options] XML_DIR") parser = OptionParser(usage="usage: %prog [options] XML_DIR")
parser.add_option("--xmldir", metavar="DIRECTORY", help="Path to Doxygen-generated XML files",
action="store", dest="xml_dir")
parser.add_option("-d", "--outdir", metavar="DIRECTORY", help="Path to Doxygen-generated XML files",
action="store", dest="outdir", default=".")
parser.add_option("-o", "--output", metavar="FILE", help="Write output to FILE", parser.add_option("-o", "--output", metavar="FILE", help="Write output to FILE",
action="store", dest="outfile") action="store", dest="outfile")
opts, args = parser.parse_args(args[1:]) opts, args = parser.parse_args(args[1:])
@@ -342,36 +342,25 @@ def main(args):
sys.stderr.write("invalid xml directory\n") sys.stderr.write("invalid xml directory\n")
return 1 return 1
symbols = []
transform = etree.XSLT(etree.parse(os.path.join(xml_dir, "combine.xslt"))) transform = etree.XSLT(etree.parse(os.path.join(xml_dir, "combine.xslt")))
doc = etree.parse(os.path.join(xml_dir, "index.xml")) doc = etree.parse(os.path.join(xml_dir, "index.xml"))
root = transform(doc) root = transform(doc)
other = []
enums = []
typedefs = []
c_files = root.xpath(".//compounddef[@kind='file']/compoundname[substring(.,string-length(.)-1)='.c']/..")
h_files = root.xpath(".//compounddef[@kind='file']/compoundname[substring(.,string-length(.)-1)='.h']/..") h_files = root.xpath(".//compounddef[@kind='file']/compoundname[substring(.,string-length(.)-1)='.h']/..")
for f in h_files: for f in h_files:
if not (f.find("compoundname").text.endswith("private.h")): for n0 in f.xpath(".//*/memberdef[@kind='enum']"):
for n0 in f.xpath(".//*/memberdef[@kind='typedef' and @prot='public']"):
if not (DoxygenProcess.stringify_children(n0.find("type")).startswith("enum")):
e = DoxyTypedef.from_memberdef(n0)
typedefs.append(e)
for n0 in f.xpath(".//*/memberdef[@kind='enum' and @prot='public']"):
e = DoxyEnum.from_memberdef(n0) e = DoxyEnum.from_memberdef(n0)
enums.append(e) symbols.append(e)
for n0 in root.xpath(".//compounddef[@kind='struct' and @prot='public']"): for n0 in root.xpath(".//compounddef[@kind='struct']"):
e = DoxyStruct.from_compounddef(n0) e = DoxyStruct.from_compounddef(n0)
other.append(e) symbols.append(e)
for n0 in root.xpath(".//compounddef[@kind='struct' and @prot='public']"): for n0 in root.xpath(".//compounddef[@kind='group']"):
for n1 in n0.xpath(".//*/memberdef[@kind='function' and @prot='public']"): for n1 in n0.xpath(".//*/memberdef[@kind='function']"):
e = DoxyFunction.from_memberdef(n1) e = DoxyFunction.from_memberdef(n1)
other.append(e) symbols.append(e)
if (opts.outfile): if (opts.outfile):
try: try:
@@ -385,26 +374,10 @@ def main(args):
try: try:
outfile.write("/*\n * Automatically generated file - do not edit\n */\n\n") outfile.write("/*\n * Automatically generated file - do not edit\n */\n\n")
# write enums first, so typedefs to them are valid (as forward enum declaration for e in filter(lambda x: x.is_documented(), symbols):
# is invalid). It's fine as an enum can't contain reference to other types. outfile.write("\n")
for e in filter(lambda x: x.is_documented(), enums):
outfile.write("\n\n")
outfile.write(e.to_gtkdoc()) outfile.write(e.to_gtkdoc())
outfile.write(e.definition) outfile.write("\n")
outfile.write("\n\n")
# write typedefs second, they are possibly undocumented but still required (even
# if they are documented, they must be written out without gtkdoc)
for e in typedefs:
outfile.write(e.definition)
outfile.write("\n\n")
# write the rest (structures, functions, ...)
for e in filter(lambda x: x.is_documented(), other):
outfile.write("\n\n")
outfile.write(e.to_gtkdoc())
outfile.write(e.definition)
outfile.write("\n\n")
except BrokenPipeError: except BrokenPipeError:
# probably piped to head or tail # probably piped to head or tail

View File

@@ -40,7 +40,7 @@ if build_doc or build_gir
configuration: doxy_wp_conf_data configuration: doxy_wp_conf_data
) )
doxyxml_wp_depfiles = [wp_lib_sources, wp_lib_headers] doxyxml_wp_depfiles = [wp_lib_sources, wp_lib_parse_headers]
doxyxml_wp = custom_target('doxyxml_wp', doxyxml_wp = custom_target('doxyxml_wp',
command: [doxygen_p, doxyfile_wp], command: [doxygen_p, doxyfile_wp],
depend_files: doxyxml_wp_depfiles, depend_files: doxyxml_wp_depfiles,
@@ -123,7 +123,7 @@ if build_gir
'@OUTDIR@/wp/xml', '@OUTDIR@/wp/xml',
], ],
depends: [doxyxml_wp], depends: [doxyxml_wp],
depend_files: doxyxml_wp_depfiles, depend_files: [doxyxml_wp_depfiles, 'gen-api-gtkdoc.py'],
output: 'wp-gtkdoc.h', output: 'wp-gtkdoc.h',
build_by_default: true, build_by_default: true,
) )
@@ -131,7 +131,7 @@ if build_gir
gnome.generate_gir(wp_lib, gnome.generate_gir(wp_lib,
namespace: 'Wp', namespace: 'Wp',
nsversion: wireplumber_api_version, nsversion: wireplumber_api_version,
sources: [wpenums_c, wpenums_h, wp_gtkdoc_h], sources: [wpenums_h, wp_lib_parse_headers, wp_gtkdoc_h],
includes: ['GLib-2.0', 'GObject-2.0', 'Gio-2.0'], includes: ['GLib-2.0', 'GObject-2.0', 'Gio-2.0'],
install: true, install: true,
) )

View File

@@ -33,7 +33,7 @@ wp_lib_priv_sources = files(
'private/pipewire-object-mixin.c', 'private/pipewire-object-mixin.c',
) )
wp_lib_headers = files( wp_lib_parse_headers = files(
'client.h', 'client.h',
'component-loader.h', 'component-loader.h',
'core.h', 'core.h',
@@ -62,6 +62,9 @@ wp_lib_headers = files(
'spa-type.h', 'spa-type.h',
'state.h', 'state.h',
'transition.h', 'transition.h',
)
wp_lib_headers = wp_lib_parse_headers + files(
'wp.h', 'wp.h',
) )
@@ -70,7 +73,7 @@ install_headers(wp_lib_headers,
) )
enums = gnome.mkenums_simple('wpenums', enums = gnome.mkenums_simple('wpenums',
sources: wp_lib_headers, sources: wp_lib_parse_headers,
header_prefix: '#include "wp/defs.h"', header_prefix: '#include "wp/defs.h"',
decorator: 'WP_API', decorator: 'WP_API',
install_header: true, install_header: true,