2020-07-10 02:36:45 +02:00
|
|
|
package dep
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
import (
|
2020-07-10 02:36:45 +02:00
|
|
|
"fmt"
|
|
|
|
|
2019-04-23 17:53:20 +02:00
|
|
|
alpm "github.com/Jguer/go-alpm"
|
2019-01-15 19:41:38 +01:00
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2020-05-02 16:17:20 +02:00
|
|
|
|
2020-06-13 19:29:50 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
2020-07-10 02:36:45 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2019-01-15 19:41:38 +01:00
|
|
|
)
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
type Order struct {
|
2019-01-15 19:41:38 +01:00
|
|
|
Aur []Base
|
|
|
|
Repo []*alpm.Package
|
2019-10-16 23:25:40 +02:00
|
|
|
Runtime stringset.StringSet
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func makeOrder() *Order {
|
|
|
|
return &Order{
|
2019-01-15 19:41:38 +01:00
|
|
|
make([]Base, 0),
|
|
|
|
make([]*alpm.Package, 0),
|
2019-10-16 23:25:40 +02:00
|
|
|
make(stringset.StringSet),
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func GetOrder(dp *Pool) *Order {
|
|
|
|
do := makeOrder()
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (do *Order) orderPkgAur(pkg *rpc.Pkg, dp *Pool, runtime bool) {
|
2019-01-15 19:41:38 +01:00
|
|
|
if runtime {
|
2019-10-05 19:39:31 +02:00
|
|
|
do.Runtime.Set(pkg.Name)
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
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})
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (do *Order) orderPkgRepo(pkg *alpm.Package, dp *Pool, runtime bool) {
|
2019-01-15 19:41:38 +01:00
|
|
|
if runtime {
|
2019-10-05 19:39:31 +02:00
|
|
|
do.Runtime.Set(pkg.Name())
|
2019-01-15 19:41:38 +01:00
|
|
|
}
|
|
|
|
delete(dp.Repo, pkg.Name())
|
|
|
|
|
2019-10-13 13:15:51 +02:00
|
|
|
_ = pkg.Depends().ForEach(func(dep alpm.Depend) (err error) {
|
2019-01-15 19:41:38 +01:00
|
|
|
repoPkg := dp.findSatisfierRepo(dep.String())
|
|
|
|
if repoPkg != nil {
|
|
|
|
do.orderPkgRepo(repoPkg, dp, runtime)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
do.Repo = append(do.Repo, pkg)
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (do *Order) HasMake() bool {
|
2019-01-15 19:41:38 +01:00
|
|
|
lenAur := 0
|
|
|
|
for _, base := range do.Aur {
|
|
|
|
lenAur += len(base)
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(do.Runtime) != lenAur+len(do.Repo)
|
|
|
|
}
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
func (do *Order) GetMake() []string {
|
2019-09-23 01:53:59 +02:00
|
|
|
makeOnly := []string{}
|
2019-01-15 19:41:38 +01:00
|
|
|
|
|
|
|
for _, base := range do.Aur {
|
|
|
|
for _, pkg := range base {
|
2019-10-05 19:39:31 +02:00
|
|
|
if !do.Runtime.Get(pkg.Name) {
|
2019-01-15 19:41:38 +01:00
|
|
|
makeOnly = append(makeOnly, pkg.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range do.Repo {
|
2019-10-05 19:39:31 +02:00
|
|
|
if !do.Runtime.Get(pkg.Name()) {
|
2019-01-15 19:41:38 +01:00
|
|
|
makeOnly = append(makeOnly, pkg.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeOnly
|
|
|
|
}
|
2020-07-10 02:36:45 +02:00
|
|
|
|
|
|
|
// Print prints repository packages to be downloaded
|
|
|
|
func (do *Order) Print() {
|
|
|
|
repo := ""
|
|
|
|
repoMake := ""
|
|
|
|
aur := ""
|
|
|
|
aurMake := ""
|
|
|
|
|
|
|
|
repoLen := 0
|
|
|
|
repoMakeLen := 0
|
|
|
|
aurLen := 0
|
|
|
|
aurMakeLen := 0
|
|
|
|
|
|
|
|
for _, pkg := range do.Repo {
|
|
|
|
pkgStr := fmt.Sprintf(" %s-%s", pkg.Name(), pkg.Version())
|
|
|
|
if do.Runtime.Get(pkg.Name()) {
|
|
|
|
repo += pkgStr
|
|
|
|
repoLen++
|
|
|
|
} else {
|
|
|
|
repoMake += pkgStr
|
|
|
|
repoMakeLen++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, base := range do.Aur {
|
|
|
|
pkg := base.Pkgbase()
|
|
|
|
pkgStr := " " + pkg + "-" + base[0].Version
|
|
|
|
pkgStrMake := pkgStr
|
|
|
|
|
|
|
|
push := false
|
|
|
|
pushMake := false
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case len(base) > 1, pkg != base[0].Name:
|
|
|
|
pkgStr += " ("
|
|
|
|
pkgStrMake += " ("
|
|
|
|
|
|
|
|
for _, split := range base {
|
|
|
|
if do.Runtime.Get(split.Name) {
|
|
|
|
pkgStr += split.Name + " "
|
|
|
|
aurLen++
|
|
|
|
push = true
|
|
|
|
} else {
|
|
|
|
pkgStrMake += split.Name + " "
|
|
|
|
aurMakeLen++
|
|
|
|
pushMake = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgStr = pkgStr[:len(pkgStr)-1] + ")"
|
|
|
|
pkgStrMake = pkgStrMake[:len(pkgStrMake)-1] + ")"
|
|
|
|
case do.Runtime.Get(base[0].Name):
|
|
|
|
aurLen++
|
|
|
|
push = true
|
|
|
|
default:
|
|
|
|
aurMakeLen++
|
|
|
|
pushMake = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if push {
|
|
|
|
aur += pkgStr
|
|
|
|
}
|
|
|
|
if pushMake {
|
|
|
|
aurMake += pkgStrMake
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printDownloads("Repo", repoLen, repo)
|
|
|
|
printDownloads("Repo Make", repoMakeLen, repoMake)
|
|
|
|
printDownloads("Aur", aurLen, aur)
|
|
|
|
printDownloads("Aur Make", aurMakeLen, aurMake)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printDownloads(repoName string, length int, packages string) {
|
|
|
|
if length < 1 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
repoInfo := fmt.Sprintf(text.Bold(text.Blue("[%s:%d]")), repoName, length)
|
|
|
|
fmt.Println(repoInfo + text.Cyan(packages))
|
|
|
|
}
|