From 485b6dd82d9a1487912a0083dbaf74132642b14c Mon Sep 17 00:00:00 2001 From: Wildan M Date: Mon, 6 Oct 2025 13:49:14 +0700 Subject: [PATCH] Detect version and provide manual version metadata --- Cargo.lock | 1 + Cargo.toml | 1 + src/bin/cook.rs | 8 ++++++++ src/recipe.rs | 35 +++++++++++++++++++++++++++++------ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b8f1fd3..0dd230b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1888,6 +1888,7 @@ dependencies = [ "pkgar-keys 0.1.19", "redox-pkg 0.2.8", "redoxer", + "regex", "serde", "tempfile", "termion", diff --git a/Cargo.toml b/Cargo.toml index b4695bef..b334424a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ pkgar-core = { path = "pkgar/pkgar-core" } pkgar-keys = { path = "pkgar/pkgar-keys" } redox-pkg = { git = "https://gitlab.redox-os.org/redox-os/pkgutils" } redoxer = "0.2" +regex = "1.11" serde = { version = "=1.0.197", features = ["derive"] } termion = "4" toml = "0.8" diff --git a/src/bin/cook.rs b/src/bin/cook.rs index 437c00b6..c1b3bc94 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -1308,6 +1308,14 @@ fn package_toml( fn package_version(recipe: &Recipe) -> String { if recipe.build.kind == BuildKind::None { "".into() + } else if let Some(v) = &recipe.package.version { + v.to_string() + } else if let Some(r) = &recipe.source { + if let Some(m) = r.guess_version() { + m + } else { + "TODO".into() + } } else { "TODO".into() } diff --git a/src/recipe.rs b/src/recipe.rs index 06c49e68..deed2ce4 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -1,6 +1,7 @@ use std::{collections::BTreeSet, convert::TryInto, fs, path::PathBuf}; use pkg::{package::PackageError, recipes, PackageName}; +use regex::Regex; use serde::{ de::{value::Error as DeError, Error as DeErrorT}, Deserialize, Serialize, @@ -61,6 +62,26 @@ pub enum SourceRecipe { }, } +impl SourceRecipe { + pub fn guess_version(&self) -> Option { + match self { + SourceRecipe::Tar { + tar, + blake3: _, + patches: _, + script: _, + } => { + let re = Regex::new(r"\d+\.\d+\.\d+").unwrap(); + if let Some(arm) = re.captures(&tar) { + return Some(arm.get(0).unwrap().as_str().to_string()); + } + None + } + _ => None, + } + } +} + /// Specifies how to build a recipe #[derive(Debug, Deserialize, PartialEq, Serialize)] #[serde(tag = "template")] @@ -117,6 +138,8 @@ pub struct BuildRecipe { pub struct PackageRecipe { #[serde(default)] pub dependencies: Vec, + #[serde(default)] + pub version: Option, } /// Everything required to build a Redox package @@ -293,9 +316,7 @@ mod tests { }, dependencies: Vec::new(), }, - package: PackageRecipe { - dependencies: Vec::new(), - }, + package: PackageRecipe::default(), } ); } @@ -335,11 +356,12 @@ mod tests { }, dependencies: Vec::new(), }, - package: PackageRecipe { - dependencies: Vec::new(), - }, + package: PackageRecipe::default(), } ); + + let source = recipe.source.unwrap(); + assert_eq!(source.guess_version(), Some("1.3.3".to_string())); } #[test] @@ -366,6 +388,7 @@ mod tests { }, package: PackageRecipe { dependencies: vec![PackageName::new("gcc13").unwrap()], + version: None, }, } );