From dcd91a92bcb9fe62e395eeea360115fafddaf9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Thu, 5 Sep 2024 17:58:22 +0200 Subject: [PATCH] doc: _extensions: :zephyr-app:'s should be valid paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a check so that we hopefuly keep all zephyr-app-commands free of references to non-existing paths. Signed-off-by: Benjamin Cabé --- doc/_extensions/zephyr/application.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/_extensions/zephyr/application.py b/doc/_extensions/zephyr/application.py index d6f9a62b5bc..88d2f8fc333 100644 --- a/doc/_extensions/zephyr/application.py +++ b/doc/_extensions/zephyr/application.py @@ -7,8 +7,11 @@ from docutils import nodes from docutils.parsers.rst import Directive from docutils.parsers.rst import directives +from pathlib import Path +ZEPHYR_BASE = Path(__file__).parents[3] + # TODO: extend and modify this for Windows. # # This could be as simple as generating a couple of sets of instructions, one @@ -186,6 +189,16 @@ class ZephyrAppCommandsDirective(Directive): if compact and skip_config: raise self.error('Both compact and maybe-skip-config options were given.') + if zephyr_app: + # as folks might use "<...>" notation to indicate a variable portion of the path, we + # deliberately don't check for the validity of such paths. + if not any([x in zephyr_app for x in ["<", ">"]]): + app_path = ZEPHYR_BASE / zephyr_app + if not app_path.is_dir(): + raise self.error( + f"zephyr-app: {zephyr_app} is not a valid folder in the zephyr tree." + ) + app = app or zephyr_app in_tree = self.IN_TREE_STR if zephyr_app else None # Allow build directories which are nested. @@ -262,7 +275,6 @@ class ZephyrAppCommandsDirective(Directive): literal['language'] = 'shell' return literal - def _generate_west(self, **kwargs): content = [] generator = kwargs['generator']