Skip to content

Commit fc6e5d5

Browse files
Update cargo source to use source provenance
1 parent d2bf8b7 commit fc6e5d5

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/buildstream_plugins/sources/cargo.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
*version_type*, for which it reports the checksum of the archive as the *version*.
7575
7676
The versions extracted from the Cargo.lock at tracking time are used to report the *guess_version*.
77+
78+
Additional source info can be specified using the `provenance` field for each referenced crate as per
79+
`built-in source provenance documentation
80+
<https://docs.buildstream.build/master/buildstream.source.html#built-in-functionality>`_.
7781
"""
7882

7983
import json
@@ -125,13 +129,14 @@
125129
# sha (str|None): The sha256 checksum of the downloaded crate
126130
#
127131
class Crate(SourceFetcher):
128-
def __init__(self, cargo, name, version, sha=None):
132+
def __init__(self, cargo, name, version, sha=None, provenance=None):
129133
super().__init__()
130134

131135
self.cargo = cargo
132136
self.name = name
133137
self.version = str(version)
134138
self.sha = sha
139+
self.provenance = provenance
135140
self.mark_download_url(cargo.url)
136141

137142
########################################################
@@ -159,7 +164,12 @@ def fetch(self, alias_override=None, **kwargs):
159164
def get_source_info(self):
160165
url, _ = self._get_url()
161166
return self.cargo.create_source_info(
162-
url, SourceInfoMedium.REMOTE_FILE, SourceVersionType.SHA256, self.sha, version_guess=self.version
167+
url,
168+
SourceInfoMedium.REMOTE_FILE,
169+
SourceVersionType.SHA256,
170+
self.sha,
171+
version_guess=self.version,
172+
provenance_node=self.provenance,
163173
)
164174

165175
########################################################
@@ -368,6 +378,8 @@ class CargoSource(Source):
368378
# We need the Cargo.lock file to construct our ref at track time
369379
BST_REQUIRES_PREVIOUS_SOURCES_TRACK = True
370380

381+
BST_CUSTOM_SOURCE_PROVENANCE = True
382+
371383
########################################################
372384
# Plugin/Source API method implementations #
373385
########################################################
@@ -513,6 +525,7 @@ def _parse_crates(self, refs):
513525
crate.get_str("name"),
514526
crate.get_str("version"),
515527
sha=crate.get_str("sha", None),
528+
provenance=crate.get_mapping("provenance", None),
516529
)
517530
for crate in refs
518531
]

0 commit comments

Comments
 (0)