2020-07-10 00:36:45 +00:00
|
|
|
package dep
|
2019-01-15 18:41:38 +00:00
|
|
|
|
|
|
|
import (
|
2020-07-10 00:36:45 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-10-01 11:38:03 +00:00
|
|
|
alpm "github.com/Jguer/go-alpm/v2"
|
|
|
|
|
2021-02-16 15:10:04 +00:00
|
|
|
rpc "github.com/Jguer/yay/v10/pkg/query"
|
2020-06-13 17:29:50 +00:00
|
|
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
2020-07-10 00:36:45 +00:00
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2019-01-15 18:41:38 +00:00
|
|
|
)
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
type Order struct {
|
2019-01-15 18:41:38 +00:00
|
|
|
Aur []Base
|
2020-10-01 11:38:03 +00:00
|
|
|
Repo []alpm.IPackage
|
2019-10-16 21:25:40 +00:00
|
|
|
Runtime stringset.StringSet
|
2019-01-15 18:41:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
func makeOrder() *Order {
|
|
|
|
return &Order{
|
2019-01-15 18:41:38 +00:00
|
|
|
make([]Base, 0),
|
2020-10-01 11:38:03 +00:00
|
|
|
make([]alpm.IPackage, 0),
|
2019-10-16 21:25:40 +00:00
|
|
|
make(stringset.StringSet),
|
2019-01-15 18:41:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
func GetOrder(dp *Pool) *Order {
|
|
|
|
do := makeOrder()
|
2019-01-15 18:41:38 +00: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 00:36:45 +00:00
|
|
|
func (do *Order) orderPkgAur(pkg *rpc.Pkg, dp *Pool, runtime bool) {
|
2019-01-15 18:41:38 +00:00
|
|
|
if runtime {
|
2019-10-05 17:39:31 +00:00
|
|
|
do.Runtime.Set(pkg.Name)
|
2019-01-15 18:41:38 +00: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-10-01 11:38:03 +00:00
|
|
|
func (do *Order) orderPkgRepo(pkg alpm.IPackage, dp *Pool, runtime bool) {
|
2019-01-15 18:41:38 +00:00
|
|
|
if runtime {
|
2019-10-05 17:39:31 +00:00
|
|
|
do.Runtime.Set(pkg.Name())
|
2019-01-15 18:41:38 +00:00
|
|
|
}
|
|
|
|
delete(dp.Repo, pkg.Name())
|
|
|
|
|
2020-07-28 23:53:25 +00:00
|
|
|
for _, dep := range dp.AlpmExecutor.PackageDepends(pkg) {
|
2019-01-15 18:41:38 +00:00
|
|
|
repoPkg := dp.findSatisfierRepo(dep.String())
|
|
|
|
if repoPkg != nil {
|
|
|
|
do.orderPkgRepo(repoPkg, dp, runtime)
|
|
|
|
}
|
2020-07-28 23:53:25 +00:00
|
|
|
}
|
2019-01-15 18:41:38 +00:00
|
|
|
|
|
|
|
do.Repo = append(do.Repo, pkg)
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
func (do *Order) HasMake() bool {
|
2019-01-15 18:41:38 +00:00
|
|
|
lenAur := 0
|
|
|
|
for _, base := range do.Aur {
|
|
|
|
lenAur += len(base)
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(do.Runtime) != lenAur+len(do.Repo)
|
|
|
|
}
|
|
|
|
|
2020-07-10 00:36:45 +00:00
|
|
|
func (do *Order) GetMake() []string {
|
2019-09-22 23:53:59 +00:00
|
|
|
makeOnly := []string{}
|
2019-01-15 18:41:38 +00:00
|
|
|
|
|
|
|
for _, base := range do.Aur {
|
|
|
|
for _, pkg := range base {
|
2019-10-05 17:39:31 +00:00
|
|
|
if !do.Runtime.Get(pkg.Name) {
|
2019-01-15 18:41:38 +00:00
|
|
|
makeOnly = append(makeOnly, pkg.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range do.Repo {
|
2019-10-05 17:39:31 +00:00
|
|
|
if !do.Runtime.Get(pkg.Name()) {
|
2019-01-15 18:41:38 +00:00
|
|
|
makeOnly = append(makeOnly, pkg.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeOnly
|
|
|
|
}
|
2020-07-10 00:36:45 +00: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))
|
|
|
|
}
|