This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tristan/bst-show-description
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 3832dde6d4835f78334e733bad753ff104a8e42d
Author: Tristan van Berkom <[email protected]>
AuthorDate: Tue Jun 18 14:11:16 2024 +0800

    Support %{description} in bst show commands
---
 src/buildstream/_frontend/cli.py        | 1 +
 src/buildstream/_frontend/widget.py     | 1 +
 src/buildstream/_loader/loadelement.pyx | 2 ++
 src/buildstream/_loader/types.py        | 1 +
 src/buildstream/element.py              | 1 +
 5 files changed, 6 insertions(+)

diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py
index 7e68a588d..ac19005c3 100644
--- a/src/buildstream/_frontend/cli.py
+++ b/src/buildstream/_frontend/cli.py
@@ -600,6 +600,7 @@ def show(app, elements, deps, except_, order, format_):
 
     \b
         %{name}           The element name
+        %{description}    The element description (Since: 2.2)
         %{key}            The abbreviated cache key (if all sources are 
consistent)
         %{full-key}       The full cache key (if all sources are consistent)
         %{state}          cached, buildable, waiting, inconsistent or junction
diff --git a/src/buildstream/_frontend/widget.py 
b/src/buildstream/_frontend/widget.py
index e6d22fcb5..96c0f7f1f 100644
--- a/src/buildstream/_frontend/widget.py
+++ b/src/buildstream/_frontend/widget.py
@@ -354,6 +354,7 @@ class LogLine(Widget):
             line = p.fmt_subst(line, "name", element._get_full_name(), 
fg="blue", bold=True)
             line = p.fmt_subst(line, "key", key.brief, fg="yellow", 
dim=dim_keys)
             line = p.fmt_subst(line, "full-key", key.full, fg="yellow", 
dim=dim_keys)
+            line = p.fmt_subst(line, "description", element._description, 
fg="yellow", dim=dim_keys)
 
             try:
                 if not element._has_all_sources_resolved():
diff --git a/src/buildstream/_loader/loadelement.pyx 
b/src/buildstream/_loader/loadelement.pyx
index b21502844..319bb595d 100644
--- a/src/buildstream/_loader/loadelement.pyx
+++ b/src/buildstream/_loader/loadelement.pyx
@@ -227,6 +227,7 @@ cdef class LoadElement:
     cdef readonly MappingNode node
     cdef readonly str name
     cdef readonly str full_name
+    cdef readonly str description
     cdef readonly str kind
     cdef int node_id
     cdef readonly bint first_pass
@@ -272,6 +273,7 @@ cdef class LoadElement:
         self.node.validate_keys(_valid_element_keys)
 
         self.kind = node.get_str(Symbol.KIND, default=None)
+        self.description = node.get_str(Symbol.DESCRIPTION, default=None)
         self.first_pass = self.kind in ("junction", "link")
 
         #
diff --git a/src/buildstream/_loader/types.py b/src/buildstream/_loader/types.py
index e9618092d..6f6829bd2 100644
--- a/src/buildstream/_loader/types.py
+++ b/src/buildstream/_loader/types.py
@@ -22,6 +22,7 @@
 class Symbol:
     FILENAME = "filename"
     KIND = "kind"
+    DESCRIPTION = "description"
     DEPENDS = "depends"
     BUILD_DEPENDS = "build-depends"
     RUNTIME_DEPENDS = "runtime-depends"
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index f70a3fcb9..e24abe090 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -248,6 +248,7 @@ class Element(Plugin):
         #
         self._depth = None  # Depth of Element in its current dependency graph
         self._overlap_collector = None  # type: Optional[OverlapCollector]
+        self._description = load_element.description  # type: str
 
         #
         # Private instance properties

Reply via email to