From 083aa1ebf6dde1380eba2ce01b163b3deefc3a7c Mon Sep 17 00:00:00 2001 From: 2bndy5 <2bndy5@gmail.com> Date: Tue, 1 Mar 2022 09:13:22 -0800 Subject: [PATCH 1/2] convert relative path to absolute Add generated dotfile.dot to gitignore since doxygen 1.9.3 copies the dotfile(s) to XML_OUTPUT Considering the path to conf.py, make a dot file's relative path absolute using the project's XML_OUTPUT. --- .gitignore | 1 + breathe/renderer/sphinxrenderer.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c39faaba..d1598d62 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ com_crashlytics_export_strings.xml # modified by build process examples/doxygen/example.tag +examples/specific/dot_graphs/xml/dotfile.dot diff --git a/breathe/renderer/sphinxrenderer.py b/breathe/renderer/sphinxrenderer.py index 9b891ce3..9269cd9d 100644 --- a/breathe/renderer/sphinxrenderer.py +++ b/breathe/renderer/sphinxrenderer.py @@ -1,3 +1,4 @@ +import os import sphinx from breathe.parser import compound, compoundsuper, DoxygenCompoundParser @@ -2369,11 +2370,22 @@ def visit_docdot(self, node) -> List[Node]: def visit_docdotfile(self, node) -> List[Node]: """Translate node from doxygen's dotfile command to sphinx's graphviz directive.""" dotcode = "" + dot_file_path = node.name # type: str + # Doxygen v1.9.3+ uses a relative path to specify the dot file. + # Previously, Doxygen used an absolute path. + # This relative path is with respect to the XML_OUTPUT path. + # furthermore, Doxygen v1.9.3+ will copy the dot file into the XML_OUTPUT + if not os.path.isabs(dot_file_path): + # use self.project_info.project_path as the XML_OUTPUT path, + # and make it absolute with consideration to the conf.py path + dot_file_path = os.path.abspath( + self.app.confdir + os.sep + self.project_info.project_path() + dot_file_path + ) try: - with open(node.name, encoding="utf-8") as fp: + with open(dot_file_path, encoding="utf-8") as fp: dotcode = fp.read() if not dotcode.rstrip("\n"): - raise RuntimeError("%s found but without any content" % node.name) + raise RuntimeError("%s found but without any content" % dot_file_path) except OSError as exc: # doxygen seems to prevent this from triggering as a non-existant file # generates no XML output for the corresponding `\dotfile` cmd @@ -2382,7 +2394,7 @@ def visit_docdotfile(self, node) -> List[Node]: self.state.document.reporter.warning(exc) graph_node = graphviz() graph_node["code"] = dotcode - graph_node["options"] = {"docname": node.name} + graph_node["options"] = {"docname": dot_file_path} caption = "" if not node.content_ else node.content_[0].getValue() if caption: caption_node = nodes.caption(caption, "") From 625b21172e89b1101963c41ce7a813453dead1c9 Mon Sep 17 00:00:00 2001 From: 2bndy5 <2bndy5@gmail.com> Date: Wed, 2 Mar 2022 12:23:46 -0800 Subject: [PATCH 2/2] compensate for user input XML_OUTPUT Use users' input as root path component if breathe_projects (in conf.py) specifies an absolute path for the project's XML_OUTPUT (not recommended for hosting from a web server). Otherwise, concatenate the path to conf.py with subsequent relative paths to the dot file (resulting in a clean absolute path). --- breathe/renderer/sphinxrenderer.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/breathe/renderer/sphinxrenderer.py b/breathe/renderer/sphinxrenderer.py index 9269cd9d..4d56b79a 100644 --- a/breathe/renderer/sphinxrenderer.py +++ b/breathe/renderer/sphinxrenderer.py @@ -2374,13 +2374,17 @@ def visit_docdotfile(self, node) -> List[Node]: # Doxygen v1.9.3+ uses a relative path to specify the dot file. # Previously, Doxygen used an absolute path. # This relative path is with respect to the XML_OUTPUT path. - # furthermore, Doxygen v1.9.3+ will copy the dot file into the XML_OUTPUT + # Furthermore, Doxygen v1.9.3+ will copy the dot file into the XML_OUTPUT if not os.path.isabs(dot_file_path): - # use self.project_info.project_path as the XML_OUTPUT path, - # and make it absolute with consideration to the conf.py path - dot_file_path = os.path.abspath( - self.app.confdir + os.sep + self.project_info.project_path() + dot_file_path - ) + # Use self.project_info.project_path as the XML_OUTPUT path, and + # make it absolute with consideration to the conf.py path + project_path = self.project_info.project_path() + if os.path.isabs(project_path): + dot_file_path = os.path.abspath(project_path + os.sep + dot_file_path) + else: + dot_file_path = os.path.abspath( + self.app.confdir + os.sep + project_path + os.sep + dot_file_path + ) try: with open(dot_file_path, encoding="utf-8") as fp: dotcode = fp.read()