You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ak...@apache.org on 2022/07/03 18:13:25 UTC
[buildstream-plugins] 03/04: Fix running track multiple times with cargo plugin
This is an automated email from the ASF dual-hosted git repository.
akitouni pushed a commit to branch abderrahim/cargo-fixes
in repository https://gitbox.apache.org/repos/asf/buildstream-plugins.git
commit cf08d80379a677c4551a875ce20e8744752e31ba
Author: Seppo Yli-Olli <se...@gmail.com>
AuthorDate: Fri Jun 17 22:30:01 2022 +0300
Fix running track multiple times with cargo plugin
Cargo plugin was earlier directly using YAML ref for returning
ref. This is dangerous since BuildStream annotates any dicts
within. Instead, construct ref based on crates.
---
src/buildstream_plugins/sources/cargo.py | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/buildstream_plugins/sources/cargo.py b/src/buildstream_plugins/sources/cargo.py
index 1544960..e5a5933 100644
--- a/src/buildstream_plugins/sources/cargo.py
+++ b/src/buildstream_plugins/sources/cargo.py
@@ -344,10 +344,6 @@ class CargoSource(Source):
# The url before any aliasing
#
self.url = node.get_str("url", "https://static.crates.io/crates")
- # XXX: should we use get_sequence here?
- self.ref = node.get_sequence("ref", None)
- if self.ref is not None:
- self.ref = self.ref.strip_node_info()
self.cargo_lock = node.get_str("cargo-lock", "Cargo.lock")
self.vendor_dir = node.get_str("vendor-dir", "crates")
@@ -356,7 +352,7 @@ class CargoSource(Source):
# Needs to be marked here so that `track` can translate it later.
self.mark_download_url(self.url)
- self.crates = self._parse_crates(self.ref)
+ self.load_ref(node)
def preflight(self):
return
@@ -371,16 +367,15 @@ class CargoSource(Source):
return all(crate.is_cached() for crate in self.crates)
def load_ref(self, node):
- # XXX: this should be get_sequence, and parse_crate should expect nodes
- self.ref = node.get_sequence("ref", None)
- self.crates = self._parse_crates(self.ref)
+ ref = node.get_sequence("ref", None)
+ self._recompute_crates(ref)
def get_ref(self):
return self.ref
def set_ref(self, ref, node):
- node["ref"] = self.ref = ref
- self.crates = self._parse_crates(self.ref)
+ node["ref"] = ref
+ self._recompute_crates(ref)
def track(self, *, previous_sources_dir):
new_ref = []
@@ -450,6 +445,19 @@ class CargoSource(Source):
# Private helpers #
########################################################
+ def _recompute_crates(self, ref):
+ self.crates = self._parse_crates(ref)
+ if not self.crates:
+ self.ref = None
+ else:
+ self.ref = [
+ {
+ "name": crate.name,
+ "version": crate.version,
+ "sha": crate.sha
+ } for crate in self.crates
+ ]
+
# _parse_crates():
#
# Generates a list of crates based on the passed ref