-
Notifications
You must be signed in to change notification settings - Fork 0
/
depOrder.go
140 lines (113 loc) · 2.71 KB
/
depOrder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
alpm "github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v9/pkg/stringset"
rpc "github.com/mikkeloscar/aur"
)
// Base is an AUR base package
type Base []*rpc.Pkg
// Pkgbase returns the first base package.
func (b Base) Pkgbase() string {
return b[0].PackageBase
}
// Version returns the first base package version.
func (b Base) Version() string {
return b[0].Version
}
// URLPath returns the first base package URL.
func (b Base) URLPath() string {
return b[0].URLPath
}
type depOrder struct {
Aur []Base
Repo []*alpm.Package
Runtime stringset.StringSet
}
func makeDepOrder() *depOrder {
return &depOrder{
make([]Base, 0),
make([]*alpm.Package, 0),
make(stringset.StringSet),
}
}
func getDepOrder(dp *depPool) *depOrder {
do := makeDepOrder()
for _, target := range dp.Targets {
dep := target.DepString()
aurPkg := dp.Aur[dep]
if aurPkg != nil && pkgSatisfies(aurPkg.Name, aurPkg.Version, dep) {
do.orderPkgAur(aurPkg, dp, true)
}
aurPkg = dp.findSatisfierAur(dep)
if aurPkg != nil {
do.orderPkgAur(aurPkg, dp, true)
}
repoPkg := dp.findSatisfierRepo(dep)
if repoPkg != nil {
do.orderPkgRepo(repoPkg, dp, true)
}
}
return do
}
func (do *depOrder) orderPkgAur(pkg *rpc.Pkg, dp *depPool, runtime bool) {
if runtime {
do.Runtime.Set(pkg.Name)
}
delete(dp.Aur, pkg.Name)
for i, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
for _, dep := range deps {
aurPkg := dp.findSatisfierAur(dep)
if aurPkg != nil {
do.orderPkgAur(aurPkg, dp, runtime && i == 0)
}
repoPkg := dp.findSatisfierRepo(dep)
if repoPkg != nil {
do.orderPkgRepo(repoPkg, dp, runtime && i == 0)
}
}
}
for i, base := range do.Aur {
if base.Pkgbase() == pkg.PackageBase {
do.Aur[i] = append(base, pkg)
return
}
}
do.Aur = append(do.Aur, Base{pkg})
}
func (do *depOrder) orderPkgRepo(pkg *alpm.Package, dp *depPool, runtime bool) {
if runtime {
do.Runtime.Set(pkg.Name())
}
delete(dp.Repo, pkg.Name())
_ = pkg.Depends().ForEach(func(dep alpm.Depend) (err error) {
repoPkg := dp.findSatisfierRepo(dep.String())
if repoPkg != nil {
do.orderPkgRepo(repoPkg, dp, runtime)
}
return nil
})
do.Repo = append(do.Repo, pkg)
}
func (do *depOrder) HasMake() bool {
lenAur := 0
for _, base := range do.Aur {
lenAur += len(base)
}
return len(do.Runtime) != lenAur+len(do.Repo)
}
func (do *depOrder) getMake() []string {
makeOnly := []string{}
for _, base := range do.Aur {
for _, pkg := range base {
if !do.Runtime.Get(pkg.Name) {
makeOnly = append(makeOnly, pkg.Name)
}
}
}
for _, pkg := range do.Repo {
if !do.Runtime.Get(pkg.Name()) {
makeOnly = append(makeOnly, pkg.Name())
}
}
return makeOnly
}