Skip to content

Commit 4f6b650

Browse files
gmarullkartben
authored andcommitted
doc: extensions: doxyrunner: add support for multiple projects
Modify the extension so that multiple Doxygen projects can be added. 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 05c1e56 commit 4f6b650

File tree

2 files changed

+69
-58
lines changed

2 files changed

+69
-58
lines changed

doc/_extensions/zephyr/doxyrunner.py

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828
=====================
2929
3030
- ``doxyrunner_doxygen``: Path to the Doxygen binary.
31-
- ``doxyrunner_doxyfile``: Path to Doxyfile.
32-
- ``doxyrunner_outdir``: Doxygen build output directory (inserted to
33-
``OUTPUT_DIRECTORY``)
34-
- ``doxyrunner_outdir_var``: Variable representing the Doxygen build output
35-
directory, as used by ``OUTPUT_DIRECTORY``. This can be useful if other
36-
Doxygen variables reference to the output directory.
37-
- ``doxyrunner_fmt``: Flag to indicate if Doxyfile should be formatted.
38-
- ``doxyrunner_fmt_vars``: Format variables dictionary (name: value).
39-
- ``doxyrunner_fmt_pattern``: Format pattern.
4031
- ``doxyrunner_silent``: If Doxygen output should be logged or not. Note that
4132
this option may not have any effect if ``QUIET`` is set to ``YES``.
33+
- ``doxyrunner_projects``: Dictionary specifying projects, keys being project
34+
name and values a dictionary with the following keys:
35+
36+
- ``doxyfile``: Path to Doxyfile.
37+
- ``outdir``: Doxygen build output directory (inserted to ``OUTPUT_DIRECTORY``)
38+
- ``outdir_var``: Variable representing the Doxygen build output directory,
39+
as used by ``OUTPUT_DIRECTORY``. This can be useful if other Doxygen
40+
variables reference to the output directory.
41+
- ``fmt``: Flag to indicate if Doxyfile should be formatted.
42+
- ``fmt_vars``: Format variables dictionary (name: value).
43+
- ``fmt_pattern``: Format pattern.
4244
"""
4345

4446
import filecmp
@@ -193,7 +195,7 @@ def process_doxyfile(
193195
return content
194196

195197

196-
def doxygen_input_has_changed(env: BuildEnvironment, doxyfile: str) -> bool:
198+
def doxygen_input_has_changed(env: BuildEnvironment, name, doxyfile: str) -> bool:
197199
"""Check if Doxygen input files have changed.
198200
199201
Args:
@@ -224,12 +226,15 @@ def doxygen_input_has_changed(env: BuildEnvironment, doxyfile: str) -> bool:
224226
for p_file in path.glob("**/" + pattern):
225227
cache.add(hash_file(p_file))
226228

229+
if not hasattr(env, "doxyrunner_cache"):
230+
env.doxyrunner_cache = dict()
231+
227232
# check if any file has changed
228-
if hasattr(env, "doxyrunner_cache") and env.doxyrunner_cache == cache:
233+
if env.doxyrunner_cache.get(name) == cache:
229234
return False
230235

231236
# store current state
232-
env.doxyrunner_cache = cache
237+
env.doxyrunner_cache[name] = cache
233238

234239
return True
235240

