mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-17 15:34:18 +08:00
Detect version and provide manual version metadata
This commit is contained in:
parent
ae06273f81
commit
485b6dd82d
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1888,6 +1888,7 @@ dependencies = [
|
||||
"pkgar-keys 0.1.19",
|
||||
"redox-pkg 0.2.8",
|
||||
"redoxer",
|
||||
"regex",
|
||||
"serde",
|
||||
"tempfile",
|
||||
"termion",
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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<String> {
|
||||
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<PackageName>,
|
||||
#[serde(default)]
|
||||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user