Skip to content

Commit

Permalink
_frontend/widget: Allow showing the CAS digest
Browse files Browse the repository at this point in the history
This adds the cas-digest format string to the show command.
  • Loading branch information
Adrien Plazas committed Feb 20, 2025
1 parent ba70052 commit 541cc9e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions man/bst-show.1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Show elements in the pipeline
%{deps} A list of all dependencies
%{build-deps} A list of build dependencies
%{runtime-deps} A list of runtime dependencies
%{cas-digest} The CAS digest
.PP
The value of the %{symbol} without the leading '%' character is understood
as a pythonic formatting string, so python formatting features apply,
Expand Down
4 changes: 3 additions & 1 deletion src/buildstream/_frontend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ def show(app, elements, deps, except_, order, format_):
%{deps} A list of all dependencies
%{build-deps} A list of build dependencies
%{runtime-deps} A list of runtime dependencies
%{cas-digest} The CAS digest
The value of the %{symbol} without the leading '%' character is understood
as a pythonic formatting string, so python formatting features apply,
Expand All @@ -638,7 +639,8 @@ def show(app, elements, deps, except_, order, format_):
state_match = re.search(r"%(\{(state)[^%]*?\})", format_)
key_match = re.search(r"%(\{(key)[^%]*?\})", format_)
full_key_match = re.search(r"%(\{(full-key)[^%]*?\})", format_)
need_state = bool(state_match or key_match or full_key_match)
cas_digest_match = re.search(r"%(\{(cas-digest)[^%]*?\})", format_)
need_state = bool(state_match or key_match or full_key_match or cas_digest_match)

if not elements:
elements = app.project.get_default_targets()
Expand Down
8 changes: 8 additions & 0 deletions src/buildstream/_frontend/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ def show_pipeline(self, dependencies, format_):
runtime_deps = [e._get_full_name() for e in element._dependencies(_Scope.RUN, recurse=False)]
line = p.fmt_subst(line, "runtime-deps", _yaml.roundtrip_dump_string(runtime_deps).rstrip("\n"))

# CAS Digest
if "%{cas-digest" in format_:
cas_digest = element._get_cas_digest()
if cas_digest is not None:
line = p.fmt_subst(line, "cas-digest", cas_digest)
else:
line = p.fmt_subst(line, "cas-digest", "(no CAS digest)", fg="yellow")

report += line + "\n"

return report.rstrip("\n")
Expand Down
16 changes: 16 additions & 0 deletions src/buildstream/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,22 @@ def _get_cache_key(self, strength=_KeyStrength.STRONG):
else:
return self.__weak_cache_key

# _get_cas_digest():
#
# Returns the CAS digest
#
# Returns:
# (str|None): The CAS digest for this Element, or None
#
# None is returned if no CAS artifact is available for this element.
#
def _get_cas_digest(self):
if self.__artifact is None:
return None
if not self.__artifact.query_cache():
return None
return self.__artifact.get_files().get_cas_digest()

# _can_query_cache():
#
# Returns whether the cache key required for cache queries is available.
Expand Down
4 changes: 4 additions & 0 deletions src/buildstream/storage/_casbaseddirectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ def is_dir_in(entry: _IndexEntry, directory: CasBasedDirectory) -> bool:

self.__invalidate_digest()

def get_cas_digest(self):
digest = self._get_digest()
return "{}/{}".format(digest.hash, digest.size_bytes)

#############################################################
# Private methods #
#############################################################
Expand Down

0 comments on commit 541cc9e

Please sign in to comment.