Skip to content

Commit 9a1c378

Browse files
gmarullkartben
authored andcommitted
doc: extensions: doxybridge: add support for multiple projects
Modify the extension so that multiple Doxygen projects can be referenced. While not required in upstream Zephyr, other users downstream may require support for this feature. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 4f6b650 commit 9a1c378

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

doc/_extensions/zephyr/doxybridge.py

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import doxmlparser
1212
from docutils import nodes
13+
from docutils.parsers.rst import directives
1314
from doxmlparser.compound import DoxCompoundKind, DoxMemberKind
1415
from sphinx import addnodes
1516
from sphinx.application import Sphinx
@@ -34,6 +35,9 @@ class DoxygenGroupDirective(SphinxDirective):
3435
has_content = False
3536
required_arguments = 1
3637
optional_arguments = 0
38+
option_spec = {
39+
"project": directives.unchanged,
40+
}
3741

3842
def run(self):
3943

@@ -48,6 +52,7 @@ def run(self):
4852
reftype="group",
4953
reftarget=self.arguments[0],
5054
refwarn=True,
55+
project=self.options.get("project")
5156
)
5257
group_xref += nodes.Text(self.arguments[0])
5358
title_signode += group_xref
@@ -73,28 +78,40 @@ def run(self, **kwargs: Any) -> None:
7378
if reftype in ("member", "data"):
7479
reftype = "var"
7580

76-
entry = self.app.env.doxybridge_cache.get(reftype)
77-
if not entry:
78-
continue
81+
found_name = None
82+
found_id = None
83+
for name in self.app.config.doxybridge_projects:
84+
entry = self.app.env.doxybridge_cache[name].get(reftype)
85+
if not entry:
86+
continue
7987

80-
reftarget = node.get("reftarget").replace(".", "::").rstrip("()")
81-
id = entry.get(reftarget)
82-
if not id:
83-
if reftype == "func":
84-
# macros are sometimes referenced as functions, so try that
85-
id = self.app.env.doxybridge_cache.get("macro").get(reftarget)
86-
if not id:
88+
reftarget = node.get("reftarget").replace(".", "::").rstrip("()")
89+
id = entry.get(reftarget)
90+
if not id:
91+
if reftype == "func":
92+
# macros are sometimes referenced as functions, so try that
93+
id = self.app.env.doxybridge_cache[name].get("macro").get(reftarget)
94+
if not id:
95+
continue
96+
else:
8797
continue
88-
else:
89-
continue
98+
99+
found_name = name
100+
found_id = id
101+
break
102+
103+
if not found_name or not found_id:
104+
continue
90105

91106
if reftype in ("struct", "union", "group"):
92107
doxygen_target = f"{id}.html"
93108
else:
94-
split = id.split("_")
109+
split = found_id.split("_")
95110
doxygen_target = f"{'_'.join(split[:-1])}.html#{split[-1][1:]}"
96111

97-
doxygen_target = str(self.app.config.doxybridge_dir) + "/html/" + doxygen_target
112+
doxygen_target = (
113+
str(self.app.config.doxybridge_projects[found_name]) + "/html/" + doxygen_target
114+
)
98115

99116
doc_dir = os.path.dirname(self.document.get("source"))
100117
doc_dest = os.path.join(
@@ -109,7 +126,7 @@ def run(self, **kwargs: Any) -> None:
109126

110127
if reftype == "group":
111128
refnode["classes"].append("doxygroup")
112-
title = self.app.env.doxybridge_group_titles.get(reftarget, "group")
129+
title = self.app.env.doxybridge_group_titles[found_name].get(reftarget, "group")
113130
refnode[0] = nodes.Text(title)
114131

115132
node.replace_self([refnode])
@@ -178,7 +195,7 @@ def parse_compound(inDirName, baseName) -> dict:
178195
return cache, group_titles
179196

180197

181-
def parse_index(app: Sphinx, inDirName):
198+
def parse_index(app: Sphinx, name, inDirName):
182199
rootObj = doxmlparser.index.parse(inDirName + "/index.xml", True)
183200
compounds = rootObj.get_compound()
184201

@@ -190,33 +207,40 @@ def parse_index(app: Sphinx, inDirName):
190207
for future in concurrent.futures.as_completed(futures):
191208
cache, group_titles = future.result()
192209
for kind, data in cache.items():
193-
app.env.doxybridge_cache.setdefault(kind, {}).update(data)
194-
app.env.doxybridge_group_titles.update(group_titles)
210+
app.env.doxybridge_cache[name].setdefault(kind, {}).update(data)
211+
app.env.doxybridge_group_titles[name].update(group_titles)
195212

196213

197214
def doxygen_parse(app: Sphinx) -> None:
198-
if not app.env.doxygen_input_changed:
199-
return
200-
201-
app.env.doxybridge_cache = {
202-
"macro": {},
203-
"var": {},
204-
"type": {},
205-
"enum": {},
206-
"enumerator": {},
207-
"func": {},
208-
"union": {},
209-
"struct": {},
210-
"group": {},
211-
}
215+
if not hasattr(app.env, "doxybridge_cache"):
216+
app.env.doxybridge_cache = dict()
217+
218+
if not hasattr(app.env, "doxybridge_group_titles"):
219+
app.env.doxybridge_group_titles = dict()
220+
221+
for project, path in app.config.doxybridge_projects.items():
222+
if project in app.env.doxygen_input_changed and not app.env.doxygen_input_changed[project]:
223+
return
224+
225+
app.env.doxybridge_cache[project] = {
226+
"macro": {},
227+
"var": {},
228+
"type": {},
229+
"enum": {},
230+
"enumerator": {},
231+
"func": {},
232+
"union": {},
233+
"struct": {},
234+
"group": {},
235+
}
212236

213-
app.env.doxybridge_group_titles = {}
237+
app.env.doxybridge_group_titles[project] = dict()
214238

215-
parse_index(app, str(app.config.doxybridge_dir / "xml"))
239+
parse_index(app, project, str(path / "xml"))
216240

217241

218242
def setup(app: Sphinx) -> dict[str, Any]:
219-
app.add_config_value("doxybridge_dir", None, "env")
243+
app.add_config_value("doxybridge_projects", None, "env")
220244

221245
app.add_directive("doxygengroup", DoxygenGroupDirective)
222246

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261

262262
# -- Options for zephyr.doxybridge plugin ---------------------------------
263263

264-
doxybridge_dir = doxyrunner_projects["zephyr"]["outdir"]
264+
doxybridge_projects = {"zephyr": doxyrunner_projects["zephyr"]["outdir"]}
265265

266266
# -- Options for html_redirect plugin -------------------------------------
267267

0 commit comments

Comments
 (0)