Skip to content

Commit 3141c0d

Browse files
committed
[nrf fromlist] 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. Upstream PR #: 82432 Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit b5e98221cf694cb43f14ebed86bf2591e36e609b)
1 parent ae67298 commit 3141c0d

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
@@ -194,7 +196,7 @@ def process_doxyfile(
194196
return content
195197

196198

197-
def doxygen_input_has_changed(env: BuildEnvironment, doxyfile: str) -> bool:
199+
def doxygen_input_has_changed(env: BuildEnvironment, name, doxyfile: str) -> bool:
198200
"""Check if Doxygen input files have changed.
199201
200202
Args:
@@ -225,12 +227,15 @@ def doxygen_input_has_changed(env: BuildEnvironment, doxyfile: str) -> bool:
225227
for p_file in path.glob("**/" + pattern):
226228
cache.add(hash_file(p_file))
227229

230+
if not hasattr(env, "doxyrunner_cache"):
231+
env.doxyrunner_cache = dict()
232+
228233
# check if any file has changed
229-
if hasattr(env, "doxyrunner_cache") and env.doxyrunner_cache == cache:
234+
if env.doxyrunner_cache.get(name) == cache:
230235
return False
231236

232237
# store current state
233-
env.doxyrunner_cache = cache
238+
env.doxyrunner_cache[name] = cache
234239

235240
return True
236241

@@ -342,53 +347,52 @@ def doxygen_build(app: Sphinx) -> None:
342347
app: Sphinx application instance.
343348
"""
344349

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

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

377-
logger.info("Syncing Doxygen output...")
378-
sync_doxygen(doxyfile, tmp_outdir, outdir)
386+
logger.info(f"Syncing Doxygen output for {name}...")
387+
sync_doxygen(doxyfile, tmp_outdir, outdir)
379388

380-
shutil.rmtree(tmp_outdir)
389+
shutil.rmtree(tmp_outdir)
381390

382391

383392
def setup(app: Sphinx) -> Dict[str, Any]:
384393
app.add_config_value("doxyrunner_doxygen", "doxygen", "env")
385-
app.add_config_value("doxyrunner_doxyfile", None, "env")
386-
app.add_config_value("doxyrunner_outdir", None, "env")
387-
app.add_config_value("doxyrunner_outdir_var", None, "env")
388-
app.add_config_value("doxyrunner_fmt", False, "env")
389-
app.add_config_value("doxyrunner_fmt_vars", {}, "env")
390-
app.add_config_value("doxyrunner_fmt_pattern", "@{}@", "env")
391394
app.add_config_value("doxyrunner_silent", True, "")
395+
app.add_config_value("doxyrunner_projects", {}, "")
392396

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

doc/conf.py

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

243243
doxyrunner_doxygen = os.environ.get("DOXYGEN_EXECUTABLE", "doxygen")
244-
doxyrunner_doxyfile = ZEPHYR_BASE / "doc" / "zephyr.doxyfile.in"
245-
doxyrunner_outdir = ZEPHYR_BUILD / "doxygen"
246-
doxyrunner_fmt = True
247-
doxyrunner_fmt_vars = {"ZEPHYR_BASE": str(ZEPHYR_BASE), "ZEPHYR_VERSION": version}
248-
doxyrunner_outdir_var = "DOXY_OUT"
244+
doxyrunner_projects = {
245+
"zephyr": {
246+
"doxyfile": ZEPHYR_BASE / "doc" / "zephyr.doxyfile.in",
247+
"outdir": ZEPHYR_BUILD / "doxygen",
248+
"fmt": True,
249+
"fmt_vars": {
250+
"ZEPHYR_BASE": str(ZEPHYR_BASE),
251+
"ZEPHYR_VERSION": version,
252+
},
253+
"outdir_var": "DOXY_OUT",
254+
},
255+
}
249256

250257
# -- Options for zephyr.doxybridge plugin ---------------------------------
251258

252-
doxybridge_dir = doxyrunner_outdir
259+
doxybridge_dir = doxyrunner_projects["zephyr"]["outdir"]
253260

254261
# -- Options for html_redirect plugin -------------------------------------
255262

@@ -348,7 +355,7 @@
348355

349356
# -- Options for zephyr.api_overview --------------------------------------
350357

351-
api_overview_doxygen_out_dir = str(doxyrunner_outdir)
358+
api_overview_doxygen_out_dir = str(doxyrunner_projects["zephyr"]["outdir"])
352359

353360
def setup(app):
354361
# theme customizations

0 commit comments

Comments
 (0)