read arch.list
Some checks failed
Gentoo Utils / build-oci-image (push) Successful in 10s
Gentoo Utils / grep (push) Failing after 2m2s
Gentoo Utils / check-format (push) Failing after 2m6s
Gentoo Utils / docs (push) Failing after 2m5s
Gentoo Utils / build (push) Failing after 5s
Gentoo Utils / test (push) Has been skipped
Gentoo Utils / fuzz (push) Has been skipped

This commit is contained in:
2025-12-13 05:36:26 +00:00
parent 4969177893
commit 789a68ff36
5 changed files with 60 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
sources += files('mod.rs')
sources += files('mod.rs', 'parsers.rs')
subdir('ebuild')
subdir('profile')

View File

@@ -19,6 +19,7 @@ use crate::{
};
pub mod ebuild;
mod parsers;
pub mod profile;
#[derive(Debug, thiserror::Error)]
@@ -37,6 +38,9 @@ pub enum Error {
Profile(profile::Error),
}
#[derive(Debug, Clone, PartialEq, Eq, Get)]
pub struct Arch(#[get(method = "get", kind = "deref")] String);
#[derive(Debug, Clone, Get)]
pub struct Repo {
#[get(kind = "deref")]
@@ -45,6 +49,8 @@ pub struct Repo {
name: String,
#[get(kind = "deref")]
package_mask: Vec<Atom>,
#[get(kind = "deref")]
arch_list: Vec<Arch>,
}
#[derive(Debug, Clone, Get)]
@@ -80,10 +86,19 @@ impl Repo {
Err(e) => return Err(Error::Io(package_mask_path, e)),
};
let arch_list_path = path.as_ref().join("profiles/arch.list");
let arch_list = match fs::read_to_string(&arch_list_path).map(|s| read_arch_list(&s)) {
Ok(Ok(arch_list)) => arch_list,
Ok(Err(e)) => return Err(e),
Err(e) if matches!(e.kind(), io::ErrorKind::NotFound) => Vec::new(),
Err(e) => return Err(Error::Io(arch_list_path, e)),
};
Ok(Self {
path: path.as_ref().to_path_buf(),
name,
package_mask,
arch_list,
})
}
@@ -366,6 +381,20 @@ fn read_package_mask(input: &str) -> Result<Vec<Atom>, Error> {
.collect())
}
fn read_arch_list(input: &str) -> Result<Vec<Arch>, Error> {
Ok(LineBasedFileExpr::<Arch>::parser()
.separated_by_with_opt_trailing(ascii_whitespace1())
.many()
.parse_finished(InputIter::new(input))
.map_err(|it| Error::Parser(it.rest().to_string()))?
.into_iter()
.filter_map(|expr| match expr {
LineBasedFileExpr::Comment => None,
LineBasedFileExpr::Expr(arch) => Some(arch),
})
.collect())
}
fn parse_depends(line: &str) -> Result<Vec<Depend<Atom>>, Error> {
Depend::<Atom>::parser()
.separated_by(ascii_whitespace1())

20
src/repo/parsers.rs Normal file
View File

@@ -0,0 +1,20 @@
use mon::{Parser, ParserIter, ascii_alphanumeric, one_of};
use crate::{Parseable, repo::Arch};
impl<'a> Parseable<'a, &'a str> for Arch {
type Parser = impl Parser<&'a str, Output = Self>;
fn parser() -> Self::Parser {
let start = ascii_alphanumeric();
let rest = ascii_alphanumeric()
.or(one_of("-".chars()))
.repeated()
.many();
start
.and(rest)
.recognize()
.map(|output: &str| Arch(output.to_string()))
}
}

View File

@@ -0,0 +1,2 @@
amd64
aarch64

View File

@@ -18,6 +18,14 @@ fn main() {
assert_eq!(global_package_mask, vec!["app-editors/vim"]);
assert_eq!(
repo.arch_list()
.iter()
.map(|arch| arch.get())
.collect::<Vec<_>>(),
vec!["amd64", "aarch64"]
);
let profile = repo
.evaluate_profile("gentoo-desktop")
.expect("failed to evaluate profile");