From 55449131fe9f0de0786d8c743ee0a353b7a12122 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 5 Nov 2021 22:05:02 +0100 Subject: driver: context: remove separate rootfs_tasks The rootfs tasks can now just be added to the regular task map. --- crates/driver/src/context.rs | 47 ++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs index 5564c86..3953f54 100644 --- a/crates/driver/src/context.rs +++ b/crates/driver/src/context.rs @@ -140,11 +140,10 @@ pub struct Context { globals: TaskArgs, tasks: HashMap>, rootfs: (ArchiveHash, String), - rootfs_tasks: HashMap, } impl Context { - pub fn new(tasks: HashMap>, pins: Pins) -> error::Result { + pub fn new(mut tasks: HashMap>, pins: Pins) -> error::Result { let platforms: HashMap<_, _> = [ arg( "build", @@ -176,14 +175,14 @@ impl Context { arg("sysroot", paths::TASK_SYSROOT.to_string()), ]); let rootfs = Context::handle_pins(pins)?; - let rootfs_tasks = Context::rootfs_tasks(); + + Context::add_rootfs_tasks(&mut tasks, &globals); Ok(Context { platforms, globals, tasks, rootfs, - rootfs_tasks, }) } @@ -204,7 +203,7 @@ impl Context { rootfs.context("No is-rootfs pins") } - fn rootfs_tasks() -> HashMap { + fn add_rootfs_tasks(tasks: &mut HashMap>, globals: &TaskArgs) { // TODO: Do not hardcode this const ROOTFS_TASKS: &[((&str, &str), bool, &[&str])] = &[ (("gmp", "install"), false, &["default"]), @@ -219,17 +218,19 @@ impl Context { (("glibc", "install"), false, &["default"]), (("e2fsprogs", "install"), false, &["default"]), ]; - - let mut ret = HashMap::new(); + let build = globals.get("build"); for ((recipe, task), has_target, outputs) in ROOTFS_TASKS { let mut task_def = TaskDef::default(); task_def.args.insert("host".to_string(), ArgType::Platform); + task_def.arg_match.set("host", build); + if *has_target { task_def .args .insert("target".to_string(), ArgType::Platform); + task_def.arg_match.set("target", build); } for output in *outputs { @@ -238,36 +239,22 @@ impl Context { .insert(output.to_string(), Output::default()); } - ret.insert( - TaskID { + task_def.priority = i32::MAX; + + tasks + .entry(TaskID { recipe: recipe.to_string(), task: task.to_string(), - }, - task_def, - ); + }) + .or_default() + .push(task_def); } - - ret } pub fn get_rootfs(&self) -> &(ArchiveHash, String) { &self.rootfs } - fn rootfs_task<'ctx>(&'ctx self, id: &'ctx TaskID, args: &TaskArgs) -> Option<&TaskDef> { - let build = self.globals.get("build").unwrap(); - if args.get("host") != Some(build) { - return None; - } - - let task_def = self.rootfs_tasks.get(id)?; - if task_def.args.get("target").is_some() && args.get("target") != Some(build) { - return None; - } - - Some(task_def) - } - fn match_task(task: &TaskDef, args: &TaskArgs) -> bool { task.arg_match .iter() @@ -292,10 +279,6 @@ impl Context { } 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) .and_then(|tasks| Self::select_task(tasks, args)) -- cgit v1.2.3