Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Aug 23, 2022
1 parent cce21ce commit a4565b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
19 changes: 11 additions & 8 deletions local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,23 @@ func installLocalPKGBUILD(
func addNodes(dbExecutor db.Executor, aurClient aur.ClientInterface, pkgName string, pkgBase string, deps []string, graph *topo.Graph[string]) {
graph.AddNode(pkgBase)
graph.Alias(pkgBase, pkgName)
graph.SetNodeInfo(pkgBase, &topo.NodeInfo{Color: "blue"})

for _, depString := range deps {
depName, _, _ := splitDep(depString)

graph.DependOn(depName, pkgBase)

warnings := query.AURWarnings{}

if dbExecutor.LocalSatisfierExists(depString) {
graph.SetNodeInfo(depName, &topo.NodeInfo{Color: "green"})
continue
} else {
graph.SetNodeInfo(depName, &topo.NodeInfo{Color: "red"})
}

graph.DependOn(depName, pkgBase)

// Check ALPM
if alpmPkg := dbExecutor.SyncSatisfier(depString); alpmPkg != nil {
newDeps := alpmPkg.Depends().Slice()
newDepsSlice := make([]string, 0, len(newDeps))
Expand All @@ -151,17 +158,13 @@ func addNodes(dbExecutor db.Executor, aurClient aur.ClientInterface, pkgName str
}

addNodes(dbExecutor, aurClient, alpmPkg.Name(), alpmPkg.Base(), newDepsSlice, graph)
}

warnings := query.AURWarnings{}
if aurPkgs, _ := query.AURInfo(context.TODO(), aurClient, []string{depName}, &warnings, 1); len(aurPkgs) != 0 {
// Check AUR
} else if aurPkgs, _ := query.AURInfo(context.TODO(), aurClient, []string{depName}, &warnings, 1); len(aurPkgs) != 0 {
pkg := aurPkgs[0]
newDeps := dep.ComputeCombinedDepList(pkg, false, false)
newDepsSlice := make([]string, 0, len(newDeps))

addNodes(dbExecutor, aurClient, pkg.PackageBase, pkg.Name, newDepsSlice, graph)
}
}

return
}
31 changes: 29 additions & 2 deletions pkg/topo/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ type (
DepMap[T comparable] map[T]NodeSet[T]
)

type NodeInfo struct {
Color string
}

type Graph[T comparable] struct {
alias AliasMap[T]
nodes NodeSet[T]

// node info map
nodeInfo map[T]NodeInfo

// `dependencies` tracks child -> parents.
dependencies DepMap[T]
// `dependents` tracks parent -> children.
Expand All @@ -32,6 +39,7 @@ func New[T comparable]() *Graph[T] {
dependencies: make(DepMap[T]),
dependents: make(DepMap[T]),
alias: make(AliasMap[T]),
nodeInfo: make(map[T]NodeInfo),
}
}

Expand Down Expand Up @@ -61,6 +69,15 @@ func (g *Graph[T]) AddNode(node T) {
g.nodes[node] = true
}

func (g *Graph[T]) SetNodeInfo(node T, nodeInfo *NodeInfo) {
// check aliases
if aliasNode, ok := g.alias[node]; ok {
node = aliasNode
}

g.nodeInfo[node] = *nodeInfo
}

func (g *Graph[T]) DependOn(child, parent T) error {
if child == parent {
return ErrSelfReferential
Expand All @@ -87,11 +104,21 @@ func (g *Graph[T]) DependOn(child, parent T) error {
func (g *Graph[T]) String() string {
var sb strings.Builder
sb.WriteString("digraph {\n")
// sb.WriteString("rankdir=LR;\n")
sb.WriteString("compound=true;\n")
sb.WriteString("concentrate=true;\n")
sb.WriteString("node [shape = record, ordering=out];\n")

for node := range g.nodes {
sb.WriteString(fmt.Sprintf("\t\"%v\";\n", node))
extra := ""
if info, ok := g.nodeInfo[node]; ok {
if info.Color != "" {
extra = fmt.Sprintf("[color = %s]", info.Color)
}
}

sb.WriteString(fmt.Sprintf("\t\"%v\"%s;\n", node, extra))
}

for parent, children := range g.dependencies {
for child := range children {
sb.WriteString(fmt.Sprintf("\t\"%v\" -> \"%v\";\n", parent, child))
Expand Down

0 comments on commit a4565b3

Please sign in to comment.