From 2729c33aa6bad65ae834314d1effe7c4fe1ab4da Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 20 Apr 2024 11:51:35 -0400 Subject: [PATCH 1/2] chore: Update akmods to account for upstream changes --- .../test-repo/recipes/akmods.yml | 4 +-- recipe/src/module.rs | 36 +++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/integration-tests/test-repo/recipes/akmods.yml b/integration-tests/test-repo/recipes/akmods.yml index 68125de3..06078bd5 100644 --- a/integration-tests/test-repo/recipes/akmods.yml +++ b/integration-tests/test-repo/recipes/akmods.yml @@ -4,7 +4,7 @@ modules: # Tests installing rpms from a combo image stage - type: akmods base: surface - nvidia-version: 545 + nvidia: true # install: # - nvidia # - openrazer @@ -15,7 +15,7 @@ modules: # Tests pulling image for main nvidia - type: akmods - nvidia-version: 545 + nvidia: true # Test pulling image for base asus - type: akmods diff --git a/recipe/src/module.rs b/recipe/src/module.rs index 306a882b..e0636cf2 100644 --- a/recipe/src/module.rs +++ b/recipe/src/module.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, process}; use anyhow::{bail, Result}; use indexmap::IndexMap; -use log::{error, trace}; +use log::{error, trace, warn}; use serde::{Deserialize, Serialize}; use serde_yaml::Value; use typed_builder::TypedBuilder; @@ -88,6 +88,7 @@ impl<'a> Module<'a> { }) } + #[must_use] pub fn generate_akmods_info(&'a self, os_version: &str) -> AkmodsInfo { trace!("generate_akmods_base({self:#?}, {os_version})"); @@ -95,28 +96,41 @@ impl<'a> Module<'a> { .config .get("base") .map(|b| b.as_str().unwrap_or_default()); - let nvidia_version = self - .config - .get("nvidia-version") - .map(|v| v.as_u64().unwrap_or_default()); + let nvidia = self.config.get("nvidia-version").map_or_else( + || { + self.config + .get("nvidia") + .is_some_and(|v| v.as_bool().unwrap_or_default()) + }, + |_| { + warn!( + "The `nvidia-version` property is deprecated, replace it with `nvidia: true`" + ); + true + }, + ); AkmodsInfo::builder() - .images(match (base, nvidia_version) { - (Some(b), Some(nv)) if !b.is_empty() && nv > 0 => ( + .images(match (base, nvidia) { + (Some(b), nv) if !b.is_empty() && nv => ( format!("akmods:{b}-{os_version}"), - Some(format!("akmods-nvidia:{b}-{os_version}-{nv}")), + Some(format!("akmods-nvidia:{b}-{os_version}")), ), (Some(b), _) if !b.is_empty() => (format!("akmods:{b}-{os_version}"), None), - (_, Some(nv)) if nv > 0 => ( + (_, nv) if nv => ( format!("akmods:main-{os_version}"), - Some(format!("akmods-nvidia:main-{os_version}-{nv}")), + Some(format!("akmods-nvidia:main-{os_version}")), ), _ => (format!("akmods:main-{os_version}"), None), }) .stage_name(format!( "{}{}", base.unwrap_or("main"), - nvidia_version.map_or_else(String::default, |nv| format!("-{nv}")) + if nvidia { + "-nvidia".to_string() + } else { + String::default() + } )) .build() } From dc92e9395dbeabf8b5a19488b63061c02e55477d Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 20 Apr 2024 12:08:45 -0400 Subject: [PATCH 2/2] Still support using deprecated versioned images --- recipe/src/module.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/recipe/src/module.rs b/recipe/src/module.rs index e0636cf2..04a9235c 100644 --- a/recipe/src/module.rs +++ b/recipe/src/module.rs @@ -90,6 +90,12 @@ impl<'a> Module<'a> { #[must_use] pub fn generate_akmods_info(&'a self, os_version: &str) -> AkmodsInfo { + #[derive(Debug, Copy, Clone)] + enum NvidiaAkmods { + Nvidia(bool), + Version(u64), + } + trace!("generate_akmods_base({self:#?}, {os_version})"); let base = self @@ -100,36 +106,44 @@ impl<'a> Module<'a> { || { self.config .get("nvidia") - .is_some_and(|v| v.as_bool().unwrap_or_default()) + .map_or_else(|| NvidiaAkmods::Nvidia(false), |v| NvidiaAkmods::Nvidia(v.as_bool().unwrap_or_default())) }, - |_| { + |v| { warn!( - "The `nvidia-version` property is deprecated, replace it with `nvidia: true`" + "The `nvidia-version` property is deprecated as upstream images may no longer exist, replace it with `nvidia: true`" ); - true + NvidiaAkmods::Version(v.as_u64().unwrap_or_default()) }, ); AkmodsInfo::builder() .images(match (base, nvidia) { - (Some(b), nv) if !b.is_empty() && nv => ( + (Some(b), NvidiaAkmods::Nvidia(nv)) if !b.is_empty() && nv => ( format!("akmods:{b}-{os_version}"), Some(format!("akmods-nvidia:{b}-{os_version}")), ), + (Some(b), NvidiaAkmods::Version(nv)) if !b.is_empty() && nv > 0 => ( + format!("akmods:{b}-{os_version}"), + Some(format!("akmods-nvidia:{b}-{os_version}-{nv}")), + ), (Some(b), _) if !b.is_empty() => (format!("akmods:{b}-{os_version}"), None), - (_, nv) if nv => ( + (_, NvidiaAkmods::Nvidia(nv)) if nv => ( format!("akmods:main-{os_version}"), Some(format!("akmods-nvidia:main-{os_version}")), ), + (_, NvidiaAkmods::Version(nv)) if nv > 0 => ( + format!("akmods:main-{os_version}"), + Some(format!("akmods-nvidia:main-{os_version}-{nv}")), + ), _ => (format!("akmods:main-{os_version}"), None), }) .stage_name(format!( "{}{}", base.unwrap_or("main"), - if nvidia { - "-nvidia".to_string() - } else { - String::default() + match nvidia { + NvidiaAkmods::Nvidia(nv) if nv => "-nvidia".to_string(), + NvidiaAkmods::Version(nv) if nv > 0 => format!("-nvidia-{nv}"), + _ => String::default(), } )) .build()