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

generator: update to account for embedded bootspec docs #141

Merged
merged 4 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"bootspec-0.1.0" = "sha256-1CysX/Pt/DDxjzANgKxVHPAMQnucBh8RbIj/P+g2yR8=";
"bootspec-0.1.0" = "sha256-Jm2MS18eykACEP4+hvS0ic1r4gIQ04gYrZyXqVpjg/U=";
};
};

Expand Down
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 {
grahamc marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 1 addition & 2 deletions generator/src/systemd_boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ fn efi_entry_impl(efi: &EfiProgram, machine_id: &str) -> Result<(String, Content
let version = efi.source.version()?;
let data = format!(
r#"title {title}
version Generation {generation} {version}
version {version}
efi {efi}
machine-id {machine_id}
"#,
title = title,
generation = generation,
version = version,
efi = unified,
machine_id = machine_id,
Expand Down