Skip to content

Commit

Permalink
feat(core): account for provides in depgraph visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Jun 6, 2024
1 parent 8598155 commit f5c5794
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 46 deletions.
94 changes: 48 additions & 46 deletions rust/aura-core/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,38 @@ impl<'a> PkgGraph<'a> {
where
D: DbLike,
{
indices.get(parent).cloned().or_else(|| {
db.get_pkg(parent).ok().map(|p| {
let ix = graph.add_node((parent, p.groups().first()));
indices.insert(parent, ix);
let next = limit.map(|l| l - 1);

if next.is_none() || next > Some(0) {
// Dependencies required at runtime.
for d in p.depends().iter() {
let true_pkg = db.get_pkg(parent).ok().or_else(|| db.provides(parent))?;
let name = true_pkg.name();
debug!("Found {} providing {}", name, parent);

indices.get(name).cloned().or_else(|| {
let ix = graph.add_node((name, true_pkg.groups().first()));
debug!("Added {} at {}", name, ix.index());
indices.insert(name, ix);
let next = limit.map(|l| l - 1);

if next.is_none() || next > Some(0) {
// Dependencies required at runtime.
for d in true_pkg.depends().iter() {
if let Some(dix) =
PkgGraph::add_dep(db, graph, indices, next, optional, d.name())
{
graph.update_edge(ix, dix, DepType::Hard);
}
}

if optional {
for d in true_pkg.optdepends().iter() {
if let Some(dix) =
PkgGraph::add_dep(db, graph, indices, next, optional, d.name())
{
graph.add_edge(ix, dix, DepType::Hard);
}
}

if optional {
for d in p.optdepends().iter() {
if let Some(dix) =
PkgGraph::add_dep(db, graph, indices, next, optional, d.name())
{
graph.add_edge(ix, dix, DepType::Opt);
}
graph.update_edge(ix, dix, DepType::Opt);
}
}
}
}

ix
})
Some(ix)
})
}

Expand All @@ -153,37 +156,36 @@ impl<'a> PkgGraph<'a> {
where
D: DbLike,
{
indices.get(child).cloned().or_else(|| {
db.get_pkg(child).ok().map(|p| {
// We pull the name back out of the summoned `Package` instead
// of using the given `child: &str` to avoid lifetime issues.
let name = p.name();
let ix = graph.add_node((name, p.groups().first()));
indices.insert(name, ix);
let next = limit.map(|l| l - 1);

if next.is_none() || next > Some(0) {
for parent in p.required_by() {
let true_pkg = db.get_pkg(child).ok().or_else(|| db.provides(child))?;
let name = true_pkg.name();
debug!("Found {} providing {}", name, child);

indices.get(name).cloned().or_else(|| {
let ix = graph.add_node((name, true_pkg.groups().first()));
indices.insert(name, ix);
let next = limit.map(|l| l - 1);

if next.is_none() || next > Some(0) {
for parent in true_pkg.required_by() {
if let Some(pix) =
PkgGraph::add_parent(db, graph, indices, next, optional, &parent)
{
graph.update_edge(pix, ix, DepType::Hard);
}
}

if optional {
for parent in true_pkg.optional_for() {
if let Some(pix) =
PkgGraph::add_parent(db, graph, indices, next, optional, &parent)
{
graph.add_edge(pix, ix, DepType::Hard);
}
}

if optional {
for parent in p.optional_for() {
if let Some(pix) =
PkgGraph::add_parent(db, graph, indices, next, optional, &parent)
{
graph.add_edge(pix, ix, DepType::Opt);
}
graph.update_edge(pix, ix, DepType::Opt);
}
}
}
}

ix
})
Some(ix)
})
}
}
Expand Down
26 changes: 26 additions & 0 deletions rust/aura-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ pub trait DbLike {
fn get_pkg<'a, S>(&'a self, name: S) -> Result<&'a alpm::Package, alpm::Error>
where
S: Into<Vec<u8>>;

/// Find a package that provides some name.
fn provides<'a, S>(&'a self, name: S) -> Option<&'a alpm::Package>
where
S: Into<Vec<u8>>;
}

impl DbLike for Db {
Expand All @@ -35,6 +40,13 @@ impl DbLike for Db {
{
self.pkg(name)
}

fn provides<'a, S>(&'a self, _: S) -> Option<&'a alpm::Package>
where
S: Into<Vec<u8>>,
{
None
}
}

impl DbLike for AlpmList<'_, &Db> {
Expand All @@ -44,6 +56,13 @@ impl DbLike for AlpmList<'_, &Db> {
{
self.pkg(name)
}

fn provides<'a, S>(&'a self, name: S) -> Option<&'a alpm::Package>
where
S: Into<Vec<u8>>,
{
self.find_satisfier(name)
}
}

/// A combination of both database sources.
Expand Down Expand Up @@ -74,6 +93,13 @@ impl<'b, 'c> DbLike for Dbs<'b, 'c> {
.get_pkg(v.clone())
.or_else(|_| self.syncs.get_pkg(v))
}

fn provides<'a, S>(&'a self, name: S) -> Option<&'a alpm::Package>
where
S: Into<Vec<u8>>,
{
self.syncs.find_satisfier(name)
}
}

/// The simplest form a package.
Expand Down

0 comments on commit f5c5794

Please sign in to comment.