Implement maintaining object relationship graph

For each object maintain parent-child relationship graph, i.e. list of
parent objects ('parents' property) and list of children objects ('children'
property).

Objects without parent(s) are objects specified in init manifest.
Objects without children are object of types that do not reuse other types.
This commit is contained in:
Darko Poljak 2021-03-21 18:10:06 +01:00
parent 10ca1c12fd
commit 7a0b697f4c
3 changed files with 43 additions and 0 deletions

View File

@ -247,6 +247,13 @@ class CdistObject:
lambda obj: os.path.join(obj.absolute_path, 'typeorder'))
typeorder_dep = fsproperty.FileListProperty(
lambda obj: os.path.join(obj.absolute_path, 'typeorder_dep'))
# objects without parents are objects specified in init manifest
parents = fsproperty.FileListProperty(
lambda obj: os.path.join(obj.absolute_path, 'parents'))
# objects without children are object of types that do not reuse other
# types
children = fsproperty.FileListProperty(
lambda obj: os.path.join(obj.absolute_path, 'children'))
def cleanup(self):
try:

View File

@ -106,6 +106,7 @@ class Emulator:
self.save_stdin()
self.record_requirements()
self.record_auto_requirements()
self.record_parent_child_relationships()
self.log.trace("Finished %s %s" % (
self.cdist_object.path, self.parameters))
@ -420,3 +421,21 @@ class Emulator:
self.log.debug("Recording autorequirement %s for %s",
current_object.name, parent.name)
parent.autorequire.append(current_object.name)
def record_parent_child_relationships(self):
# __object_name is the name of the object whose type manifest is
# currently executed
__object_name = self.env.get('__object_name', None)
if __object_name:
# The object whose type manifest is currently run
parent = self.cdist_object.object_from_name(__object_name)
# The object currently being defined
current_object = self.cdist_object
if current_object.name not in parent.children:
self.log.debug("Recording child %s for %s",
current_object.name, parent.name)
parent.children.append(current_object.name)
if parent.name not in current_object.parents:
self.log.debug("Recording parent %s for %s",
parent.name, current_object.name)
current_object.parents.append(parent.name)

View File

@ -61,6 +61,14 @@ Object cache overview
~~~~~~~~~~~~~~~~~~~~~
Each object under :strong:`object` directory has its own structure.
autorequire
file containing a list of object auto requirements
children
file containing a list of object children, i.e. objects of types that this
type reuses (along with 'parents' it is used for maintaining parent-child
relationship graph)
code-local
code generated from gencode-local, present only if something is
generated
@ -80,6 +88,15 @@ parameter
directory containing type parameter named files containing parameter
values
parents
file containing a list of object parents, i.e. objects of types that reuse
this type (along with 'children' it is used for maintaining parent-child
relationship graph); objects without parents are objects specified in init
manifest
require
file containing a list of object requirements
source
this type's source (init manifest)