diff --git a/doc/_extensions/zephyr/link-roles.py b/doc/_extensions/zephyr/link-roles.py index c1474bab312..be82226bd57 100644 --- a/doc/_extensions/zephyr/link-roles.py +++ b/doc/_extensions/zephyr/link-roles.py @@ -9,7 +9,11 @@ from __future__ import unicode_literals import re import subprocess from docutils import nodes +from pathlib import Path from sphinx.util import logging +from typing import Final + +ZEPHYR_BASE: Final[str] = Path(__file__).parents[3] try: import west.manifest @@ -43,6 +47,7 @@ def setup(app): app.add_config_value("link_roles_manifest_baseurl", None, "env") app.add_config_value("link_roles_manifest_project", None, "env") + app.add_config_value("link_roles_manifest_project_broken_links_ignore_globs", [], "env") # The role just creates new nodes based on information in the # arguments; its behavior doesn't depend on any other documents. @@ -59,7 +64,8 @@ def modulelink(default_module=None, format="blob"): rev = get_github_rev() config = inliner.document.settings.env.app.config baseurl = config.link_roles_manifest_baseurl - trace = f"at '{inliner.parent.source}', line {lineno}" + source, line = inliner.reporter.get_source_and_line(lineno) + trace = f"at '{source}:{line}'" m = re.search(r"(.*)\s*<(.*)>", text) if m: @@ -99,6 +105,17 @@ def modulelink(default_module=None, format="blob"): f"Configuration value `link_roles_manifest_baseurl` not set\n\t{trace}" ) + if module == config.link_roles_manifest_project: + p = Path(source).relative_to(inliner.document.settings.env.srcdir) + if not any( + p.match(glob) + for glob in config.link_roles_manifest_project_broken_links_ignore_globs + ): + if not Path(ZEPHYR_BASE, link).exists(): + logger.warning( + f"{link} not found in {config.link_roles_manifest_project} {trace}" + ) + url = f"{baseurl}/{format}/{rev}/{link}" node = nodes.reference(rawtext, link_text, refuri=url, **options) return [node], [] diff --git a/doc/conf.py b/doc/conf.py index f5942acaf44..a25cc6818c7 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -258,6 +258,9 @@ html_redirect_pages = redirects.REDIRECTS # -- Options for zephyr.link-roles ---------------------------------------- link_roles_manifest_project = "zephyr" +link_roles_manifest_project_broken_links_ignore_globs = [ + "releases/release-notes-[123].*.rst", +] link_roles_manifest_baseurl = "https://github.com/zephyrproject-rtos/zephyr" # -- Options for notfound.extension ---------------------------------------