fix: animation timeline loops
This commit is contained in:
1 parent
0a29c7c88a
commit
b126596973
22 files changed
+270
-158
No files matched your search
+5
-4
@@ -140,8 +140,8 @@ const HOST: &[Step] = &[
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn description(unit: &str) -> &'static str {
|
fn description(unit: &str) -> Option<&'static str> {
|
||||||
match unit {
|
let description = match unit {
|
||||||
"initrd.target" => "Initrd Default Target",
|
"initrd.target" => "Initrd Default Target",
|
||||||
"initrd-fs.target" => "Initrd File Systems",
|
"initrd-fs.target" => "Initrd File Systems",
|
||||||
"initrd-root-device.target" => "Initrd Root Device",
|
"initrd-root-device.target" => "Initrd Root Device",
|
||||||
@@ -168,8 +168,9 @@ fn description(unit: &str) -> &'static str {
|
|||||||
"nvidia-powerd.service" => "NVIDIA Dynamic Boost",
|
"nvidia-powerd.service" => "NVIDIA Dynamic Boost",
|
||||||
"sys-devices-virtual-misc-rfkill.device" => "/sys/devices/virtual/misc/rfkill",
|
"sys-devices-virtual-misc-rfkill.device" => "/sys/devices/virtual/misc/rfkill",
|
||||||
"systemd-rfkill.service" => "Load/Save RF Kill Switch Status",
|
"systemd-rfkill.service" => "Load/Save RF Kill Switch Status",
|
||||||
_ => "",
|
_ => return None,
|
||||||
}
|
};
|
||||||
|
Some(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
|
|||||||
+5
-4
@@ -154,8 +154,8 @@ const HOST: &[Step] = &[
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn description(unit: &str) -> &'static str {
|
fn description(unit: &str) -> Option<&'static str> {
|
||||||
match unit {
|
let description = match unit {
|
||||||
"initrd.target" => "Initrd Default Target",
|
"initrd.target" => "Initrd Default Target",
|
||||||
"initrd-fs.target" => "Initrd File Systems",
|
"initrd-fs.target" => "Initrd File Systems",
|
||||||
"initrd-root-fs.target" => "Initrd Root File System",
|
"initrd-root-fs.target" => "Initrd Root File System",
|
||||||
@@ -185,8 +185,9 @@ fn description(unit: &str) -> &'static str {
|
|||||||
"systemd-logind.service" => "User Login Management",
|
"systemd-logind.service" => "User Login Management",
|
||||||
"NetworkManager.service" => "Network Manager",
|
"NetworkManager.service" => "Network Manager",
|
||||||
"systemd-timesyncd.service" => "Network Time Synchronization",
|
"systemd-timesyncd.service" => "Network Time Synchronization",
|
||||||
_ => "",
|
_ => return None,
|
||||||
}
|
};
|
||||||
|
Some(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ const SHUTDOWN: &[Step] = &[
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
fn description(unit: &str) -> &'static str {
|
fn description(unit: &str) -> Option<&'static str> {
|
||||||
match unit {
|
let description = match unit {
|
||||||
"poweroff.target" | "systemd-poweroff.service" => "System Power Off",
|
"poweroff.target" | "systemd-poweroff.service" => "System Power Off",
|
||||||
"final.target" => "Late Shutdown Services",
|
"final.target" => "Late Shutdown Services",
|
||||||
"umount.target" => "Unmount All Filesystems",
|
"umount.target" => "Unmount All Filesystems",
|
||||||
@@ -78,8 +78,9 @@ fn description(unit: &str) -> &'static str {
|
|||||||
"NetworkManager.service" => "Network Manager",
|
"NetworkManager.service" => "Network Manager",
|
||||||
"var-lib-docker.mount" => "/var/lib/docker",
|
"var-lib-docker.mount" => "/var/lib/docker",
|
||||||
"home.mount" => "/home",
|
"home.mount" => "/home",
|
||||||
_ => "",
|
_ => return None,
|
||||||
}
|
};
|
||||||
|
Some(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ pub struct BootState {
|
|||||||
pub handoff_unit: Option<String>,
|
pub handoff_unit: Option<String>,
|
||||||
pub manager_exited_at: Option<Duration>,
|
pub manager_exited_at: Option<Duration>,
|
||||||
pub milestone_targets: Vec<String>,
|
pub milestone_targets: Vec<String>,
|
||||||
|
boot_finished: bool,
|
||||||
finished_before_reconnect: usize,
|
finished_before_reconnect: usize,
|
||||||
units: HashMap<String, UnitRecord>,
|
units: HashMap<String, UnitRecord>,
|
||||||
jobs: HashMap<u32, String>,
|
jobs: HashMap<u32, String>,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ pub enum BootChange {
|
|||||||
ManagerExited {
|
ManagerExited {
|
||||||
at: Duration,
|
at: Duration,
|
||||||
},
|
},
|
||||||
|
BootFinished,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BootState {
|
impl BootState {
|
||||||
@@ -47,6 +48,7 @@ impl BootState {
|
|||||||
BootChange::SwitchRoot { at } => self.switch_root(at),
|
BootChange::SwitchRoot { at } => self.switch_root(at),
|
||||||
BootChange::ForgetJobs => self.forget_jobs(),
|
BootChange::ForgetJobs => self.forget_jobs(),
|
||||||
BootChange::ManagerExited { at } => self.manager_exited_at = Some(at),
|
BootChange::ManagerExited { at } => self.manager_exited_at = Some(at),
|
||||||
|
BootChange::BootFinished => self.mark_boot_finished(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,4 +95,12 @@ mod tests {
|
|||||||
assert_eq!(applied.is_complete(), called.is_complete());
|
assert_eq!(applied.is_complete(), called.is_complete());
|
||||||
assert_eq!(waiting_rows(&applied), waiting_rows(&called));
|
assert_eq!(waiting_rows(&applied), waiting_rows(&called));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn boot_finished_change_marks_the_boot_complete() {
|
||||||
|
let mut state = BootState::new(Phase::Host);
|
||||||
|
assert!(!state.is_complete());
|
||||||
|
state.apply(BootChange::BootFinished);
|
||||||
|
assert!(state.is_complete());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{read_dir, read_link, read_to_string},
|
fs::{read_dir, read_link, read_to_string},
|
||||||
|
iter::once,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -13,8 +14,8 @@ const NIXOS_SYSTEM: &str = "nixos-system-";
|
|||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
pub struct BootOrigin {
|
pub struct BootOrigin {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub system: String,
|
pub system: Option<String>,
|
||||||
pub generation: String,
|
pub generation: Option<String>,
|
||||||
pub kernel: String,
|
pub kernel: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,11 +34,9 @@ impl BootOrigin {
|
|||||||
.iter()
|
.iter()
|
||||||
.find_map(|path| read_to_string(path).ok())
|
.find_map(|path| read_to_string(path).ok())
|
||||||
.and_then(|release| pretty_name(&release))
|
.and_then(|release| pretty_name(&release))
|
||||||
})
|
});
|
||||||
.unwrap_or_default();
|
let generation =
|
||||||
let generation = system_path
|
system_path.and_then(|path| generation_of(Path::new(path), &system_links()));
|
||||||
.map(|path| generation_of(Path::new(path), &system_links()))
|
|
||||||
.unwrap_or_default();
|
|
||||||
Self {
|
Self {
|
||||||
kernel: format!("Linux {}", names.release().to_string_lossy()),
|
kernel: format!("Linux {}", names.release().to_string_lossy()),
|
||||||
host,
|
host,
|
||||||
@@ -48,19 +47,15 @@ impl BootOrigin {
|
|||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn parts(&self) -> Vec<String> {
|
pub fn parts(&self) -> Vec<String> {
|
||||||
[
|
once(self.host.clone())
|
||||||
self.host.clone(),
|
.chain(self.system.clone())
|
||||||
self.system.clone(),
|
.chain(
|
||||||
if self.generation.is_empty() {
|
self.generation
|
||||||
String::new()
|
.as_ref()
|
||||||
} else {
|
.map(|generation| format!("generation {generation}")),
|
||||||
format!("generation {}", self.generation)
|
)
|
||||||
},
|
.chain(once(self.kernel.clone()))
|
||||||
self.kernel.clone(),
|
.collect()
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.filter(|part| !part.is_empty())
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,12 +102,11 @@ fn system_links() -> Vec<SystemLink> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generation_of(system_path: &Path, links: &[SystemLink]) -> String {
|
fn generation_of(system_path: &Path, links: &[SystemLink]) -> Option<String> {
|
||||||
links
|
links
|
||||||
.iter()
|
.iter()
|
||||||
.find(|link| link.target == system_path)
|
.find(|link| link.target == system_path)
|
||||||
.map(|link| link.generation.clone())
|
.map(|link| link.generation.clone())
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -147,8 +141,11 @@ mod tests {
|
|||||||
target: system.into(),
|
target: system.into(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
assert_eq!(generation_of(Path::new(system), &links), "2771");
|
assert_eq!(
|
||||||
assert_eq!(generation_of(Path::new(system), &links[..1]), "");
|
generation_of(Path::new(system), &links),
|
||||||
|
Some("2771".to_owned())
|
||||||
|
);
|
||||||
|
assert_eq!(generation_of(Path::new(system), &links[..1]), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -163,8 +160,8 @@ mod tests {
|
|||||||
fn unknown_parts_are_left_out() {
|
fn unknown_parts_are_left_out() {
|
||||||
let origin = BootOrigin {
|
let origin = BootOrigin {
|
||||||
host: "ryzen".to_owned(),
|
host: "ryzen".to_owned(),
|
||||||
system: "NixOS 26.11".to_owned(),
|
system: Some("NixOS 26.11".to_owned()),
|
||||||
generation: String::new(),
|
generation: None,
|
||||||
kernel: "Linux 7.2.9".to_owned(),
|
kernel: "Linux 7.2.9".to_owned(),
|
||||||
};
|
};
|
||||||
assert_eq!(origin.parts(), ["ryzen", "NixOS 26.11", "Linux 7.2.9"]);
|
assert_eq!(origin.parts(), ["ryzen", "NixOS 26.11", "Linux 7.2.9"]);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ impl BootState {
|
|||||||
handoff_unit,
|
handoff_unit,
|
||||||
manager_exited_at: None,
|
manager_exited_at: None,
|
||||||
milestone_targets,
|
milestone_targets,
|
||||||
|
boot_finished: false,
|
||||||
finished_before_reconnect: 0,
|
finished_before_reconnect: 0,
|
||||||
units: HashMap::new(),
|
units: HashMap::new(),
|
||||||
jobs: HashMap::new(),
|
jobs: HashMap::new(),
|
||||||
@@ -92,6 +93,10 @@ impl BootState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mark_boot_finished(&mut self) {
|
||||||
|
self.boot_finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn track_unit(&mut self, facts: UnitFacts, activity: Activity) {
|
pub fn track_unit(&mut self, facts: UnitFacts, activity: Activity) {
|
||||||
let record = self
|
let record = self
|
||||||
.units
|
.units
|
||||||
@@ -212,13 +217,7 @@ impl BootState {
|
|||||||
if matches!(self.phase, Phase::Initrd | Phase::Shutdown) {
|
if matches!(self.phase, Phase::Initrd | Phase::Shutdown) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if self
|
if self.boot_finished {
|
||||||
.handoff_unit
|
|
||||||
.as_deref()
|
|
||||||
.and_then(|unit| self.units.get(unit))
|
|
||||||
.and_then(|handoff| handoff.activity.state)
|
|
||||||
.is_some_and(|state| state != ActiveState::Inactive)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let Root::Queued(root) = &self.root else {
|
let Root::Queued(root) = &self.root else {
|
||||||
@@ -285,30 +284,26 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_manager_activation_hands_the_console_over() {
|
fn display_manager_activation_does_not_hand_the_console_over() {
|
||||||
let mut state = sample();
|
let mut state = sample();
|
||||||
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
||||||
assert!(!state.is_complete());
|
|
||||||
state.update_activity(HANDOFF_UNIT, activating(6000 * MS));
|
state.update_activity(HANDOFF_UNIT, activating(6000 * MS));
|
||||||
|
assert!(!state.is_complete());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn boot_finished_hands_the_console_over() {
|
||||||
|
let mut state = sample();
|
||||||
|
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
||||||
|
state.mark_boot_finished();
|
||||||
assert!(state.is_complete());
|
assert!(state.is_complete());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn display_manager_started_in_one_step_hands_the_console_over() {
|
fn boot_finished_is_ignored_in_the_initrd() {
|
||||||
let mut state = sample();
|
let mut state = BootState::new(Phase::Initrd);
|
||||||
queue_unit(&mut state, 20, waiting(HANDOFF_UNIT, &[]), 500 * MS);
|
state.mark_boot_finished();
|
||||||
state.finish_job(20, JobResult::Done, 6000 * MS);
|
|
||||||
assert!(!state.is_complete());
|
assert!(!state.is_complete());
|
||||||
state.update_activity(
|
|
||||||
HANDOFF_UNIT,
|
|
||||||
Activity {
|
|
||||||
state: Some(ActiveState::Active),
|
|
||||||
inactive_exit: Some(6000 * MS),
|
|
||||||
active_enter: Some(6000 * MS),
|
|
||||||
active_exit: None,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
assert!(state.is_complete());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub enum JobResult {
|
|||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct UnitFacts {
|
pub struct UnitFacts {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: Option<String>,
|
||||||
pub after: Vec<String>,
|
pub after: Vec<String>,
|
||||||
pub before: Vec<String>,
|
pub before: Vec<String>,
|
||||||
}
|
}
|
||||||
@@ -90,18 +90,18 @@ impl UnitKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn tag(self) -> &'static str {
|
pub fn tag(self) -> Option<&'static str> {
|
||||||
match self {
|
match self {
|
||||||
Self::Service | Self::Target | Self::Other => "",
|
Self::Service | Self::Target | Self::Other => None,
|
||||||
Self::Socket => "Socket",
|
Self::Socket => Some("Socket"),
|
||||||
Self::Mount => "Mount",
|
Self::Mount => Some("Mount"),
|
||||||
Self::Automount => "Automount",
|
Self::Automount => Some("Automount"),
|
||||||
Self::Device => "Device",
|
Self::Device => Some("Device"),
|
||||||
Self::Swap => "Swap",
|
Self::Swap => Some("Swap"),
|
||||||
Self::Path => "Path",
|
Self::Path => Some("Path"),
|
||||||
Self::Timer => "Timer",
|
Self::Timer => Some("Timer"),
|
||||||
Self::Slice => "Slice",
|
Self::Slice => Some("Slice"),
|
||||||
Self::Scope => "Scope",
|
Self::Scope => Some("Scope"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,12 +114,15 @@ impl UnitKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn labelled_by_description(facts: &UnitFacts) -> bool {
|
fn labelled_by_description(facts: &UnitFacts) -> bool {
|
||||||
!facts.description.is_empty() && UnitKind::of(&facts.name).labelled_by_description()
|
facts.description.is_some() && UnitKind::of(&facts.name).labelled_by_description()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn display_label(facts: &UnitFacts) -> String {
|
pub(super) fn display_label(facts: &UnitFacts) -> String {
|
||||||
if labelled_by_description(facts) {
|
if labelled_by_description(facts) {
|
||||||
return facts.description.clone();
|
return facts
|
||||||
|
.description
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| facts.name.clone());
|
||||||
}
|
}
|
||||||
match UnitKind::of(&facts.name) {
|
match UnitKind::of(&facts.name) {
|
||||||
UnitKind::Target | UnitKind::Other => facts.name.clone(),
|
UnitKind::Target | UnitKind::Other => facts.name.clone(),
|
||||||
@@ -130,13 +133,12 @@ pub(super) fn display_label(facts: &UnitFacts) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn summary(facts: &UnitFacts) -> String {
|
pub(super) fn summary(facts: &UnitFacts) -> Option<String> {
|
||||||
let repeats_the_name = facts.description == facts.name
|
let repeats_the_name = facts.description.as_deref().is_some_and(|description| {
|
||||||
|| facts
|
description == facts.name || description.eq_ignore_ascii_case(&display_label(facts))
|
||||||
.description
|
});
|
||||||
.eq_ignore_ascii_case(&display_label(facts));
|
|
||||||
if labelled_by_description(facts) || repeats_the_name {
|
if labelled_by_description(facts) || repeats_the_name {
|
||||||
return String::new();
|
return None;
|
||||||
}
|
}
|
||||||
facts.description.clone()
|
facts.description.clone()
|
||||||
}
|
}
|
||||||
@@ -168,11 +170,11 @@ mod tests {
|
|||||||
fn kinds_with_a_tag_drop_their_suffix() {
|
fn kinds_with_a_tag_drop_their_suffix() {
|
||||||
let socket = facts("docker.socket", &[]);
|
let socket = facts("docker.socket", &[]);
|
||||||
assert_eq!(UnitKind::of(&socket.name), UnitKind::Socket);
|
assert_eq!(UnitKind::of(&socket.name), UnitKind::Socket);
|
||||||
assert_eq!(UnitKind::Socket.tag(), "Socket");
|
assert_eq!(UnitKind::Socket.tag(), Some("Socket"));
|
||||||
assert_eq!(display_label(&socket), "docker");
|
assert_eq!(display_label(&socket), "docker");
|
||||||
assert_eq!(display_label(&facts("sshd.service", &[])), "sshd");
|
assert_eq!(display_label(&facts("sshd.service", &[])), "sshd");
|
||||||
assert_eq!(display_label(&facts("basic.target", &[])), "basic.target");
|
assert_eq!(display_label(&facts("basic.target", &[])), "basic.target");
|
||||||
assert_eq!(UnitKind::Target.tag(), "");
|
assert_eq!(UnitKind::Target.tag(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -182,11 +184,11 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
described("multi-user.target", "Multi-User System"),
|
described("multi-user.target", "Multi-User System"),
|
||||||
"Multi-User System"
|
Some("Multi-User System".to_owned())
|
||||||
);
|
);
|
||||||
assert_eq!(described("greetd.service", "greetd.service"), "");
|
assert_eq!(described("greetd.service", "greetd.service"), None);
|
||||||
assert_eq!(described("greetd.service", "Greetd"), "");
|
assert_eq!(described("greetd.service", "Greetd"), None);
|
||||||
assert_eq!(described("dev-sda.device", "Samsung SSD"), "");
|
assert_eq!(described("dev-sda.device", "Samsung SSD"), None);
|
||||||
assert_eq!(described("demo.service", ""), "");
|
assert_eq!(described("demo.service", ""), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,11 @@ use super::{
|
|||||||
|
|
||||||
type WaitingGraph<'a> = DiGraphMap<&'a str, ()>;
|
type WaitingGraph<'a> = DiGraphMap<&'a str, ()>;
|
||||||
|
|
||||||
|
struct WaitingEdge<'a> {
|
||||||
|
waiter: &'a str,
|
||||||
|
dependency: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
struct ReachableSibling<'a> {
|
struct ReachableSibling<'a> {
|
||||||
unit: &'a str,
|
unit: &'a str,
|
||||||
reaches: HashSet<&'a str>,
|
reaches: HashSet<&'a str>,
|
||||||
@@ -33,7 +38,7 @@ pub enum RowStatus {
|
|||||||
pub struct TreeRow {
|
pub struct TreeRow {
|
||||||
pub depth: usize,
|
pub depth: usize,
|
||||||
pub label: String,
|
pub label: String,
|
||||||
pub description: String,
|
pub description: Option<String>,
|
||||||
pub kind: UnitKind,
|
pub kind: UnitKind,
|
||||||
pub status: RowStatus,
|
pub status: RowStatus,
|
||||||
pub chain: Vec<String>,
|
pub chain: Vec<String>,
|
||||||
@@ -103,15 +108,15 @@ impl BootState {
|
|||||||
.for_each(|(name, _)| {
|
.for_each(|(name, _)| {
|
||||||
graph.add_node(name.as_str());
|
graph.add_node(name.as_str());
|
||||||
});
|
});
|
||||||
let edges: Vec<(&str, &str)> = graph
|
let edges: Vec<WaitingEdge> = graph
|
||||||
.nodes()
|
.nodes()
|
||||||
.flat_map(|waiter| {
|
.flat_map(|waiter| {
|
||||||
self.waits_for(waiter, &graph)
|
self.waits_for(waiter, &graph)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |dependency| (waiter, dependency))
|
.map(move |dependency| WaitingEdge { waiter, dependency })
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
graph.extend(edges);
|
graph.extend(edges.into_iter().map(|edge| (edge.waiter, edge.dependency)));
|
||||||
let root = self.root.unit().filter(|root| graph.contains_node(root));
|
let root = self.root.unit().filter(|root| graph.contains_node(root));
|
||||||
let stages: Vec<&str> = self
|
let stages: Vec<&str> = self
|
||||||
.milestone_targets
|
.milestone_targets
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ fn tree_on_top_timeline_below() {
|
|||||||
"{screen}"
|
"{screen}"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
lines[timeline + 4].contains("·■")
|
lines[timeline + 4].contains("·█")
|
||||||
&& lines[timeline + 4].ends_with(['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█']),
|
&& lines[timeline + 4].ends_with(['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█']),
|
||||||
"{screen}"
|
"{screen}"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -75,9 +75,10 @@ impl Timeline<'_> {
|
|||||||
let bar_rows = usize::from(height.saturating_sub(CHROME_HEIGHT));
|
let bar_rows = usize::from(height.saturating_sub(CHROME_HEIGHT));
|
||||||
let room = bar_rows.saturating_sub(self.milestones.len() + self.running.len());
|
let room = bar_rows.saturating_sub(self.milestones.len() + self.running.len());
|
||||||
let mut longest_first = self.finished.clone();
|
let mut longest_first = self.finished.clone();
|
||||||
longest_first.sort_by_key(|run| Reverse(run.finished_at.saturating_sub(run.started_at)));
|
longest_first
|
||||||
|
.sort_unstable_by_key(|run| Reverse(run.finished_at.saturating_sub(run.started_at)));
|
||||||
longest_first.truncate(room.min(SLOWEST_RUNS_SHOWN));
|
longest_first.truncate(room.min(SLOWEST_RUNS_SHOWN));
|
||||||
longest_first.sort_by_key(|run| run.started_at);
|
longest_first.sort_unstable_by_key(|run| run.started_at);
|
||||||
longest_first
|
longest_first
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,10 +144,14 @@ impl Timeline<'_> {
|
|||||||
symbol: self.glyphs.waiting_bead,
|
symbol: self.glyphs.waiting_bead,
|
||||||
color: self.colors.queued_bar,
|
color: self.colors.queued_bar,
|
||||||
});
|
});
|
||||||
|
let running_bar = self
|
||||||
|
.glyphs
|
||||||
|
.growing_tip
|
||||||
|
.map_or(self.glyphs.bead, |tips| tips[7]);
|
||||||
let ran = Segment {
|
let ran = Segment {
|
||||||
from: run.since,
|
from: run.since,
|
||||||
to: self.now,
|
to: self.now,
|
||||||
symbol: self.glyphs.bead,
|
symbol: running_bar,
|
||||||
color: self.colors.running,
|
color: self.colors.running,
|
||||||
};
|
};
|
||||||
TimelineEntry {
|
TimelineEntry {
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ pub fn render_prompted(
|
|||||||
pub fn ryzen_origin() -> BootOrigin {
|
pub fn ryzen_origin() -> BootOrigin {
|
||||||
BootOrigin {
|
BootOrigin {
|
||||||
host: "ryzen".to_owned(),
|
host: "ryzen".to_owned(),
|
||||||
system: "NixOS 26.11".to_owned(),
|
system: Some("NixOS 26.11".to_owned()),
|
||||||
generation: "2771".to_owned(),
|
generation: Some("2771".to_owned()),
|
||||||
kernel: "Linux 7.2.9".to_owned(),
|
kernel: "Linux 7.2.9".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::iter::successors;
|
||||||
|
|
||||||
use crate::boot_model::{RowStatus, TreeNode, TreeRow, UnitKind, flatten_forest};
|
use crate::boot_model::{RowStatus, TreeNode, TreeRow, UnitKind, flatten_forest};
|
||||||
|
|
||||||
const MIN_FOLDED_LINKS: usize = 2;
|
const MIN_FOLDED_LINKS: usize = 2;
|
||||||
@@ -55,13 +57,12 @@ impl TreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn foldable_links(&self) -> usize {
|
fn foldable_links(&self) -> usize {
|
||||||
let mut links = 0;
|
successors(Some(self), |cursor| {
|
||||||
let mut cursor = self;
|
(cursor.is_chain_link() && cursor.children[0].is_chain_link())
|
||||||
while cursor.is_chain_link() && cursor.children[0].is_chain_link() {
|
.then(|| &cursor.children[0])
|
||||||
links += 1;
|
})
|
||||||
cursor = &cursor.children[0];
|
.count()
|
||||||
}
|
.saturating_sub(1)
|
||||||
links
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold(mut self, may_absorb: bool) -> Self {
|
fn fold(mut self, may_absorb: bool) -> Self {
|
||||||
|
|||||||
+27
-21
@@ -170,12 +170,12 @@ impl UnitTree<'_> {
|
|||||||
.iter()
|
.iter()
|
||||||
.zip(self.stages())
|
.zip(self.stages())
|
||||||
.filter(|(row, _)| {
|
.filter(|(row, _)| {
|
||||||
row.chain.is_empty() && !(row.description.is_empty() && row.kind.tag().is_empty())
|
row.chain.is_empty() && !(row.description.is_none() && row.kind.tag().is_none())
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let tag = annotated
|
let tag = annotated
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(row, _)| width_of(row.kind.tag()))
|
.map(|(row, _)| width_of(row.kind.tag().unwrap_or_default()))
|
||||||
.fold(MIN_TAG_WIDTH, u16::max);
|
.fold(MIN_TAG_WIDTH, u16::max);
|
||||||
let content = unannotated.saturating_sub(2);
|
let content = unannotated.saturating_sub(2);
|
||||||
let label = (content * 3 / 5).max(MIN_LABEL_WIDTH);
|
let label = (content * 3 / 5).max(MIN_LABEL_WIDTH);
|
||||||
@@ -214,16 +214,23 @@ impl UnitTree<'_> {
|
|||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
};
|
};
|
||||||
let style = self.label_style(row, stage);
|
let style = self.label_style(row, stage);
|
||||||
Row::new(columns.shown([
|
Row::new(
|
||||||
Line::from(vec![
|
columns.shown([
|
||||||
prefix.fg(self.colors.branches),
|
Line::from(vec![
|
||||||
marker,
|
prefix.fg(self.colors.branches),
|
||||||
Span::styled(self.chained_label(row, room), style),
|
marker,
|
||||||
|
Span::styled(self.chained_label(row, room), style),
|
||||||
|
]),
|
||||||
|
Line::from(annotation(row.kind.tag().unwrap_or_default(), columns.tag))
|
||||||
|
.fg(self.colors.columns),
|
||||||
|
Line::from(annotation(
|
||||||
|
row.description.as_deref().unwrap_or_default(),
|
||||||
|
columns.description,
|
||||||
|
))
|
||||||
|
.fg(self.colors.columns),
|
||||||
|
Line::from(timer).style(style).right_aligned(),
|
||||||
]),
|
]),
|
||||||
Line::from(annotation(row.kind.tag(), columns.tag)).fg(self.colors.columns),
|
)
|
||||||
Line::from(annotation(&row.description, columns.description)).fg(self.colors.columns),
|
|
||||||
Line::from(timer).style(style).right_aligned(),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,22 +284,21 @@ impl Widget for UnitTree<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tree_prefixes(rows: &[TreeRow]) -> Vec<String> {
|
fn tree_prefixes(rows: &[TreeRow]) -> Vec<String> {
|
||||||
let mut later_sibling: Vec<bool> = Vec::new();
|
let is_last = rows
|
||||||
let mut is_last: Vec<bool> = rows
|
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|row| {
|
.scan(Vec::<bool>::new(), |later_sibling, row| {
|
||||||
let last = !later_sibling.get(row.depth).copied().unwrap_or(false);
|
let last = !later_sibling.get(row.depth).copied().unwrap_or(false);
|
||||||
later_sibling.resize(row.depth + 1, false);
|
later_sibling.resize(row.depth + 1, false);
|
||||||
later_sibling[row.depth] = true;
|
later_sibling[row.depth] = true;
|
||||||
last
|
Some(last)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect::<Vec<_>>()
|
||||||
is_last.reverse();
|
.into_iter()
|
||||||
let mut trunks: Vec<&str> = Vec::new();
|
.rev();
|
||||||
rows.iter()
|
rows.iter()
|
||||||
.zip(is_last)
|
.zip(is_last)
|
||||||
.map(|(row, last)| {
|
.scan(Vec::<&str>::new(), |trunks, (row, last)| {
|
||||||
trunks.truncate(row.depth);
|
trunks.truncate(row.depth);
|
||||||
let connector = if last { LAST_BRANCH } else { BRANCH };
|
let connector = if last { LAST_BRANCH } else { BRANCH };
|
||||||
let prefix = once(ENDED_TRUNK)
|
let prefix = once(ENDED_TRUNK)
|
||||||
@@ -300,7 +306,7 @@ fn tree_prefixes(rows: &[TreeRow]) -> Vec<String> {
|
|||||||
.chain(once(connector))
|
.chain(once(connector))
|
||||||
.collect();
|
.collect();
|
||||||
trunks.push(if last { ENDED_TRUNK } else { PASSING_TRUNK });
|
trunks.push(if last { ENDED_TRUNK } else { PASSING_TRUNK });
|
||||||
prefix
|
Some(prefix)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@@ -325,7 +331,7 @@ mod tests {
|
|||||||
TreeRow {
|
TreeRow {
|
||||||
depth,
|
depth,
|
||||||
label: String::new(),
|
label: String::new(),
|
||||||
description: String::new(),
|
description: None,
|
||||||
kind: UnitKind::Service,
|
kind: UnitKind::Service,
|
||||||
status: RowStatus::Waiting,
|
status: RowStatus::Waiting,
|
||||||
chain: Vec::new(),
|
chain: Vec::new(),
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ pub struct Console {
|
|||||||
quiet_kernel: Option<QuietKernelConsole>,
|
quiet_kernel: Option<QuietKernelConsole>,
|
||||||
foreground: Option<ForegroundVt>,
|
foreground: Option<ForegroundVt>,
|
||||||
for_system: bool,
|
for_system: bool,
|
||||||
|
handing_over: bool,
|
||||||
pub glyphs: Glyphs,
|
pub glyphs: Glyphs,
|
||||||
pub bold_is_brightness: bool,
|
pub bold_is_brightness: bool,
|
||||||
}
|
}
|
||||||
@@ -37,6 +38,7 @@ impl Console {
|
|||||||
ForegroundVt::take()
|
ForegroundVt::take()
|
||||||
},
|
},
|
||||||
for_system,
|
for_system,
|
||||||
|
handing_over: false,
|
||||||
glyphs: font_glyphs(),
|
glyphs: font_glyphs(),
|
||||||
bold_is_brightness: own_vt().is_some(),
|
bold_is_brightness: own_vt().is_some(),
|
||||||
}
|
}
|
||||||
@@ -63,12 +65,30 @@ impl Console {
|
|||||||
.quiet_kernel
|
.quiet_kernel
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.is_some_and(QuietKernelConsole::keep_quiet);
|
.is_some_and(QuietKernelConsole::keep_quiet);
|
||||||
let terminal_was_taken = self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
let terminal_was_taken =
|
||||||
|
!self.handing_over && self.foreground.as_ref().is_some_and(ForegroundVt::insist);
|
||||||
let glyphs = font_glyphs();
|
let glyphs = font_glyphs();
|
||||||
let font_changed = glyphs != self.glyphs;
|
let font_changed = glyphs != self.glyphs;
|
||||||
self.glyphs = glyphs;
|
self.glyphs = glyphs;
|
||||||
kernel_got_loud || terminal_was_taken || font_changed
|
kernel_got_loud || terminal_was_taken || font_changed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn begin_handover(&mut self) {
|
||||||
|
self.handing_over = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn console_was_taken(&self) -> bool {
|
||||||
|
self.foreground
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(ForegroundVt::taken_away)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn leave_console(&mut self) {
|
||||||
|
if let Some(foreground) = &mut self.foreground {
|
||||||
|
foreground.leave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QuietKernelConsole {
|
struct QuietKernelConsole {
|
||||||
@@ -162,6 +182,7 @@ struct VtState {
|
|||||||
struct ForegroundVt {
|
struct ForegroundVt {
|
||||||
own: u16,
|
own: u16,
|
||||||
previous: u16,
|
previous: u16,
|
||||||
|
leave: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn active_vt() -> Option<u16> {
|
fn active_vt() -> Option<u16> {
|
||||||
@@ -186,12 +207,20 @@ impl ForegroundVt {
|
|||||||
if previous != own {
|
if previous != own {
|
||||||
activate(own).ok()?;
|
activate(own).ok()?;
|
||||||
}
|
}
|
||||||
Some(Self { own, previous })
|
Some(Self {
|
||||||
|
own,
|
||||||
|
previous,
|
||||||
|
leave: false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insist(&self) -> bool {
|
fn insist(&self) -> bool {
|
||||||
active_vt().is_some_and(|active| active != self.own) && activate(self.own).is_ok()
|
active_vt().is_some_and(|active| active != self.own) && activate(self.own).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn taken_away(&self) -> bool {
|
||||||
|
active_vt().is_some_and(|active| active != self.own)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for ForegroundVt {
|
impl Drop for ForegroundVt {
|
||||||
@@ -200,6 +229,9 @@ impl Drop for ForegroundVt {
|
|||||||
eprintln!("bootvine: leaving a password prompt to the console agent on this terminal");
|
eprintln!("bootvine: leaving a password prompt to the console agent on this terminal");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if self.leave {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let _ = activate(self.previous);
|
let _ = activate(self.previous);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ pub struct LiveDesk {
|
|||||||
entry: Option<PasswordEntry>,
|
entry: Option<PasswordEntry>,
|
||||||
requests_watched: bool,
|
requests_watched: bool,
|
||||||
clear_requested: bool,
|
clear_requested: bool,
|
||||||
|
handover_deadline: Option<Duration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LiveDesk {
|
impl LiveDesk {
|
||||||
@@ -37,6 +38,7 @@ impl LiveDesk {
|
|||||||
entry: None,
|
entry: None,
|
||||||
requests_watched,
|
requests_watched,
|
||||||
clear_requested: false,
|
clear_requested: false,
|
||||||
|
handover_deadline: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +80,21 @@ impl ConsoleDesk for LiveDesk {
|
|||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn frame_passed(&mut self, _state: &mut BootState, _now: Duration) -> ControlFlow<WatchEnding> {
|
fn begin_handover(&mut self, now: Duration, hold_for: Duration) {
|
||||||
ControlFlow::Continue(())
|
self.console.begin_handover();
|
||||||
|
self.handover_deadline = Some(now + hold_for);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame_passed(&mut self, _state: &mut BootState, now: Duration) -> ControlFlow<WatchEnding> {
|
||||||
|
let Some(deadline) = self.handover_deadline else {
|
||||||
|
return ControlFlow::Continue(());
|
||||||
|
};
|
||||||
|
if self.console.console_was_taken() || now >= deadline {
|
||||||
|
self.console.leave_console();
|
||||||
|
ControlFlow::Break(WatchEnding::BootCompleted)
|
||||||
|
} else {
|
||||||
|
ControlFlow::Continue(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn password_requests_changed(&mut self) {
|
fn password_requests_changed(&mut self) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{path::Path, time::Duration};
|
use std::{path::Path, time::Duration};
|
||||||
|
|
||||||
use futures::{StreamExt, stream};
|
use futures::{StreamExt, stream};
|
||||||
use tokio::{runtime::Builder, time::sleep};
|
use tokio::runtime::Builder;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
boot_model::{BootState, Phase, boot_origin::BootOrigin},
|
boot_model::{BootState, Phase, boot_origin::BootOrigin},
|
||||||
@@ -110,9 +110,6 @@ async fn watch_live_boot(settings: &Settings, phase: Phase) -> Result<(), Error>
|
|||||||
);
|
);
|
||||||
let mut terminal = ratatui::try_init()?;
|
let mut terminal = ratatui::try_init()?;
|
||||||
let ending = watch_until_ending(&mut screen, &mut terminal, inputs).await;
|
let ending = watch_until_ending(&mut screen, &mut terminal, inputs).await;
|
||||||
if matches!(ending, WatchEnding::BootCompleted) {
|
|
||||||
sleep(settings.timing.keep_final_frame_for).await;
|
|
||||||
}
|
|
||||||
ratatui::restore();
|
ratatui::restore();
|
||||||
match ending {
|
match ending {
|
||||||
WatchEnding::Failed(error) => Err(error),
|
WatchEnding::Failed(error) => Err(error),
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ pub trait ConsoleDesk {
|
|||||||
fn refreshed_origin(&self) -> Option<BootOrigin> {
|
fn refreshed_origin(&self) -> Option<BootOrigin> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn begin_handover(&mut self, _now: Duration, _hold_for: Duration) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CachedProjection {
|
struct CachedProjection {
|
||||||
@@ -71,6 +73,7 @@ pub struct WatchScreen<Desk> {
|
|||||||
pub desk: Desk,
|
pub desk: Desk,
|
||||||
origin: BootOrigin,
|
origin: BootOrigin,
|
||||||
full_repaint_due: bool,
|
full_repaint_due: bool,
|
||||||
|
handover_begun: bool,
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
timing: Timing,
|
timing: Timing,
|
||||||
epoch: Duration,
|
epoch: Duration,
|
||||||
@@ -91,6 +94,7 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
|||||||
desk,
|
desk,
|
||||||
origin,
|
origin,
|
||||||
full_repaint_due: false,
|
full_repaint_due: false,
|
||||||
|
handover_begun: false,
|
||||||
colors,
|
colors,
|
||||||
timing,
|
timing,
|
||||||
epoch,
|
epoch,
|
||||||
@@ -106,7 +110,7 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
|||||||
fn absorb(&mut self, input: ScreenInput) -> ControlFlow<WatchEnding> {
|
fn absorb(&mut self, input: ScreenInput) -> ControlFlow<WatchEnding> {
|
||||||
let now = self.now();
|
let now = self.now();
|
||||||
match input {
|
match input {
|
||||||
ScreenInput::Boot(changes) => self.apply_boot_changes(changes),
|
ScreenInput::Boot(changes) => self.apply_boot_changes(changes, now),
|
||||||
ScreenInput::Key(event) => self.desk.press_key(&event, now),
|
ScreenInput::Key(event) => self.desk.press_key(&event, now),
|
||||||
ScreenInput::Frame => self.desk.frame_passed(&mut self.state, now),
|
ScreenInput::Frame => self.desk.frame_passed(&mut self.state, now),
|
||||||
ScreenInput::PromptCheck => {
|
ScreenInput::PromptCheck => {
|
||||||
@@ -130,7 +134,11 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_boot_changes(&mut self, changes: Vec<BootChange>) -> ControlFlow<WatchEnding> {
|
fn apply_boot_changes(
|
||||||
|
&mut self,
|
||||||
|
changes: Vec<BootChange>,
|
||||||
|
now: Duration,
|
||||||
|
) -> ControlFlow<WatchEnding> {
|
||||||
let phase_before = self.state.phase;
|
let phase_before = self.state.phase;
|
||||||
changes
|
changes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -144,11 +152,16 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
|||||||
if !self.state.is_complete() {
|
if !self.state.is_complete() {
|
||||||
return ControlFlow::Continue(());
|
return ControlFlow::Continue(());
|
||||||
}
|
}
|
||||||
eprintln!(
|
if !self.handover_begun {
|
||||||
"bootvine: {} reached, handing the console over",
|
self.handover_begun = true;
|
||||||
self.state.root.unit().unwrap_or("boot")
|
eprintln!(
|
||||||
);
|
"bootvine: {} reached, handing the console over",
|
||||||
ControlFlow::Break(WatchEnding::BootCompleted)
|
self.state.root.unit().unwrap_or("boot")
|
||||||
|
);
|
||||||
|
self.desk
|
||||||
|
.begin_handover(now, self.timing.keep_final_frame_for);
|
||||||
|
}
|
||||||
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn absorb_batch<B: Backend>(
|
fn absorb_batch<B: Backend>(
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub struct QueuedUnit {
|
|||||||
pub fn facts(name: &str, after: &[&str]) -> UnitFacts {
|
pub fn facts(name: &str, after: &[&str]) -> UnitFacts {
|
||||||
UnitFacts {
|
UnitFacts {
|
||||||
name: name.to_owned(),
|
name: name.to_owned(),
|
||||||
description: String::new(),
|
description: None,
|
||||||
after: after.iter().map(ToString::to_string).collect(),
|
after: after.iter().map(ToString::to_string).collect(),
|
||||||
before: Vec::new(),
|
before: Vec::new(),
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ impl QueuedUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn described(mut self, description: &str) -> Self {
|
pub fn described(mut self, description: &str) -> Self {
|
||||||
description.clone_into(&mut self.facts.description);
|
self.facts.description = (!description.is_empty()).then(|| description.to_owned());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ pub struct Scenario {
|
|||||||
pub phase: Phase,
|
pub phase: Phase,
|
||||||
pub steps: &'static [Step],
|
pub steps: &'static [Step],
|
||||||
pub after_switch_root: &'static [Step],
|
pub after_switch_root: &'static [Step],
|
||||||
pub describe: fn(&str) -> &'static str,
|
pub describe: fn(&str) -> Option<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ScriptedJob {
|
struct ScriptedJob {
|
||||||
@@ -93,13 +93,13 @@ struct ScriptedJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptedJob {
|
impl ScriptedJob {
|
||||||
fn facts(&self, steps: &[Step], describe: fn(&str) -> &'static str) -> UnitFacts {
|
fn facts(&self, steps: &[Step], describe: fn(&str) -> Option<&'static str>) -> UnitFacts {
|
||||||
let is_stopping = |unit: &&str| steps.iter().any(|step| step.unit == *unit && step.stops);
|
let is_stopping = |unit: &&str| steps.iter().any(|step| step.unit == *unit && step.stops);
|
||||||
let (before, after): (Vec<&str>, Vec<&str>) =
|
let (before, after): (Vec<&str>, Vec<&str>) =
|
||||||
self.step.after.iter().copied().partition(is_stopping);
|
self.step.after.iter().copied().partition(is_stopping);
|
||||||
UnitFacts {
|
UnitFacts {
|
||||||
name: self.step.unit.to_owned(),
|
name: self.step.unit.to_owned(),
|
||||||
description: describe(self.step.unit).to_owned(),
|
description: describe(self.step.unit).map(str::to_owned),
|
||||||
after: after.into_iter().map(ToString::to_string).collect(),
|
after: after.into_iter().map(ToString::to_string).collect(),
|
||||||
before: before.into_iter().map(ToString::to_string).collect(),
|
before: before.into_iter().map(ToString::to_string).collect(),
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ struct Answer {
|
|||||||
impl Script {
|
impl Script {
|
||||||
fn begin(
|
fn begin(
|
||||||
steps: &'static [Step],
|
steps: &'static [Step],
|
||||||
describe: fn(&str) -> &'static str,
|
describe: fn(&str) -> Option<&'static str>,
|
||||||
first_job: u32,
|
first_job: u32,
|
||||||
state: &mut BootState,
|
state: &mut BootState,
|
||||||
now: Duration,
|
now: Duration,
|
||||||
@@ -298,7 +298,7 @@ impl Script {
|
|||||||
struct DemoDesk {
|
struct DemoDesk {
|
||||||
script: Script,
|
script: Script,
|
||||||
after_switch_root: Option<&'static [Step]>,
|
after_switch_root: Option<&'static [Step]>,
|
||||||
describe: fn(&str) -> &'static str,
|
describe: fn(&str) -> Option<&'static str>,
|
||||||
settled_at: Option<Duration>,
|
settled_at: Option<Duration>,
|
||||||
typed: Zeroizing<String>,
|
typed: Zeroizing<String>,
|
||||||
glyphs: Glyphs,
|
glyphs: Glyphs,
|
||||||
@@ -354,8 +354,8 @@ impl ConsoleDesk for DemoDesk {
|
|||||||
fn demo_origin() -> BootOrigin {
|
fn demo_origin() -> BootOrigin {
|
||||||
BootOrigin {
|
BootOrigin {
|
||||||
host: "demo".to_owned(),
|
host: "demo".to_owned(),
|
||||||
system: "NixOS 26.11.20261007.39ad350".to_owned(),
|
system: Some("NixOS 26.11.20261007.39ad350".to_owned()),
|
||||||
generation: "42".to_owned(),
|
generation: Some("42".to_owned()),
|
||||||
kernel: "Linux 7.2.9".to_owned(),
|
kernel: "Linux 7.2.9".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,7 +420,7 @@ mod tests {
|
|||||||
|
|
||||||
fn asking_demo() -> AskingDemo {
|
fn asking_demo() -> AskingDemo {
|
||||||
let mut state = BootState::new(Phase::Initrd);
|
let mut state = BootState::new(Phase::Initrd);
|
||||||
let mut script = Script::begin(UNLOCK_ONLY, |_| "", 1, &mut state, Duration::ZERO);
|
let mut script = Script::begin(UNLOCK_ONLY, |_| None, 1, &mut state, Duration::ZERO);
|
||||||
script.advance(&mut state, Duration::ZERO);
|
script.advance(&mut state, Duration::ZERO);
|
||||||
AskingDemo { script, state }
|
AskingDemo { script, state }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,9 +209,9 @@ impl BusFeed {
|
|||||||
async fn origin_change(
|
async fn origin_change(
|
||||||
&mut self,
|
&mut self,
|
||||||
connection: &mut BusConnection,
|
connection: &mut BusConnection,
|
||||||
) -> Result<Option<BootChange>, Error> {
|
) -> Result<Vec<BootChange>, Error> {
|
||||||
if self.gave_origin {
|
if self.gave_origin {
|
||||||
return Ok(None);
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
self.gave_origin = true;
|
self.gave_origin = true;
|
||||||
let origin = if connection.boot_in_progress().await? {
|
let origin = if connection.boot_in_progress().await? {
|
||||||
@@ -219,7 +219,9 @@ impl BusFeed {
|
|||||||
} else {
|
} else {
|
||||||
monotonic_now()
|
monotonic_now()
|
||||||
};
|
};
|
||||||
Ok(Some(BootChange::SetOrigin(origin)))
|
Ok(once(BootChange::SetOrigin(origin))
|
||||||
|
.chain(self.boot_finished())
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn track_all(
|
async fn track_all(
|
||||||
@@ -347,9 +349,17 @@ impl BusFeed {
|
|||||||
})
|
})
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
|
Signal::BootFinished => self.boot_finished(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn boot_finished(&self) -> Vec<BootChange> {
|
||||||
|
(self.phase == Phase::Host)
|
||||||
|
.then_some(BootChange::BootFinished)
|
||||||
|
.into_iter()
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
async fn queue_new_job(
|
async fn queue_new_job(
|
||||||
&mut self,
|
&mut self,
|
||||||
connection: &mut BusConnection,
|
connection: &mut BusConnection,
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ pub enum Signal {
|
|||||||
path: Path<'static>,
|
path: Path<'static>,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
},
|
},
|
||||||
|
BootFinished,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FetchedUnit {
|
pub struct FetchedUnit {
|
||||||
@@ -355,7 +356,7 @@ fn unit_facts_from(name: &str, properties: &PropMap) -> UnitFacts {
|
|||||||
};
|
};
|
||||||
UnitFacts {
|
UnitFacts {
|
||||||
name: text("Id").unwrap_or_else(|| name.to_owned()),
|
name: text("Id").unwrap_or_else(|| name.to_owned()),
|
||||||
description: text("Description").unwrap_or_default(),
|
description: text("Description").filter(|description| !description.is_empty()),
|
||||||
after: names("After"),
|
after: names("After"),
|
||||||
before: names("Before"),
|
before: names("Before"),
|
||||||
}
|
}
|
||||||
@@ -386,9 +387,10 @@ fn parse_signal(message: &Message) -> Option<Signal> {
|
|||||||
}
|
}
|
||||||
let interface = message.interface()?;
|
let interface = message.interface()?;
|
||||||
let member = message.member()?;
|
let member = message.member()?;
|
||||||
match &*interface {
|
match (&*interface, &*member) {
|
||||||
MANAGER_INTERFACE => parse_job_signal(message, &member),
|
(MANAGER_INTERFACE, "JobNew" | "JobRemoved") => parse_job_signal(message, &member),
|
||||||
PROPERTIES_INTERFACE if &*member == "PropertiesChanged" => parse_unit_change(message),
|
(MANAGER_INTERFACE, "PropertiesChanged") => parse_manager_change(message),
|
||||||
|
(PROPERTIES_INTERFACE, "PropertiesChanged") => parse_unit_change(message),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,6 +425,24 @@ fn parse_unit_change(message: &Message) -> Option<Signal> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_manager_change(message: &Message) -> Option<Signal> {
|
||||||
|
let (changed_interface, changed, _invalidated): (String, PropMap, Vec<String>) =
|
||||||
|
message.read3().ok()?;
|
||||||
|
if changed_interface != MANAGER_INTERFACE {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
finish_timestamp(&changed)
|
||||||
|
.is_some()
|
||||||
|
.then_some(Signal::BootFinished)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finish_timestamp(properties: &PropMap) -> Option<u64> {
|
||||||
|
properties
|
||||||
|
.get("FinishTimestampMonotonic")
|
||||||
|
.and_then(|value| value.0.as_u64())
|
||||||
|
.filter(|micros| *micros != 0)
|
||||||
|
}
|
||||||
|
|
||||||
fn activity_from(properties: &PropMap) -> Activity {
|
fn activity_from(properties: &PropMap) -> Activity {
|
||||||
let monotonic = |property: &str| {
|
let monotonic = |property: &str| {
|
||||||
properties
|
properties
|
||||||
|
|||||||
Reference in new issue
Block a user