Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions strictdoc/cli/command_parser_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"reqif-sdoc",
"reqifz-sdoc",
"sdoc",
"doxygen",
"spdx",
]
EXCEL_PARSERS = ["basic"]
Expand Down
13 changes: 13 additions & 0 deletions strictdoc/core/actions/export_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from strictdoc.core.project_config import ProjectConfig
from strictdoc.core.traceability_index import TraceabilityIndex
from strictdoc.core.traceability_index_builder import TraceabilityIndexBuilder
from strictdoc.export.doxygen.doxygen_generator import DoxygenGenerator
from strictdoc.export.html.document_type import DocumentType
from strictdoc.export.html.html_generator import HTMLGenerator
from strictdoc.export.html.html_templates import HTMLTemplates
Expand Down Expand Up @@ -153,6 +154,18 @@ def export(self) -> None:
if "sdoc" in self.project_config.export_formats:
self.export_sdoc()

if "doxygen" in self.project_config.export_formats:
output_doxygen_root = os.path.join(
self.project_config.output_dir, "doxygen"
)
doxygen_generator = DoxygenGenerator(
project_config=self.project_config
)
doxygen_generator.export(
traceability_index=self.traceability_index,
path_to_output_dir=output_doxygen_root,
)

if "spdx" in self.project_config.export_formats:
output_dot_root = os.path.join(
self.project_config.output_dir, "spdx"
Expand Down
63 changes: 63 additions & 0 deletions strictdoc/export/doxygen/doxygen_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
from pathlib import Path

from strictdoc.backend.sdoc.models.document import SDocDocument
from strictdoc.backend.sdoc.models.node import SDocNode
from strictdoc.core.document_iterator import DocumentCachingIterator
from strictdoc.core.project_config import ProjectConfig
from strictdoc.core.traceability_index import TraceabilityIndex
from strictdoc.export.html.renderers.link_renderer import LinkRenderer


class DoxygenGenerator:
def __init__(self, project_config: ProjectConfig):
self.project_config: ProjectConfig = project_config

def export(
self,
*,
traceability_index: TraceabilityIndex,
path_to_output_dir: str,
) -> None:
Path(path_to_output_dir).mkdir(parents=True, exist_ok=True)
output_path = os.path.join(path_to_output_dir, "strictdoc.xml")

link_renderer = LinkRenderer(
root_path="NOT_RELEVANT", static_path="NOT_RELEVANT"
)

def template_node(node_uid: str, path_to_html: str) -> str:
return f"""\
<compound kind="page">
<name>{node_uid}</name>
<filename>html/{path_to_html}</filename>
</compound>
"""

template_all_nodes = ""

assert traceability_index.document_tree is not None
assert traceability_index.document_tree.document_list is not None

document_: SDocDocument
for document_ in traceability_index.document_tree.document_list:
document_iterator = DocumentCachingIterator(document_)

for node in document_iterator.all_content(
print_fragments=False,
print_fragments_from_files=False,
):
if isinstance(node, SDocNode) and node.reserved_uid is not None:
path_to_html = link_renderer.render_node_doxygen_link(node)
template_all_nodes += template_node(
node.reserved_uid, path_to_html
)

template_xml = f"""\
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<tagfile doxygen_version="1.9.8">
{template_all_nodes.rstrip()}
</tagfile>
"""
with open(output_path, "w", encoding="utf8") as file:
file.write(template_xml)
17 changes: 17 additions & 0 deletions strictdoc/export/html/renderers/link_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ def render_node_link(
self.req_link_cache[link_cache_key][node] = requirement_link
return requirement_link

def render_node_doxygen_link(
self,
node: Union[SDocDocument, SDocNode, SDocSection, Anchor],
):
"""
allow_local: used on the DTR screen where we want to ensure that only
full paths are used when jumping to the DOC screen.
"""

assert isinstance(node, (SDocNode, SDocSection, Anchor)), node
local_link = self.render_local_anchor(node)
document_link = (
node.parent_or_including_document.meta.get_html_doc_link()
)
requirement_link = f"{document_link}#{local_link}"
return requirement_link

def render_requirement_link_from_source_file(self, node, source_file):
assert isinstance(node, SDocNode)
assert isinstance(source_file, SourceFile)
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import sys
from enum import Enum
from typing import Optional, Dict
from typing import Dict, Optional

if not hasattr(inspect, "getargspec"):
inspect.getargspec = inspect.getfullargspec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RUN: %expect_exit 2 %strictdoc export --formats=foo %S | filecheck %s --dump-input=fail

CHECK: {{.*}} export: error: argument --formats: invalid choice: 'foo' (choose from 'html', 'html2pdf', 'rst', 'json', 'excel', 'reqif-sdoc', 'reqifz-sdoc', 'sdoc', 'spdx')
CHECK: {{.*}} export: error: argument --formats: invalid choice: 'foo' (choose from 'html', 'html2pdf', 'rst', 'json', 'excel', 'reqif-sdoc', 'reqifz-sdoc', 'sdoc', 'doxygen', 'spdx')
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[DOCUMENT]
TITLE: Hello world doc

[REQUIREMENT]
UID: REQ-2
TITLE: Title #2
STATEMENT: System shall do foo.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[DOCUMENT]
TITLE: Hello world doc

[REQUIREMENT]
UID: REQ-3
TITLE: Title #3
STATEMENT: System shall do foo.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[DOCUMENT]
TITLE: Hello world doc

[REQUIREMENT]
UID: REQ-1
TITLE: Title #1
STATEMENT: System shall do foo.
15 changes: 15 additions & 0 deletions tests/integration/features/doxygen/01_basic_export/strictdoc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<tagfile doxygen_version="1.9.8">
<compound kind="page">
<name>REQ-1</name>
<filename>html/01_basic_export/input1.html#1-REQ-1</filename>
</compound>
<compound kind="page">
<name>REQ-2</name>
<filename>html/01_basic_export/folder/input2.html#1-REQ-2</filename>
</compound>
<compound kind="page">
<name>REQ-3</name>
<filename>html/01_basic_export/folder/subfolder/input3.html#1-REQ-3</filename>
</compound>
</tagfile>
4 changes: 4 additions & 0 deletions tests/integration/features/doxygen/01_basic_export/test.itest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RUN: %strictdoc export %S --formats doxygen --output-dir Output | filecheck %s --dump-input=fail
CHECK: Step 'Export SDoc' took: {{.*}} sec.

RUN: %diff %S/strictdoc.xml %S/Output/doxygen/strictdoc.xml
Loading