read global package.mask

This commit is contained in:
2025-12-13 04:49:28 +00:00
parent fd3efced29
commit 4969177893
4 changed files with 39 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),
} }

View File

@@ -0,0 +1 @@
app-editors/vim

View File

@@ -8,6 +8,16 @@ fn main() {
.nth(1) .nth(1)
.expect("expected path to mockrepo as first argument"); .expect("expected path to mockrepo as first argument");
let repo = Repo::new(&repo_path).expect("failed to read repo"); let repo = Repo::new(&repo_path).expect("failed to read repo");
let global_package_mask = repo
.package_mask()
.iter()
.map(Atom::to_string)
.sorted()
.collect::<Vec<_>>();
assert_eq!(global_package_mask, vec!["app-editors/vim"]);
let profile = repo let profile = repo
.evaluate_profile("gentoo-desktop") .evaluate_profile("gentoo-desktop")
.expect("failed to evaluate profile"); .expect("failed to evaluate profile");