mirror of
https://github.com/edera-dev/sprout.git
synced 2026-02-04 08:40:17 +00:00
chore(sprout): implement iterator stamping to cleanup code
This commit is contained in:
@@ -21,7 +21,7 @@ pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfigurat
|
||||
// Resolve the path to the image to chainload.
|
||||
let resolved = eficore::path::resolve_path(
|
||||
Some(context.root().loaded_image_path()?),
|
||||
&context.stamp(&configuration.path),
|
||||
context.stamp(&configuration.path),
|
||||
)
|
||||
.context("unable to resolve chainload path")?;
|
||||
|
||||
@@ -38,8 +38,7 @@ pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfigurat
|
||||
.context("unable to open loaded image protocol")?;
|
||||
|
||||
// Stamp and combine the options to pass to the image.
|
||||
let options =
|
||||
utils::combine_options(configuration.options.iter().map(|item| context.stamp(item)));
|
||||
let options = utils::combine_options(context.stamp_iter(configuration.options.iter()));
|
||||
|
||||
// Pass the load options to the image.
|
||||
// If no options are provided, the resulting string will be empty.
|
||||
@@ -50,6 +49,7 @@ pub fn chainload(context: Rc<SproutContext>, configuration: &ChainloadConfigurat
|
||||
.context("unable to convert chainloader options to CString16")?,
|
||||
);
|
||||
|
||||
// Ensure the chainloader options limit is not exceeded.
|
||||
if options.num_bytes() > u32::MAX as usize {
|
||||
bail!("chainloader options too large");
|
||||
}
|
||||
|
||||
@@ -20,20 +20,11 @@ use uefi::Guid;
|
||||
/// Builds a configuration string for the Xen EFI stub using the specified `configuration`.
|
||||
fn build_xen_config(context: Rc<SproutContext>, configuration: &EderaConfiguration) -> String {
|
||||
// Stamp xen options and combine them.
|
||||
let xen_options = utils::combine_options(
|
||||
configuration
|
||||
.xen_options
|
||||
.iter()
|
||||
.map(|item| context.stamp(item)),
|
||||
);
|
||||
let xen_options = utils::combine_options(context.stamp_iter(configuration.xen_options.iter()));
|
||||
|
||||
// Stamp kernel options and combine them.
|
||||
let kernel_options = utils::combine_options(
|
||||
configuration
|
||||
.kernel_options
|
||||
.iter()
|
||||
.map(|item| context.stamp(item)),
|
||||
);
|
||||
let kernel_options =
|
||||
utils::combine_options(context.stamp_iter(configuration.kernel_options.iter()));
|
||||
|
||||
// xen config file format is ini-like
|
||||
[
|
||||
|
||||
@@ -269,6 +269,15 @@ impl SproutContext {
|
||||
Self::stamp_values(&self.all_values(), text.as_ref()).1
|
||||
}
|
||||
|
||||
/// Stamps all the items from the iterator `input` with all the values in this [SproutContext]
|
||||
/// and it's parents. This calls [self.stamp] on each item.
|
||||
pub fn stamp_iter(
|
||||
&self,
|
||||
input: impl Iterator<Item = impl AsRef<str>>,
|
||||
) -> impl Iterator<Item = String> {
|
||||
input.map(|item| self.stamp(item))
|
||||
}
|
||||
|
||||
/// Unloads a [SproutContext] back into an owned context. This
|
||||
/// may not succeed if something else is holding onto the value.
|
||||
pub fn unload(self: Rc<SproutContext>) -> Option<SproutContext> {
|
||||
|
||||
@@ -18,7 +18,7 @@ fn load_driver(context: Rc<SproutContext>, driver: &DriverDeclaration) -> Result
|
||||
// Resolve the path to the driver image.
|
||||
let resolved = eficore::path::resolve_path(
|
||||
Some(context.root().loaded_image_path()?),
|
||||
&context.stamp(&driver.path),
|
||||
context.stamp(&driver.path),
|
||||
)
|
||||
.context("unable to resolve path to driver")?;
|
||||
|
||||
|
||||
@@ -22,11 +22,10 @@ pub fn generate(
|
||||
|
||||
// Stamp the entry title and actions from the template.
|
||||
let mut entry = list.entry.clone();
|
||||
entry.actions = entry
|
||||
.actions
|
||||
.into_iter()
|
||||
.map(|action| context.stamp(action))
|
||||
.collect();
|
||||
|
||||
// Stamp all the actions this entry references.
|
||||
entry.actions = context.stamp_iter(entry.actions.into_iter()).collect();
|
||||
|
||||
// Push the entry into the list with the new context.
|
||||
entries.push(BootableEntry::new(
|
||||
index.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user