Skip to content

Commit 541cc9e

Browse files
author
Adrien Plazas
committed
_frontend/widget: Allow showing the CAS digest
This adds the cas-digest format string to the show command.
1 parent ba70052 commit 541cc9e

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

man/bst-show.1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Show elements in the pipeline
4545
%{deps} A list of all dependencies
4646
%{build-deps} A list of build dependencies
4747
%{runtime-deps} A list of runtime dependencies
48+
%{cas-digest} The CAS digest
4849
.PP
4950
The value of the %{symbol} without the leading '%' character is understood
5051
as a pythonic formatting string, so python formatting features apply,

src/buildstream/_frontend/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ def show(app, elements, deps, except_, order, format_):
613613
%{deps} A list of all dependencies
614614
%{build-deps} A list of build dependencies
615615
%{runtime-deps} A list of runtime dependencies
616+
%{cas-digest} The CAS digest
616617
617618
The value of the %{symbol} without the leading '%' character is understood
618619
as a pythonic formatting string, so python formatting features apply,
@@ -638,7 +639,8 @@ def show(app, elements, deps, except_, order, format_):
638639
state_match = re.search(r"%(\{(state)[^%]*?\})", format_)
639640
key_match = re.search(r"%(\{(key)[^%]*?\})", format_)
640641
full_key_match = re.search(r"%(\{(full-key)[^%]*?\})", format_)
641-
need_state = bool(state_match or key_match or full_key_match)
642+
cas_digest_match = re.search(r"%(\{(cas-digest)[^%]*?\})", format_)
643+
need_state = bool(state_match or key_match or full_key_match or cas_digest_match)
642644

643645
if not elements:
644646
elements = app.project.get_default_targets()

src/buildstream/_frontend/widget.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ def show_pipeline(self, dependencies, format_):
437437
runtime_deps = [e._get_full_name() for e in element._dependencies(_Scope.RUN, recurse=False)]
438438
line = p.fmt_subst(line, "runtime-deps", _yaml.roundtrip_dump_string(runtime_deps).rstrip("\n"))
439439

440+
# CAS Digest
441+
if "%{cas-digest" in format_:
442+
cas_digest = element._get_cas_digest()
443+
if cas_digest is not None:
444+
line = p.fmt_subst(line, "cas-digest", cas_digest)
445+
else:
446+
line = p.fmt_subst(line, "cas-digest", "(no CAS digest)", fg="yellow")
447+
440448
report += line + "\n"
441449

442450
return report.rstrip("\n")

src/buildstream/element.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,22 @@ def _get_cache_key(self, strength=_KeyStrength.STRONG):
12721272
else:
12731273
return self.__weak_cache_key
12741274

1275+
# _get_cas_digest():
1276+
#
1277+
# Returns the CAS digest
1278+
#
1279+
# Returns:
1280+
# (str|None): The CAS digest for this Element, or None
1281+
#
1282+
# None is returned if no CAS artifact is available for this element.
1283+
#
1284+
def _get_cas_digest(self):
1285+
if self.__artifact is None:
1286+
return None
1287+
if not self.__artifact.query_cache():
1288+
return None
1289+
return self.__artifact.get_files().get_cas_digest()
1290+
12751291
# _can_query_cache():
12761292
#
12771293
# Returns whether the cache key required for cache queries is available.

src/buildstream/storage/_casbaseddirectory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ def is_dir_in(entry: _IndexEntry, directory: CasBasedDirectory) -> bool:
529529

530530
self.__invalidate_digest()
531531

532+
def get_cas_digest(self):
533+
digest = self._get_digest()
534+
return "{}/{}".format(digest.hash, digest.size_bytes)
535+
532536
#############################################################
533537
# Private methods #
534538
#############################################################

0 commit comments

Comments
 (0)