feat(tvix/derivation): make input_sources a BTreeSet

These need to be sorted anyways, so let's use the correct data structure for it.

Change-Id: I009c9989d7647dc1df716170f3680c981db6e4b2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7846
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2023-01-16 15:25:08 +01:00 committed by clbot
parent f6b4abac35
commit 95cad95b93
3 changed files with 5 additions and 14 deletions

View file

@ -22,7 +22,7 @@ pub struct Derivation {
pub input_derivations: BTreeMap<String, BTreeSet<String>>, pub input_derivations: BTreeMap<String, BTreeSet<String>>,
#[serde(rename = "inputSrcs")] #[serde(rename = "inputSrcs")]
pub input_sources: Vec<String>, pub input_sources: BTreeSet<String>,
pub outputs: BTreeMap<String, Output>, pub outputs: BTreeMap<String, Output>,
@ -111,15 +111,14 @@ impl Derivation {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
// collect the list of paths from input_sources and input_derivations // collect the list of paths from input_sources and input_derivations
// into a sorted list, and join them by : // into a (sorted, guaranteed by BTreeSet) list, and join them by :
hasher.update(write::TEXT_COLON); hasher.update(write::TEXT_COLON);
let concat_inputs: Vec<String> = { let concat_inputs: BTreeSet<String> = {
let mut inputs = self.input_sources.clone(); let mut inputs = self.input_sources.clone();
let input_derivation_keys: Vec<String> = let input_derivation_keys: Vec<String> =
self.input_derivations.keys().cloned().collect(); self.input_derivations.keys().cloned().collect();
inputs.extend(input_derivation_keys); inputs.extend(input_derivation_keys);
inputs.sort();
inputs inputs
}; };

View file

@ -61,16 +61,8 @@ impl Derivation {
} }
// Validate all input_sources // Validate all input_sources
for (i, input_source) in self.input_sources.iter().enumerate() { for input_source in self.input_sources.iter() {
StorePath::from_absolute_path(input_source)?; StorePath::from_absolute_path(input_source)?;
if i > 0 && self.input_sources[i - 1] >= *input_source {
bail!(
"invalid input source order: {} < {}",
input_source,
self.input_sources[i - 1],
);
}
} }
// validate platform // validate platform

View file

@ -118,7 +118,7 @@ pub fn write_input_derivations(
pub fn write_input_sources( pub fn write_input_sources(
writer: &mut impl Write, writer: &mut impl Write,
input_sources: &[String], input_sources: &BTreeSet<String>,
) -> Result<(), fmt::Error> { ) -> Result<(), fmt::Error> {
writer.write_char(COMMA)?; writer.write_char(COMMA)?;