From f6e4529dba0adbf1736687686a0d70e674830a21 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 1 Nov 2021 23:16:41 +0100 Subject: context: get rootfs hash from pin map --- crates/driver/src/context.rs | 29 +++++++++++++++++++++++++++-- crates/driver/src/main.rs | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/driver/src/context.rs b/crates/driver/src/context.rs index b77655f..1c8c0bd 100644 --- a/crates/driver/src/context.rs +++ b/crates/driver/src/context.rs @@ -13,6 +13,7 @@ use regex::Regex; use common::{ error::{self, Contextualizable}, + string_hash::ArchiveHash, types::TaskID, }; @@ -136,11 +137,12 @@ pub struct Context { platforms: HashMap, globals: TaskArgs, tasks: HashMap, + rootfs: (ArchiveHash, String), rootfs_tasks: HashMap, } impl Context { - pub fn new(tasks: HashMap, _pins: Pins) -> Self { + pub fn new(tasks: HashMap, pins: Pins) -> error::Result { let platforms: HashMap<_, _> = [ arg( "build", @@ -171,14 +173,33 @@ impl Context { arg("destdir", paths::TASK_DESTDIR.to_string()), arg("sysroot", paths::TASK_SYSROOT.to_string()), ]); + let rootfs = Context::handle_pins(pins)?; let rootfs_tasks = Context::rootfs_tasks(); - Context { + Ok(Context { platforms, globals, tasks, + rootfs, rootfs_tasks, + }) + } + + fn handle_pins(pins: Pins) -> error::Result<(ArchiveHash, String)> { + let mut rootfs = None; + + for (name, pin) in pins { + if pin.is_rootfs { + if rootfs.is_some() { + return Err(error::Error::new("Multiple is-rootfs pins")); + } + let hash = pin.hash.context("is-rootfs pin without hash")?; + + rootfs = Some((hash, name)); + } } + + rootfs.context("No is-rootfs pins") } fn rootfs_tasks() -> HashMap { @@ -227,6 +248,10 @@ impl Context { 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) { diff --git a/crates/driver/src/main.rs b/crates/driver/src/main.rs index 2763dfa..fe9204a 100644 --- a/crates/driver/src/main.rs +++ b/crates/driver/src/main.rs @@ -32,7 +32,8 @@ fn main() { let ctx = context::Context::new( recipe::read_recipes("examples/recipes").unwrap(), pin::read_pins("examples/pins.yml").unwrap(), - ); + ) + .unwrap(); let mut rsv = resolve::Resolver::new(&ctx); -- cgit v1.2.3