Skip to content

Commit 6bc1da1

Browse files
authored
Merge pull request #2527 from haxtibal/tdmg/source_node_sanity
Add sanity checks for source_nodes configuration
2 parents 9bcd798 + 672710f commit 6bc1da1

File tree

13 files changed

+190
-1
lines changed

13 files changed

+190
-1
lines changed

docs/strictdoc_01_user_guide.sdoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,6 +2987,14 @@ To enable SDoc node parsing, the corresponding source file must be registered in
29872987

29882988
.. code-block::
29892989

2990+
features = [
2991+
"REQUIREMENT_TO_SOURCE_TRACEABILITY",
2992+
"SOURCE_FILE_LANGUAGE_PARSERS",
2993+
]
2994+
2995+
# if custom include_source_paths are set, it must include the corresponding source file
2996+
include_source_paths = ["tests/**"]
2997+
29902998
source_nodes = [
29912999
{ "tests/" = { uid = "TEST_DOC", node_type = "TEST_SPEC" } }
29923000
]

strictdoc/core/file_traceability_index.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ def create_folder_section(
593593

594594
section_cache = {}
595595
source_nodes_config: List[Dict[str, str]] = project_config.source_nodes
596+
unused_source_node_paths = {
597+
config_entry_["path"] for config_entry_ in source_nodes_config
598+
}
596599
for (
597600
path_to_source_file_,
598601
traceability_info_,
@@ -604,8 +607,10 @@ def create_folder_section(
604607
continue
605608

606609
for config_entry_ in source_nodes_config:
607-
if path_to_source_file_.startswith(config_entry_["path"]):
610+
config_entry_path = config_entry_["path"]
611+
if path_to_source_file_.startswith(config_entry_path):
608612
relevant_source_node_entry = config_entry_
613+
unused_source_node_paths.discard(config_entry_path)
609614
break
610615
else:
611616
continue
@@ -723,6 +728,13 @@ def create_folder_section(
723728
rhs_node=source_sdoc_node,
724729
)
725730

731+
# Warn if source_node was not matched by any include_source_paths, it indicates misconfiguration
732+
for unused_source_node_path in unused_source_node_paths:
733+
print( # noqa: T201
734+
f"warning: source_node path {unused_source_node_path} doesn't match any source file. "
735+
"Hint: Check include_source_paths."
736+
)
737+
726738
# Iterate over all generated documents to calculate all node levels.
727739
for document_ in documents_with_generated_content:
728740
document_iterator = DocumentCachingIterator(document_)

strictdoc/core/project_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,14 @@ def _load_from_dictionary(
749749

750750
if "source_nodes" in project_content:
751751
source_nodes_config = project_content["source_nodes"]
752+
if len(source_nodes_config) > 0 and not {
753+
ProjectFeature.REQUIREMENT_TO_SOURCE_TRACEABILITY,
754+
ProjectFeature.SOURCE_FILE_LANGUAGE_PARSERS,
755+
}.issubset(project_features):
756+
print( # noqa: T201
757+
"warning: defining source_nodes without enabling REQUIREMENT_TO_SOURCE_TRACEABILITY and "
758+
"SOURCE_FILE_LANGUAGE_PARSERS has no effect"
759+
)
752760
assert isinstance(source_nodes_config, list)
753761
for item_ in source_nodes_config:
754762
source_node_path = next(iter(item_))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[DOCUMENT]
2+
TITLE: Hello world doc
3+
4+
[REQUIREMENT]
5+
UID: REQ-1
6+
TITLE: Requirement Title
7+
STATEMENT: Requirement Statement
8+
9+
[REQUIREMENT]
10+
UID: REQ-2
11+
TITLE: Requirement Title #2
12+
STATEMENT: Requirement Statement #2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
3+
/**
4+
* Some text.
5+
*
6+
* @relation(REQ-1, scope=function)
7+
*
8+
* INTENTION: Ensure alls steps are taken to make foo ready.
9+
*/
10+
void setup_foo(void) {
11+
print("please setup foo manually\n");
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[DOCUMENT]
2+
MID: c2d4542d5f1741c88dfcb4f68ad7dcbd
3+
TITLE: Source Code
4+
UID: SRC_DOC
5+
6+
[GRAMMAR]
7+
ELEMENTS:
8+
- TAG: SECTION
9+
PROPERTIES:
10+
IS_COMPOSITE: True
11+
FIELDS:
12+
- TITLE: UID
13+
TYPE: String
14+
REQUIRED: False
15+
- TITLE: TITLE
16+
TYPE: String
17+
REQUIRED: True
18+
- TAG: SRC_SPEC
19+
PROPERTIES:
20+
VIEW_STYLE: Narrative
21+
FIELDS:
22+
- TITLE: UID
23+
TYPE: String
24+
REQUIRED: False
25+
- TITLE: TITLE
26+
TYPE: String
27+
REQUIRED: True
28+
- TITLE: INTENTION
29+
TYPE: String
30+
REQUIRED: False
31+
RELATIONS:
32+
- TYPE: Parent
33+
- TYPE: File
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
3+
features = []
4+
5+
source_nodes = [
6+
{ "src/" = { uid = "SRC_DOC", node_type = "SRC_SPEC" } }
7+
]
8+
9+
exclude_source_paths = [
10+
"src.itest"
11+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# @relation(SDOC-SRS-141, scope=file)
3+
#
4+
# Using source_nodes depends on having REQUIREMENT_TO_SOURCE_TRACEABILITY
5+
# and SOURCE_FILE_LANGUAGE_PARSERS enabled. Warn if not enabled by configuration.
6+
#
7+
8+
RUN: %expect_exit 0 %strictdoc export %S --output-dir %T | filecheck %s --dump-input=fail
9+
CHECK: warning: defining source_nodes without enabling REQUIREMENT_TO_SOURCE_TRACEABILITY and SOURCE_FILE_LANGUAGE_PARSERS has no effect
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[DOCUMENT]
2+
TITLE: Hello world doc
3+
4+
[REQUIREMENT]
5+
UID: REQ-1
6+
TITLE: Requirement Title
7+
STATEMENT: Requirement Statement
8+
9+
[REQUIREMENT]
10+
UID: REQ-2
11+
TITLE: Requirement Title #2
12+
STATEMENT: Requirement Statement #2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
3+
/**
4+
* Some text.
5+
*
6+
* @relation(REQ-1, scope=function)
7+
*
8+
* INTENTION: Ensure alls steps are taken to make foo ready.
9+
*/
10+
void setup_foo(void) {
11+
print("please setup foo manually\n");
12+
}

0 commit comments

Comments
 (0)