Skip to content

Commit 6bc0a07

Browse files
author
Adrien Plazas
committed
_frontend/widget: Add artifact-cas-digest show format
This adds the artifact-cas-digest format string to the show command, allowing to show the CAS digest of the built artifact.
1 parent ba70052 commit 6bc0a07

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
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+
%{artifact-cas-digest} The CAS digest of the built artifact
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+
%{artifact-cas-digest} The CAS digest of the built artifact
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+
artifact_cas_digest_match = re.search(r"%(\{(artifact-cas-digest)[^%]*?\})", format_)
643+
need_state = bool(state_match or key_match or full_key_match or artifact_cas_digest_match)
642644

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

src/buildstream/_frontend/widget.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,21 @@ 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+
# Artifact CAS Digest
441+
if "%{artifact-cas-digest" in format_:
442+
artifact = element._get_artifact()
443+
if not artifact.query_cache():
444+
artifact = None
445+
if artifact is not None:
446+
artifact_files = artifact.get_files()
447+
# We call the private CasBasedDirectory._get_digest() for
448+
# the moment, we should make it public on Directory.
449+
artifact_digest = artifact_files._get_digest()
450+
formated_artifact_digest = "{}/{}".format(artifact_digest.hash, artifact_digest.size_bytes)
451+
line = p.fmt_subst(line, "artifact-cas-digest", formated_artifact_digest)
452+
else:
453+
line = p.fmt_subst(line, "artifact-cas-digest", "(no artifact CAS digest)", fg="yellow")
454+
440455
report += line + "\n"
441456

442457
return report.rstrip("\n")

tests/frontend/show.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,9 @@ def setup_test():
438438
("%{deps}", "- import-dev.bst\n- import-links.bst\n- import-bin.bst"),
439439
("%{build-deps}", "- import-dev.bst\n- import-links.bst"),
440440
("%{runtime-deps}", "- import-links.bst\n- import-bin.bst"),
441+
("%{artifact-cas-digest}", "(no artifact CAS digest)"),
441442
],
442-
ids=["deps", "build-deps", "runtime-deps"],
443+
ids=["deps", "build-deps", "runtime-deps", "artifact-cas-digest"],
443444
)
444445
def test_format_deps(cli, datafiles, dep_kind, expected_deps):
445446
project = str(datafiles)

0 commit comments

Comments
 (0)