style: cargo fmt the nvidia changes

This commit is contained in:
Phoebus 2026-09-23 06:10:21 -07:00
parent 5103b57be9
commit 33b0b1df77
3 changed files with 46 additions and 31 deletions

View file

@ -311,8 +311,18 @@ impl NvidiaPlan {
// only accelerate one of them.
let open_only: Vec<String> = supported
.iter()
.filter(|d| d.generation.map(|g| g.requires_open_modules()).unwrap_or(false))
.map(|d| format!("{} ({})", d.pci_id, d.generation.map(|g| g.as_str()).unwrap_or("unknown")))
.filter(|d| {
d.generation
.map(|g| g.requires_open_modules())
.unwrap_or(false)
})
.map(|d| {
format!(
"{} ({})",
d.pci_id,
d.generation.map(|g| g.as_str()).unwrap_or("unknown")
)
})
.collect();
let prop_only: Vec<String> = supported
.iter()
@ -321,7 +331,13 @@ impl NvidiaPlan {
.map(|g| g.requires_proprietary_modules())
.unwrap_or(false)
})
.map(|d| format!("{} ({})", d.pci_id, d.generation.map(|g| g.as_str()).unwrap_or("unknown")))
.map(|d| {
format!(
"{} ({})",
d.pci_id,
d.generation.map(|g| g.as_str()).unwrap_or("unknown")
)
})
.collect();
return Self {
devices,
@ -623,20 +639,14 @@ impl LiveNvidiaPlan {
o.push_str(&format!(
"device={} {}\n",
device.pci_id,
device
.generation
.map(|g| g.as_str())
.unwrap_or("unknown")
device.generation.map(|g| g.as_str()).unwrap_or("unknown")
));
}
for device in &self.unclaimed {
o.push_str(&format!(
"unclaimed={} {}\n",
device.pci_id,
device
.generation
.map(|g| g.as_str())
.unwrap_or("unknown")
device.generation.map(|g| g.as_str()).unwrap_or("unknown")
));
}
o.push_str(&format!("reason={}\n", self.reason));
@ -848,7 +858,11 @@ mod tests {
assert!(!plan.supported);
assert_eq!(plan.branch, "nouveau");
assert_eq!(plan.flavor, None);
assert!(plan.reason.contains("no single NVIDIA branch"), "{}", plan.reason);
assert!(
plan.reason.contains("no single NVIDIA branch"),
"{}",
plan.reason
);
assert!(plan.gentoo_atom().is_none());
}

View file

@ -194,9 +194,7 @@ fn embedded_version(name: &str, prefix: &str) -> Option<String> {
if version.is_empty()
|| !version.chars().next()?.is_ascii_digit()
|| !version.contains('.')
|| !version
.chars()
.all(|c| c.is_ascii_digit() || c == '.')
|| !version.chars().all(|c| c.is_ascii_digit() || c == '.')
{
return None;
}
@ -470,9 +468,8 @@ pub fn verify_live_nvidia(
// The live-only load script must be present; a machine without an NVIDIA
// GPU must never record a failed unit.
let load = resolve_in_rootfs(rootfs, "usr/local/bin/phoebus-nvidia-load").filter(|p| {
size_of(p) > 0
});
let load =
resolve_in_rootfs(rootfs, "usr/local/bin/phoebus-nvidia-load").filter(|p| size_of(p) > 0);
if load.is_none() {
return Err(fail(
"usr/local/bin/phoebus-nvidia-load is missing or empty (gated driver load)".into(),
@ -567,11 +564,7 @@ mod tests {
touch(&root.join("usr/local/bin/phoebus-nvidia-load"));
let conf = root.join("etc/modprobe.d/phoebus-nvidia.conf");
std::fs::create_dir_all(conf.parent().unwrap()).unwrap();
std::fs::write(
&conf,
b"blacklist nouveau\noptions nvidia_drm modeset=1\n",
)
.unwrap();
std::fs::write(&conf, b"blacklist nouveau\noptions nvidia_drm modeset=1\n").unwrap();
}
#[test]
@ -593,8 +586,12 @@ mod tests {
complete_rootfs(dir.path());
// The dpkg version carries a Debian revision; the libs and firmware do
// not.
verify_live_nvidia(dir.path(), "550.163.01-1~deb13u1", NvidiaModuleFlavor::Proprietary)
.unwrap();
verify_live_nvidia(
dir.path(),
"550.163.01-1~deb13u1",
NvidiaModuleFlavor::Proprietary,
)
.unwrap();
}
#[test]
@ -710,8 +707,9 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
complete_rootfs(dir.path());
write_bytes(
&dir.path()
.join(format!("usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.{DRIVER}")),
&dir.path().join(format!(
"usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.{DRIVER}"
)),
1,
);
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
@ -725,8 +723,9 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
complete_rootfs(dir.path());
std::fs::rename(
dir.path()
.join(format!("usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.{DRIVER}")),
dir.path().join(format!(
"usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.{DRIVER}"
)),
dir.path()
.join("usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.999.0.0"),
)

View file

@ -256,12 +256,14 @@ pub fn probe_nvidia_display_devices(sysfs: &Path) -> Vec<GpuInfo> {
.ok()
.map(|s| s.trim().to_string())
};
let (Some(class), Some(vendor), Some(device)) = (read("class"), read("vendor"), read("device"))
let (Some(class), Some(vendor), Some(device)) =
(read("class"), read("vendor"), read("device"))
else {
continue;
};
let parse = |s: &str| u32::from_str_radix(s.trim_start_matches("0x"), 16).ok();
let (Some(class), Some(vendor), Some(device)) = (parse(&class), parse(&vendor), parse(&device))
let (Some(class), Some(vendor), Some(device)) =
(parse(&class), parse(&vendor), parse(&device))
else {
continue;
};