summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan.vanberkom@codethink.co.uk>2020-08-06 19:51:52 +0900
committerbst-marge-bot <marge-bot@buildstream.build>2020-08-10 08:33:55 +0000
commitcbc592b555212d49e1363a4e84d98551d4bf6826 (patch)
tree8a5d64a80c7ff08daad3b73a2dc492b486e80a55
parent1e0aaf4a97ee7e19563bc3fbf323e7d23c4f5aac (diff)
downloadbuildstream-cbc592b555212d49e1363a4e84d98551d4bf6826.tar.gz
_project.py, _loader/loadcontext.py: Added Project.loaded_projects()
This adds a new _ProjectInformation type to types.py which is returned by the new Project.loaded_projects() API, supported by a new internal LoaderContext.loaded_projects() function. This allows the frontend some helpful information to print about the loaded projects in the session heading.
-rw-r--r--src/buildstream/_loader/loadcontext.py27
-rw-r--r--src/buildstream/_project.py17
-rw-r--r--src/buildstream/types.py18
3 files changed, 62 insertions, 0 deletions
diff --git a/src/buildstream/_loader/loadcontext.py b/src/buildstream/_loader/loadcontext.py
index 6183a192b..4e6c9bca6 100644
--- a/src/buildstream/_loader/loadcontext.py
+++ b/src/buildstream/_loader/loadcontext.py
@@ -19,6 +19,7 @@
from .._exceptions import LoadError
from ..exceptions import LoadErrorReason
+from ..types import _ProjectInformation
# ProjectLoaders()
@@ -74,6 +75,21 @@ class ProjectLoaders:
elif primary and duplicates:
self._raise_conflict(duplicates, internal)
+ # loaded_projects()
+ #
+ # A generator which yeilds all of the instances
+ # of this loaded project.
+ #
+ # Yields:
+ # (_ProjectInformation): A descriptive project information object
+ #
+ def loaded_projects(self):
+ for loader in self._collect:
+ duplicating, internalizing = self._search_project_relationships(loader)
+ yield _ProjectInformation(
+ loader.project, loader.provenance, [str(l) for l in duplicating], [str(l) for l in internalizing]
+ )
+
# _search_project_relationships()
#
# Searches this loader's ancestry for projects which mark this
@@ -241,3 +257,14 @@ class LoadContext:
self._loaders[project.name] = project_loaders
project_loaders.register_loader(loader)
+
+ # loaded_projects()
+ #
+ # A generator which yeilds all of the loaded projects
+ #
+ # Yields:
+ # (_ProjectInformation): A descriptive project information object
+ #
+ def loaded_projects(self):
+ for _, project_loaders in self._loaders.items():
+ yield from project_loaders.loaded_projects()
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 3180165bd..3562ea5d4 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -622,6 +622,23 @@ class Project:
return False
+ # loaded_projects()
+ #
+ # A generator which yields all the projects in context of a loaded
+ # pipeline, including the self project.
+ #
+ # Projects will be yielded in the order in which they were loaded
+ # for the current session's pipeline.
+ #
+ # This is used by the frontend to print information about all the
+ # loaded projects.
+ #
+ # Yields:
+ # (_ProjectInformation): A descriptive project information object
+ #
+ def loaded_projects(self):
+ yield from self.load_context.loaded_projects()
+
########################################################
# Private Methods #
########################################################
diff --git a/src/buildstream/types.py b/src/buildstream/types.py
index 3d97fc7b9..cf76defbd 100644
--- a/src/buildstream/types.py
+++ b/src/buildstream/types.py
@@ -226,6 +226,24 @@ class _PipelineSelection(FastEnum):
return str(self.value)
+# _ProjectInformation()
+#
+# A descriptive object about a project.
+#
+# Args:
+# project (Project): The project instance
+# provenance (ProvenanceInformation): The provenance information, if any
+# duplicates (list): List of project descriptions which declared this project as a duplicate
+# internal (list): List of project descriptions which declared this project as internal
+#
+class _ProjectInformation:
+ def __init__(self, project, provenance, duplicates, internal):
+ self.project = project
+ self.provenance = provenance
+ self.duplicates = duplicates
+ self.internal = internal
+
+
########################################
# Type aliases #
########################################