summaryrefslogtreecommitdiffstats
path: root/crates/driver/src/context.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-11-03 21:08:23 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-11-03 22:21:53 +0100
commit550295e0906e7ea874b3b2c35fb17519b429369c (patch)
tree72b22a201526ceba47a69e6ade09fe2f5cd1dd68 /crates/driver/src/context.rs
parented31f842d6fc892120117b22d9bfcc13745e16bc (diff)
downloadrebel-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.
Diffstat (limited to 'crates/driver/src/context.rs')
-rw-r--r--crates/driver/src/context.rs22
1 files changed, 18 insertions, 4 deletions
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> {