Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
generator: update to account for embedded bootspec docs
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc committed May 17, 2022
1 parent d41b90f commit 18004b9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ regex = { version = "1.5.5" }
serde_json = "1.0.81"
tempfile = "3.3.0"
structopt = { version = "0.3.26", default-features = false }
bootspec = { git = "https://github.com/DeterminateSystems/bootspec", branch = "import" }
synthesize = { git = "https://github.com/DeterminateSystems/bootspec", branch = "import" }
bootspec = { git = "https://github.com/DeterminateSystems/bootspec", branch = "rfc-embed-subs" }
synthesize = { git = "https://github.com/DeterminateSystems/bootspec", branch = "rfc-embed-subs" }
11 changes: 3 additions & 8 deletions generator/src/bootable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fs;
use std::io::{self, Write};

use bootspec::{BootJson, SpecialisationName};
use bootspec::SpecialisationName;

use crate::{Generation, Result};

Expand Down Expand Up @@ -51,22 +50,18 @@ fn flatten_impl(
});

for (name, desc) in input.bootspec.specialisation {
let bootspec_path = desc.bootspec.0;

writeln!(
io::stderr(),
"Flattening specialisation '{name}' of toplevel {toplevel}: {path}",
toplevel = input.bootspec.toplevel.0.display(),
name = name.0,
path = bootspec_path.display()
path = desc.toplevel.0.display()
)?;

let json = fs::read_to_string(&bootspec_path)?;
let parsed: BootJson = serde_json::from_str(&json)?;
let gen = Generation {
index: input.index,
profile: input.profile.clone(),
bootspec: parsed,
bootspec: desc,
};

toplevels.extend(self::flatten_impl(vec![gen], Some(name))?);
Expand Down
18 changes: 5 additions & 13 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use bootspec::{BootJson, JSON_FILENAME};
use regex::Regex;
Expand All @@ -23,7 +23,7 @@ lazy_static::lazy_static! {
static ref PROFILE_RE: Regex = Regex::new("/system-profiles/(?P<profile>[^-]+)-(?P<generation>\\d+)-link").unwrap();
}

pub fn get_json(tempdir: &Path, generation_path: PathBuf) -> Result<BootJson> {
pub fn get_json(generation_path: PathBuf) -> Result<BootJson> {
let json_path = generation_path.join(JSON_FILENAME);

let mut json: Option<BootJson> = None;
Expand All @@ -36,17 +36,9 @@ pub fn get_json(tempdir: &Path, generation_path: PathBuf) -> Result<BootJson> {
}

if json.is_none() {
let dest = tempdir.join("synthesis");

// Time to synthesize
synthesize::synthesize_schema_from_generation(&generation_path, &dest)?;
let json_path = dest.join("boot.v1.json");

if let Ok(cont) = fs::read_to_string(&json_path) {
if let Ok(parsed) = serde_json::from_str(&cont) {
json = Some(parsed)
}
}
json = Some(synthesize::synthesize_schema_from_generation(
&generation_path,
)?);
}

Ok(json.unwrap())
Expand Down
9 changes: 1 addition & 8 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::PathBuf;
use generator::bootable::{self, Bootable, EfiProgram};
use generator::{systemd_boot, Generation, Result};
use structopt::StructOpt;
use tempfile::{tempdir, tempdir_in, TempDir};

#[derive(Default, Debug, StructOpt)]
struct Args {
Expand All @@ -28,8 +27,6 @@ struct Args {

fn main() -> Result<()> {
let args = Args::from_args();
let parent_tempdir = tempdir()?;
let mut tempdirs: Vec<TempDir> = vec![];

let generations = args
.generations
Expand All @@ -38,11 +35,7 @@ fn main() -> Result<()> {
generator::parse_generation(&gen)
.ok()
.map(|(index, profile)| {
let tempdir =
tempdir_in(parent_tempdir.path()).expect("Failed to get a new tempdir");

let bootspec = generator::get_json(tempdir.path(), PathBuf::from(gen));
tempdirs.push(tempdir);
let bootspec = generator::get_json(PathBuf::from(gen));

if let Ok(bootspec) = bootspec {
Some(Generation {
Expand Down

0 comments on commit 18004b9

Please sign in to comment.