read global package.mask
All checks were successful
Gentoo Utils / build-oci-image (pull_request) Successful in 3s
Gentoo Utils / build (pull_request) Successful in 44s

This commit is contained in:
2025-12-13 04:49:28 +00:00
parent 6194121072
commit b929ddcafe
2 changed files with 28 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ use crate::{
atom::{self, Atom}, atom::{self, Atom},
repo::{ repo::{
ebuild::{Depend, Eapi, Ebuild, Eclass, License, SrcUri}, ebuild::{Depend, Eapi, Ebuild, Eclass, License, SrcUri},
profile::Profile, profile::{LineBasedFileExpr, Profile},
}, },
useflag::IUseFlag, useflag::IUseFlag,
}; };
@@ -43,6 +43,8 @@ pub struct Repo {
path: PathBuf, path: PathBuf,
#[get(kind = "deref")] #[get(kind = "deref")]
name: String, name: String,
#[get(kind = "deref")]
package_mask: Vec<Atom>,
} }
#[derive(Debug, Clone, Get)] #[derive(Debug, Clone, Get)]
@@ -69,9 +71,19 @@ impl Repo {
Err(e) => return Err(Error::Io(name_path, e)), Err(e) => return Err(Error::Io(name_path, e)),
}; };
let package_mask_path = path.as_ref().join("profiles/package.mask");
let package_mask =
match fs::read_to_string(&package_mask_path).map(|s| read_package_mask(&s)) {
Ok(Ok(package_mask)) => package_mask,
Ok(Err(e)) => return Err(e),
Err(e) if matches!(e.kind(), io::ErrorKind::NotFound) => Vec::new(),
Err(e) => return Err(Error::Io(package_mask_path, e)),
};
Ok(Self { Ok(Self {
path: path.as_ref().to_path_buf(), path: path.as_ref().to_path_buf(),
name, name,
package_mask,
}) })
} }
@@ -340,6 +352,20 @@ fn read_idepend(input: &str) -> Option<Result<Vec<Depend<Atom>>, Error>> {
Some(parse_depends(line)) Some(parse_depends(line))
} }
fn read_package_mask(input: &str) -> Result<Vec<Atom>, Error> {
Ok(profile::LineBasedFileExpr::<Atom>::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(atom) => Some(atom),
})
.collect())
}
fn parse_depends(line: &str) -> Result<Vec<Depend<Atom>>, Error> { fn parse_depends(line: &str) -> Result<Vec<Depend<Atom>>, Error> {
Depend::<Atom>::parser() Depend::<Atom>::parser()
.separated_by(ascii_whitespace1()) .separated_by(ascii_whitespace1())

View File

@@ -32,7 +32,7 @@ mod parsers;
mod useflags; mod useflags;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum LineBasedFileExpr<T> { pub(super) enum LineBasedFileExpr<T> {
Comment, Comment,
Expr(T), Expr(T),
} }