@@ -341,53 +346,52 @@ def doxygen_build(app: Sphinx) -> None:
341346
app: Sphinx application instance.
342347
"""
343348

344-
if app.config.doxyrunner_outdir:
345-
outdir = Path(app.config.doxyrunner_outdir)
346-
else:
347-
outdir = Path(app.outdir) / "_doxygen"
348-
349-
outdir.mkdir(exist_ok=True)
350-
tmp_outdir = outdir / "tmp"
351-
352-
logger.info("Preparing Doxyfile...")
353-
doxyfile = process_doxyfile(
354-
app.config.doxyrunner_doxyfile,
355-
tmp_outdir,
356-
app.config.doxyrunner_silent,
357-
app.config.doxyrunner_fmt,
358-
app.config.doxyrunner_fmt_pattern,
359-
app.config.doxyrunner_fmt_vars,
360-
app.config.doxyrunner_outdir_var,
361-
)
349+
for name, config in app.config.doxyrunner_projects.items():
350+
if config.get("outdir"):
351+
outdir = Path(config["outdir"])
352+
else:
353+
outdir = Path(app.outdir) / "_doxygen" / name
362354

363-
logger.info("Checking if Doxygen needs to be run...")
364-
app.env.doxygen_input_changed = doxygen_input_has_changed(app.env, doxyfile)
365-
if not app.env.doxygen_input_changed:
366-
logger.info("Doxygen build will be skipped (no changes)!")
367-
return
368-
369-
logger.info("Running Doxygen...")
370-
run_doxygen(
371-
app.config.doxyrunner_doxygen,
372-
doxyfile,
373-
app.config.doxyrunner_silent,
374-
)
355+
outdir.mkdir(exist_ok=True)
356+
tmp_outdir = outdir / "tmp"
357+
358+
logger.info("Preparing Doxyfile...")
359+
doxyfile = process_doxyfile(
360+
config["doxyfile"],
361+
tmp_outdir,
362+
app.config.doxyrunner_silent,
363+
config.get("fmt", False),
364+
config.get("fmt_pattern", "@{}@"),
365+
config.get("fmt_vars", {}),
366+
config.get("outdir_var"),
367+
)
368+
369+
logger.info(f"Checking if Doxygen needs to be run for {name}...")
370+
if not hasattr(app.env, "doxygen_input_changed"):
371+
app.env.doxygen_input_changed = dict()
372+
373+
app.env.doxygen_input_changed[name] = doxygen_input_has_changed(app.env, name, doxyfile)
374+
if not app.env.doxygen_input_changed[name]:
375+
logger.info(f"Doxygen build for {name} will be skipped (no changes)!")
376+
return
377+
378+
logger.info(f"Running Doxygen for {name}...")
379+
run_doxygen(
380+
app.config.doxyrunner_doxygen,
381+
doxyfile,
382+
app.config.doxyrunner_silent,
383+
)
375384

376-
logger.info("Syncing Doxygen output...")
377-
sync_doxygen(doxyfile, tmp_outdir, outdir)
385+
logger.info(f"Syncing Doxygen output for {name}...")
386+
sync_doxygen(doxyfile, tmp_outdir, outdir)
378387

379-
shutil.rmtree(tmp_outdir)
388+
shutil.rmtree(tmp_outdir)
380389

381390

382391
def setup(app: Sphinx) -> dict[str, Any]:
383392
app.add_config_value("doxyrunner_doxygen", "doxygen", "env")
384-
app.add_config_value("doxyrunner_doxyfile", None, "env")
385-
app.add_config_value("doxyrunner_outdir", None, "env")
386-
app.add_config_value("doxyrunner_outdir_var", None, "env")
387-
app.add_config_value("doxyrunner_fmt", False, "env")
388-
app.add_config_value("doxyrunner_fmt_vars", {}, "env")
389-
app.add_config_value("doxyrunner_fmt_pattern", "@{}@", "env")
390393
app.add_config_value("doxyrunner_silent", True, "")
394+
app.add_config_value("doxyrunner_projects", {}, "")
391395

392396
app.connect("builder-inited", doxygen_build)
393397

doc/conf.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,22 @@
246246
# -- Options for zephyr.doxyrunner plugin ---------------------------------
247247

248248
doxyrunner_doxygen = os.environ.get("DOXYGEN_EXECUTABLE", "doxygen")
249-
doxyrunner_doxyfile = ZEPHYR_BASE / "doc" / "zephyr.doxyfile.in"
250-
doxyrunner_outdir = ZEPHYR_BUILD / "doxygen"
251-
doxyrunner_fmt = True
252-
doxyrunner_fmt_vars = {"ZEPHYR_BASE": str(ZEPHYR_BASE), "ZEPHYR_VERSION": version}
253-
doxyrunner_outdir_var = "DOXY_OUT"
249+
doxyrunner_projects = {
250+
"zephyr": {
251+
"doxyfile": ZEPHYR_BASE / "doc" / "zephyr.doxyfile.in",
252+
"outdir": ZEPHYR_BUILD / "doxygen",
253+
"fmt": True,
254+
"fmt_vars": {
255+
"ZEPHYR_BASE": str(ZEPHYR_BASE),
256+
"ZEPHYR_VERSION": version,
257+
},
258+
"outdir_var": "DOXY_OUT",
259+
},
260+
}
254261

255262
# -- Options for zephyr.doxybridge plugin ---------------------------------
256263

257-
doxybridge_dir = doxyrunner_outdir
264+
doxybridge_dir = doxyrunner_projects["zephyr"]["outdir"]
258265

259266
# -- Options for html_redirect plugin -------------------------------------
260267

@@ -356,7 +363,7 @@
356363

357364
# -- Options for zephyr.api_overview --------------------------------------
358365

359-
api_overview_doxygen_out_dir = str(doxyrunner_outdir)
366+
api_overview_doxygen_out_dir = str(doxyrunner_projects["zephyr"]["outdir"])
360367

361368
def setup(app):
362369
# theme customizations

0 commit comments

Comments
 (0)