diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-11-03 21:08:23 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-11-03 22:21:53 +0100 |
commit | 550295e0906e7ea874b3b2c35fb17519b429369c (patch) | |
tree | 72b22a201526ceba47a69e6ade09fe2f5cd1dd68 | |
parent | ed31f842d6fc892120117b22d9bfcc13745e16bc (diff) | |
download | rebel-550295e0906e7ea874b3b2c35fb17519b429369c.tar rebel-550295e0906e7ea874b3b2c35fb17519b429369c.zip |
driver: store multiple recipe with the same ID, select highest version number
We are using the Debian version number scheme for comparision.
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | crates/driver/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/driver/src/context.rs | 22 | ||||
-rw-r--r-- | crates/driver/src/recipe.rs | 6 |
4 files changed, 29 insertions, 7 deletions
@@ -173,6 +173,12 @@ dependencies = [ ] [[package]] +name = "deb-version" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b390250ca2b6862735ef39a7b37b0266a8d5cd9d1e579260c95b1dc27761d6ad" + +[[package]] name = "digest" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -499,6 +505,7 @@ name = "rebel" version = "0.1.0" dependencies = [ "clap", + "deb-version", "enum-kinds", "handlebars", "indoc", diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index 215c451..36afe9f 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -12,6 +12,7 @@ common = { path = "../common", package = "rebel-common" } runner = { path = "../runner", package = "rebel-runner" } clap = "3.0.0-beta.2" +deb-version = "0.1.1" enum-kinds = "0.5.1" handlebars = "4.1.3" indoc = "1.0.3" diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs index c3ca79f..ccb8581 100644 --- a/crates/driver/src/context.rs +++ b/crates/driver/src/context.rs @@ -140,13 +140,13 @@ fn platform_relation(args: &TaskArgs, from: &str, to: &str) -> Option<PlatformRe pub struct Context { platforms: HashMap<String, Arg>, globals: TaskArgs, - tasks: HashMap<TaskID, TaskDef>, + tasks: HashMap<TaskID, Vec<TaskDef>>, rootfs: (ArchiveHash, String), rootfs_tasks: HashMap<TaskID, TaskDef>, } impl Context { - pub fn new(tasks: HashMap<TaskID, TaskDef>, pins: Pins) -> error::Result<Self> { + pub fn new(tasks: HashMap<TaskID, Vec<TaskDef>>, pins: Pins) -> error::Result<Self> { let platforms: HashMap<_, _> = [ arg( "build", @@ -270,15 +270,29 @@ impl Context { Some(task_def) } + fn select_task(tasks: &[TaskDef]) -> &TaskDef { + tasks + .iter() + .max_by(|task1, task2| { + deb_version::compare_versions( + task1.meta.version.as_deref().unwrap_or_default(), + task2.meta.version.as_deref().unwrap_or_default(), + ) + }) + .unwrap() + } + fn get_with_args<'ctx>(&'ctx self, id: &'ctx TaskID, args: &TaskArgs) -> Result<&TaskDef> { if let Some(rootfs_task) = self.rootfs_task(id, args) { return Ok(rootfs_task); } - self.tasks.get(id).ok_or(Error { + let tasks = self.tasks.get(id).ok_or(Error { task: id, kind: ErrorKind::TaskNotFound, - }) + })?; + + Ok(Self::select_task(tasks)) } pub fn get<'ctx>(&'ctx self, task: &TaskRef<'ctx>) -> Result<&TaskDef> { diff --git a/crates/driver/src/recipe.rs b/crates/driver/src/recipe.rs index 745e2f6..277a393 100644 --- a/crates/driver/src/recipe.rs +++ b/crates/driver/src/recipe.rs @@ -51,8 +51,8 @@ fn is_yml(path: &Path) -> bool { path.extension() == Some("yml".as_ref()) } -pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, TaskDef>> { - let mut tasks = HashMap::new(); +pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, Vec<TaskDef>>> { + let mut tasks = HashMap::<TaskID, Vec<TaskDef>>::new(); for entry in WalkDir::new(path).into_iter().filter_map(|e| e.ok()) { let path = entry.path(); @@ -85,7 +85,7 @@ pub fn read_recipes<P: AsRef<Path>>(path: P) -> Result<HashMap<TaskID, TaskDef>> task: label, }; task.meta = meta.clone(); - tasks.insert(task_id, task); + tasks.entry(task_id).or_default().push(task); } } |