tool: always include version in PRETTY_NAME
... to give a consistent user experience in systemd-boot. Fixes #220.
This commit is contained in:
parent
3da3049bef
commit
ec05d707f3
|
@ -67,7 +67,16 @@ impl Generation {
|
|||
}
|
||||
}
|
||||
|
||||
/// Describe the generation in a single line.
|
||||
/// A helper for describe functions below.
|
||||
fn describe_specialisation(&self) -> String {
|
||||
if let Some(specialization) = &self.specialisation_name {
|
||||
format!("-{specialization}")
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Describe the generation in a single line for humans.
|
||||
///
|
||||
/// Emulates how NixOS's current systemd-boot-builder.py describes generations so that the user
|
||||
/// interface remains similar.
|
||||
|
@ -83,14 +92,15 @@ impl Generation {
|
|||
format!(
|
||||
"Generation {}{}, {}",
|
||||
self.version,
|
||||
if let Some(specialization) = &self.specialisation_name {
|
||||
format!("-{specialization}")
|
||||
} else {
|
||||
"".to_string()
|
||||
},
|
||||
self.describe_specialisation(),
|
||||
build_time
|
||||
)
|
||||
}
|
||||
|
||||
/// A unique short identifier.
|
||||
pub fn version_tag(&self) -> String {
|
||||
format!("{}{}", self.version, self.describe_specialisation(),)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Generation {
|
||||
|
|
|
@ -26,10 +26,21 @@ impl OsRelease {
|
|||
// Because the ID field here does not have the same meaning as in a real os-release file,
|
||||
// it is fine to use a dummy value.
|
||||
map.insert("ID".into(), String::from("lanza"));
|
||||
|
||||
// systemd-boot will only show VERSION_ID when PRETTY_NAME is not unique. This is
|
||||
// confusing to users. Make sure that our PRETTY_NAME is unique, so we get a consistent
|
||||
// user experience.
|
||||
//
|
||||
// See #220.
|
||||
map.insert(
|
||||
"PRETTY_NAME".into(),
|
||||
generation.spec.bootspec.bootspec.label.clone(),
|
||||
format!(
|
||||
"{} ({})",
|
||||
generation.spec.bootspec.bootspec.label,
|
||||
generation.describe()
|
||||
),
|
||||
);
|
||||
|
||||
map.insert("VERSION_ID".into(), generation.describe());
|
||||
|
||||
Ok(Self(map))
|
||||
|
|
|
@ -27,8 +27,8 @@ fn generate_expected_os_release() -> Result<()> {
|
|||
|
||||
let expected = expect![[r#"
|
||||
ID=lanza
|
||||
PRETTY_NAME=LanzaOS
|
||||
VERSION_ID=Generation 1, Built on 1970-01-01
|
||||
PRETTY_NAME=LanzaOS (Generation 1, 1970-01-01)
|
||||
VERSION_ID=Generation 1, 1970-01-01
|
||||
"#]];
|
||||
|
||||
expected.assert_eq(&String::from_utf8(os_release_section)?);
|
||||
|
|
Loading…
Reference in New Issue