summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorCorentin Noël <tintou@noel.tf>2023-04-29 23:18:31 +0200
committerCorentin Noël <tintou@noel.tf>2023-04-29 23:25:36 +0200
commitb99435279a281f2c541100b693c96e67d6c1bd62 (patch)
tree804748ffd7a2e609689000996144c84f713a241f /giscanner
parentf9b412e96d5618894158284289cf2a3fe6e7cbfd (diff)
downloadgobject-introspection-b99435279a281f2c541100b693c96e67d6c1bd62.tar.gz
Allow to specify the format of the documentationtintou/doc-format
Helps the consumers of the documentation to assume that the documentation is using gtk-doc format or gi-docgen.
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/ast.py1
-rw-r--r--giscanner/girparser.py12
-rw-r--r--giscanner/girwriter.py6
-rw-r--r--giscanner/scannermain.py8
4 files changed, 27 insertions, 0 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index ad94f437..be8e1e01 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -402,6 +402,7 @@ class Namespace(object):
self.shared_libraries = [] # str
self.c_includes = [] # str
self.exported_packages = [] # str
+ self.doc_format = None
def type_from_name(self, name, ctype=None):
"""Backwards compatibility method for older .gir files, which
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index b652f2d6..23536c81 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -29,6 +29,7 @@ from .message import Position
CORE_NS = "http://www.gtk.org/introspection/core/1.0"
C_NS = "http://www.gtk.org/introspection/c/1.0"
+DOC_NS = "http://www.gtk.org/introspection/doc/1.0"
GLIB_NS = "http://www.gtk.org/introspection/glib/1.0"
@@ -44,6 +45,10 @@ def _cns(tag):
return '{%s}%s' % (C_NS, tag)
+def _docns(tag):
+ return '{%s}%s' % (DOC_NS, tag)
+
+
class GIRParser(object):
def __init__(self, types_only=False):
@@ -65,6 +70,7 @@ class GIRParser(object):
self._pkgconfig_packages = set()
self._includes = set()
self._c_includes = set()
+ self._doc_format = None
self._c_prefix = None
self._parse_api(tree.getroot())
@@ -110,6 +116,8 @@ class GIRParser(object):
self._parse_pkgconfig_package(node)
elif node.tag == _cns('include'):
self._parse_c_include(node)
+ elif node.tag == _docns('format'):
+ self._parse_doc_format(node)
ns = root.find(_corens('namespace'))
assert ns is not None
@@ -127,6 +135,7 @@ class GIRParser(object):
self._namespace.shared_libraries = ns.attrib['shared-library'].split(',')
self._namespace.includes = self._includes
self._namespace.c_includes = self._c_includes
+ self._namespace.doc_format = self._doc_format
self._namespace.exported_packages = self._pkgconfig_packages
parser_methods = {
@@ -166,6 +175,9 @@ class GIRParser(object):
def _parse_c_include(self, node):
self._c_includes.add(node.attrib['name'])
+ def _parse_doc_format(self, node):
+ self._doc_format = node.attrib['name']
+
def _parse_alias(self, node):
typeval = self._parse_type(node)
alias = ast.Alias(node.attrib['name'], typeval, node.attrib.get(_cns('type')))
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index db4dccb4..21197e5a 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -53,6 +53,8 @@ class GIRWriter(XMLWriter):
self._write_pkgconfig_pkg(pkg)
for c_include in sorted(set(namespace.c_includes)):
self._write_c_include(c_include)
+ if namespace.doc_format:
+ self._write_doc_format(namespace.doc_format)
self._namespace = namespace
self._write_namespace(namespace)
self._namespace = None
@@ -69,6 +71,10 @@ class GIRWriter(XMLWriter):
attrs = [('name', c_include)]
self.write_tag('c:include', attrs)
+ def _write_doc_format(self, doc_format):
+ attrs = [('name', doc_format)]
+ self.write_tag('doc:format', attrs)
+
def _write_namespace(self, namespace):
attrs = [('name', namespace.name),
('version', namespace.version),
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index 1d39ab84..186bfd07 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -220,6 +220,10 @@ match the namespace prefix.""")
parser.add_option("", "--compiler",
action="store", dest="compiler", default=None,
help="the C compiler to use internally")
+ parser.add_option("", "--doc-format",
+ action="store", dest="doc_format",
+ help=("name of the documentation format used in the project, "
+ "should be on of gtk-doc or gi-docgen"))
group = get_preprocessor_option_group(parser)
parser.add_option_group(group)
@@ -580,6 +584,9 @@ def scanner_main(args):
or options.header_only):
_error("Must specify --program or --library")
+ if options.doc_format and options.doc_format != 'gtk-doc' and options.doc_format != 'gi-docgen':
+ _error("Unknown doc-type: %s" % (options.doc_format, ))
+
namespace = create_namespace(options)
logger = message.MessageLogger.get(namespace=namespace)
if options.warn_all:
@@ -638,6 +645,7 @@ def scanner_main(args):
transformer.namespace.c_includes = options.c_includes
transformer.namespace.exported_packages = exported_packages
+ transformer.namespace.doc_format = options.doc_format
sources_top_dirs = get_source_root_dirs(options, filenames)
writer = Writer(transformer.namespace, sources_top_dirs)