[rtems-central commit] items: Add create_unique_link()

Sebastian Huber sebh at rtems.org
Fri Sep 2 12:49:20 UTC 2022


Module:    rtems-central
Branch:    master
Commit:    d848122fb572673c5f91ea1e32beb527e9f52bb9
Changeset: http://git.rtems.org/rtems-central/commit/?id=d848122fb572673c5f91ea1e32beb527e9f52bb9

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Sep  1 09:47:33 2022 +0200

items: Add create_unique_link()

---

 rtemsspec/items.py      | 13 +++++++++++++
 rtemsspec/rtems.py      | 11 ++++++-----
 rtemsspec/validation.py |  9 ++++-----
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index c0815256..8dbab199 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -430,6 +430,19 @@ class Item:
         self._data = self._cache.load_data(self.file, self._uid)
 
 
+def create_unique_link(child: Item, parent: Item, data: Any) -> None:
+    """
+    Creates a unique link from the child to the parent item and vice versa
+    using the data for the link.
+    """
+    for item in parent.children(data["role"]):
+        if item.uid == child.uid:
+            break
+    else:
+        parent.add_link_to_child(Link(child, data))
+        child.add_link_to_parent(Link(parent, data))
+
+
 class ItemTemplate(string.Template):
     """ String template for item mapper identifiers. """
     idpattern = "[a-zA-Z0-9._/-]+(:[a-zA-Z0-9._/-]+)?(:[^${}]*)?"
diff --git a/rtemsspec/rtems.py b/rtemsspec/rtems.py
index 97e9da82..3efa82eb 100644
--- a/rtemsspec/rtems.py
+++ b/rtemsspec/rtems.py
@@ -24,7 +24,9 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-from rtemsspec.items import Item, ItemCache, Link
+from typing import Any
+
+from rtemsspec.items import create_unique_link, Item, ItemCache
 
 _NOT_PRE_QUALIFIED = set([
     "/acfg/constraint/option-not-pre-qualified",
@@ -40,10 +42,9 @@ def is_pre_qualified(item: Item) -> bool:
             _NOT_PRE_QUALIFIED))
 
 
-def _add_link(item_cache: ItemCache, child: Item, link: Link) -> None:
-    parent = item_cache[child.to_abs_uid(link["uid"])]
-    parent.add_link_to_child(Link(child, link))
-    child.add_link_to_parent(Link(parent, link))
+def _add_link(item_cache: ItemCache, child: Item, data: Any) -> None:
+    parent = item_cache[child.to_abs_uid(data["uid"])]
+    create_unique_link(child, parent, data)
 
 
 def augment_with_test_links(item_cache: ItemCache) -> None:
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index fce22ad1..ceb326e8 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -36,8 +36,8 @@ from rtemsspec.content import CContent, CInclude, enabled_by_to_exp, \
     ExpressionMapper, GenericContent, get_integer_type, get_value_params, \
     get_value_plural, get_value_doxygen_group, get_value_doxygen_function, \
     to_camel_case
-from rtemsspec.items import Item, ItemCache, \
-    ItemGetValueContext, ItemMapper, Link
+from rtemsspec.items import create_unique_link, Item, ItemCache, \
+    ItemGetValueContext, ItemMapper
 from rtemsspec.transitionmap import TransitionMap
 
 _CaseToSuite = Dict[str, List["_TestItem"]]
@@ -1213,6 +1213,5 @@ def augment_with_test_case_links(item_cache: ItemCache) -> None:
         child = item_cache[test_case_uid]
         for test_suite in test_suites:
             parent = item_cache[test_suite.item.uid]
-            link = {"role": "test-case", "uid": parent.uid}
-            parent.add_link_to_child(Link(child, link))
-            child.add_link_to_parent(Link(parent, link))
+            data = {"role": "test-case", "uid": parent.uid}
+            create_unique_link(child, parent, data)



More information about the vc mailing list