parse arch.list
All checks were successful
Gentoo Utils / build-oci-image (push) Successful in 17s
Gentoo Utils / check-format (push) Successful in 1m46s
Gentoo Utils / docs (push) Successful in 1m50s
Gentoo Utils / build (push) Successful in 2m1s
Gentoo Utils / test (push) Successful in 32s

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

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())