use crate::error::Error;
use crate::model;
use crate::pins;
use crate::platform::checked;
use crate::platform::ffi;
use crate::store::Store;
pub struct Builder {
store: Store,
}
impl Builder {
pub fn new(store: Store) -> Self {
Self { store }
}
pub fn store(&self) -> &Store {
&self.store
}
pub fn build(&self, plan: &model::BuildPlan) -> Result<(), Error> {
let code = ffi::czbridge_build(
plan.clone(),
&self.store.root().display().to_string(),
&self.store.kernel().display().to_string(),
self.store.initfs_reference(),
&self.store.initfs().display().to_string(),
);
checked(code, format!("build {}", plan.tag)).map(|_| ())
}
pub fn provision(&self) -> Result<(), Error> {
let code = ffi::czbridge_provision(
&self.store.root().display().to_string(),
&self.store.kernel().display().to_string(),
pins::KERNEL_URL,
pins::KERNEL_IN_ARCHIVE,
self.store.initfs_reference(),
&self.store.initfs().display().to_string(),
);
checked(code, "provision the image store").map(|_| ())
}
}