2017-08-02 17:24:03 +00:00
|
|
|
package main
|
|
|
|
|
2017-08-07 13:43:25 +00:00
|
|
|
import (
|
2018-03-16 19:30:14 +00:00
|
|
|
"fmt"
|
2018-03-02 11:32:35 +00:00
|
|
|
"strings"
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
alpm "github.com/jguer/go-alpm"
|
2018-01-20 22:37:10 +00:00
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2018-03-15 13:51:37 +00:00
|
|
|
gopkg "github.com/mikkeloscar/gopkgbuild"
|
2017-08-07 13:43:25 +00:00
|
|
|
)
|
2017-08-04 09:26:53 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
type depTree struct {
|
2018-02-17 23:35:54 +00:00
|
|
|
ToProcess stringSet
|
2018-01-20 22:37:10 +00:00
|
|
|
Repo map[string]*alpm.Package
|
|
|
|
Aur map[string]*rpc.Pkg
|
|
|
|
Missing stringSet
|
2018-03-16 19:30:14 +00:00
|
|
|
Groups stringSet
|
2018-03-29 05:01:02 +00:00
|
|
|
Provides map[string]string
|
2018-04-11 03:43:51 +00:00
|
|
|
Warnings *aurWarnings
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type depCatagories struct {
|
2018-01-20 22:37:10 +00:00
|
|
|
Repo []*alpm.Package
|
2018-02-16 17:18:59 +00:00
|
|
|
Aur []*rpc.Pkg
|
2018-02-15 21:23:34 +00:00
|
|
|
MakeOnly stringSet
|
2018-02-16 17:18:59 +00:00
|
|
|
Bases map[string][]*rpc.Pkg
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func makeDepTree() *depTree {
|
|
|
|
dt := depTree{
|
2018-02-17 23:35:54 +00:00
|
|
|
make(stringSet),
|
2018-01-17 21:48:23 +00:00
|
|
|
make(map[string]*alpm.Package),
|
|
|
|
make(map[string]*rpc.Pkg),
|
|
|
|
make(stringSet),
|
2018-03-16 19:30:14 +00:00
|
|
|
make(stringSet),
|
2018-03-29 05:01:02 +00:00
|
|
|
make(map[string]string),
|
2018-04-11 03:43:51 +00:00
|
|
|
&aurWarnings{},
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return &dt
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeDependCatagories() *depCatagories {
|
|
|
|
dc := depCatagories{
|
|
|
|
make([]*alpm.Package, 0),
|
|
|
|
make([]*rpc.Pkg, 0),
|
2018-02-15 21:23:34 +00:00
|
|
|
make(stringSet),
|
|
|
|
make(map[string][]*rpc.Pkg),
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return &dc
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Cut the version requirement from a dependency leaving just the name.
|
2018-03-15 14:21:08 +00:00
|
|
|
func splitNameFromDep(dep string) (string, string) {
|
2018-03-17 02:05:16 +00:00
|
|
|
split := strings.FieldsFunc(dep, func(c rune) bool {
|
2018-02-22 21:05:39 +00:00
|
|
|
return c == '>' || c == '<' || c == '='
|
2018-03-15 14:21:08 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if len(split) == 1 {
|
|
|
|
return split[0], ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return split[0], split[1]
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 19:14:37 +00:00
|
|
|
//split apart db/package to db and package
|
|
|
|
func splitDbFromName(pkg string) (string, string) {
|
|
|
|
split := strings.SplitN(pkg, "/", 2)
|
|
|
|
|
|
|
|
if len(split) == 2 {
|
|
|
|
return split[0], split[1]
|
|
|
|
}
|
2018-03-19 15:30:44 +00:00
|
|
|
return "", split[0]
|
2018-03-10 19:14:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-29 13:40:38 +00:00
|
|
|
func isDevelName(name string) bool {
|
|
|
|
for _, suffix := range []string{"git", "svn", "hg", "bzr", "nightly"} {
|
|
|
|
if strings.HasSuffix(name, suffix) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Contains(name, "-always-")
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:23:20 +00:00
|
|
|
func getBases(pkgs map[string]*rpc.Pkg) map[string][]*rpc.Pkg {
|
|
|
|
bases := make(map[string][]*rpc.Pkg)
|
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
nextpkg:
|
2018-03-22 18:23:20 +00:00
|
|
|
for _, pkg := range pkgs {
|
2018-03-29 05:01:02 +00:00
|
|
|
for _, base := range bases[pkg.PackageBase] {
|
|
|
|
if base == pkg {
|
|
|
|
continue nextpkg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:23:20 +00:00
|
|
|
_, ok := bases[pkg.PackageBase]
|
|
|
|
if !ok {
|
|
|
|
bases[pkg.PackageBase] = make([]*rpc.Pkg, 0)
|
|
|
|
}
|
|
|
|
bases[pkg.PackageBase] = append(bases[pkg.PackageBase], pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return bases
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
func aurFindProvider(name string, dt *depTree) (string, *rpc.Pkg) {
|
|
|
|
dep, _ := splitNameFromDep(name)
|
|
|
|
aurpkg, exists := dt.Aur[dep]
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
return dep, aurpkg
|
|
|
|
}
|
|
|
|
|
|
|
|
dep, exists = dt.Provides[dep]
|
|
|
|
if exists {
|
|
|
|
aurpkg, exists = dt.Aur[dep]
|
|
|
|
if exists {
|
|
|
|
return dep, aurpkg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func repoFindProvider(name string, dt *depTree) (string, *alpm.Package) {
|
|
|
|
dep, _ := splitNameFromDep(name)
|
|
|
|
alpmpkg, exists := dt.Repo[dep]
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
return dep, alpmpkg
|
|
|
|
}
|
|
|
|
|
|
|
|
dep, exists = dt.Provides[dep]
|
|
|
|
if exists {
|
|
|
|
alpmpkg, exists = dt.Repo[dep]
|
|
|
|
if exists {
|
|
|
|
return dep, alpmpkg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Step two of dependency resolving. We already have all the information on the
|
|
|
|
// packages we need, now it's just about ordering them correctly.
|
|
|
|
// pkgs is a list of targets, the packages we want to install. Dependencies are
|
|
|
|
// not included.
|
|
|
|
// For each package we want we iterate down the tree until we hit the bottom.
|
|
|
|
// This is done recursively for each branch.
|
|
|
|
// The start of the tree is defined as the package we want.
|
|
|
|
// When we hit the bottom of the branch we know thats the first package
|
|
|
|
// we need to install so we add it to the start of the to install
|
|
|
|
// list (dc.Aur and dc.Repo).
|
|
|
|
// We work our way up until there is another branch to go down and do it all
|
|
|
|
// again.
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// Here is a visual example:
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// a
|
|
|
|
// / \
|
|
|
|
// b c
|
2018-03-03 01:11:16 +00:00
|
|
|
// / \
|
2018-03-03 02:45:16 +00:00
|
|
|
// d e
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// We see a and it needs b and c
|
|
|
|
// We see b and it needs d and e
|
|
|
|
// We see d - it needs nothing so we add d to our list and move up
|
|
|
|
// We see e - it needs nothing so we add e to our list and move up
|
|
|
|
// We see c - it needs nothing so we add c to our list and move up
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// The final install order would come out as debca
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// There is a little more to this, handling provides, multiple packages wanting the
|
|
|
|
// same dependencies, etc. This is just the basic premise.
|
2018-01-17 21:48:23 +00:00
|
|
|
func getDepCatagories(pkgs []string, dt *depTree) (*depCatagories, error) {
|
|
|
|
dc := makeDependCatagories()
|
2018-02-15 21:23:34 +00:00
|
|
|
seen := make(stringSet)
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-03-22 18:23:20 +00:00
|
|
|
dc.Bases = getBases(dt.Aur)
|
2018-02-27 20:57:11 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
for _, pkg := range pkgs {
|
2018-03-29 05:01:02 +00:00
|
|
|
dep, alpmpkg := repoFindProvider(pkg, dt)
|
|
|
|
if alpmpkg != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
repoDepCatagoriesRecursive(alpmpkg, dc, dt, false)
|
|
|
|
dc.Repo = append(dc.Repo, alpmpkg)
|
|
|
|
delete(dt.Repo, dep)
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
dep, aurpkg := aurFindProvider(pkg, dt)
|
|
|
|
if aurpkg != nil {
|
2018-02-15 21:23:34 +00:00
|
|
|
depCatagoriesRecursive(aurpkg, dc, dt, false, seen)
|
|
|
|
if !seen.get(aurpkg.PackageBase) {
|
|
|
|
dc.Aur = append(dc.Aur, aurpkg)
|
|
|
|
seen.set(aurpkg.PackageBase)
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
delete(dt.Aur, dep)
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 16:27:53 +00:00
|
|
|
for _, base := range dc.Bases {
|
|
|
|
for _, pkg := range base {
|
|
|
|
for _, dep := range pkg.Depends {
|
|
|
|
dc.MakeOnly.remove(dep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range dc.Repo {
|
|
|
|
pkg.Depends().ForEach(func(_dep alpm.Depend) error {
|
|
|
|
dep := _dep.Name
|
|
|
|
dc.MakeOnly.remove(dep)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
2018-02-15 21:23:34 +00:00
|
|
|
|
2018-03-12 18:49:03 +00:00
|
|
|
for _, pkg := range pkgs {
|
|
|
|
dc.MakeOnly.remove(pkg)
|
|
|
|
}
|
|
|
|
|
2018-03-01 14:52:57 +00:00
|
|
|
dupes := make(map[*alpm.Package]struct{})
|
|
|
|
filteredRepo := make([]*alpm.Package, 0)
|
|
|
|
|
|
|
|
for _, pkg := range dc.Repo {
|
|
|
|
_, ok := dupes[pkg]
|
|
|
|
if ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dupes[pkg] = struct{}{}
|
|
|
|
filteredRepo = append(filteredRepo, pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
dc.Repo = filteredRepo
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return dc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func repoDepCatagoriesRecursive(pkg *alpm.Package, dc *depCatagories, dt *depTree, isMake bool) {
|
|
|
|
pkg.Depends().ForEach(func(_dep alpm.Depend) error {
|
2018-03-29 05:01:02 +00:00
|
|
|
dep, alpmpkg := repoFindProvider(_dep.Name, dt)
|
|
|
|
if alpmpkg != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
delete(dt.Repo, dep)
|
|
|
|
repoDepCatagoriesRecursive(alpmpkg, dc, dt, isMake)
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
if isMake {
|
2018-02-15 21:23:34 +00:00
|
|
|
dc.MakeOnly.set(alpmpkg.Name())
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 21:23:34 +00:00
|
|
|
dc.Repo = append(dc.Repo, alpmpkg)
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-27 20:57:11 +00:00
|
|
|
func depCatagoriesRecursive(_pkg *rpc.Pkg, dc *depCatagories, dt *depTree, isMake bool, seen stringSet) {
|
|
|
|
for _, pkg := range dc.Bases[_pkg.PackageBase] {
|
|
|
|
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
2018-03-29 05:01:02 +00:00
|
|
|
for _, pkg := range deps {
|
|
|
|
dep, aurpkg := aurFindProvider(pkg, dt)
|
|
|
|
if aurpkg != nil {
|
2018-02-27 20:57:11 +00:00
|
|
|
delete(dt.Aur, dep)
|
|
|
|
depCatagoriesRecursive(aurpkg, dc, dt, isMake, seen)
|
|
|
|
|
|
|
|
if !seen.get(aurpkg.PackageBase) {
|
|
|
|
dc.Aur = append(dc.Aur, aurpkg)
|
|
|
|
seen.set(aurpkg.PackageBase)
|
|
|
|
}
|
|
|
|
|
|
|
|
if isMake {
|
|
|
|
dc.MakeOnly.set(aurpkg.Name)
|
|
|
|
}
|
2018-02-15 21:23:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
dep, alpmpkg := repoFindProvider(pkg, dt)
|
|
|
|
if alpmpkg != nil {
|
2018-02-27 20:57:11 +00:00
|
|
|
delete(dt.Repo, dep)
|
|
|
|
repoDepCatagoriesRecursive(alpmpkg, dc, dt, isMake)
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-02-27 20:57:11 +00:00
|
|
|
if isMake {
|
|
|
|
dc.MakeOnly.set(alpmpkg.Name())
|
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-02-27 20:57:11 +00:00
|
|
|
dc.Repo = append(dc.Repo, alpmpkg)
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-02-27 20:57:11 +00:00
|
|
|
isMake = true
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// This is step one for dependency resolving. pkgs is a slice of the packages you
|
|
|
|
// want to resolve the dependencies for. They can be a mix of aur and repo
|
|
|
|
// dependencies. All unmet dependencies will be resolved.
|
|
|
|
//
|
|
|
|
// For Aur dependencies depends, makedepends and checkdepends are resolved but
|
|
|
|
// for repo packages only depends are resolved as they are prebuilt.
|
2018-04-17 17:01:34 +00:00
|
|
|
// The return will be split into three categories: Repo, Aur and Missing.
|
2018-03-03 02:45:16 +00:00
|
|
|
// The return is in no way ordered. This step is is just aimed at gathering the
|
|
|
|
// packages we need.
|
|
|
|
//
|
|
|
|
// This has been designed to make the least amount of rpc requests as possible.
|
|
|
|
// Web requests are probably going to be the bottleneck here so minimizing them
|
|
|
|
// provides a nice speed boost.
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// Here is a visual expample of the request system.
|
|
|
|
// Remember only unsatisfied packages are requested, if a package is already
|
|
|
|
// installed we dont bother.
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
|
|
|
// a
|
|
|
|
// / \
|
|
|
|
// b c
|
|
|
|
// / \
|
|
|
|
// d e
|
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// We see a so we send a request for a
|
|
|
|
// We see a wants b and c so we send a request for b and c
|
|
|
|
// We see d and e so we send a request for d and e
|
2018-03-03 01:11:16 +00:00
|
|
|
//
|
2018-03-03 02:45:16 +00:00
|
|
|
// Thats 5 packages in 3 requests. The amount of requests needed should always be
|
|
|
|
// the same as the height of the tree.
|
|
|
|
// The example does not really do this justice, In the real world where packages
|
|
|
|
// have 10+ dependencies each this is a very nice optimization.
|
2018-04-11 03:43:51 +00:00
|
|
|
func getDepTree(pkgs []string, warnings *aurWarnings) (*depTree, error) {
|
2018-01-17 21:48:23 +00:00
|
|
|
dt := makeDepTree()
|
2018-04-11 03:43:51 +00:00
|
|
|
dt.Warnings = warnings
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2017-10-18 02:38:19 +00:00
|
|
|
localDb, err := alpmHandle.LocalDb()
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
return dt, err
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
syncDb, err := alpmHandle.SyncDbs()
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
2018-01-17 21:48:23 +00:00
|
|
|
return dt, err
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 22:37:10 +00:00
|
|
|
for _, pkg := range pkgs {
|
2018-03-10 19:14:37 +00:00
|
|
|
db, name := splitDbFromName(pkg)
|
2018-03-16 19:30:14 +00:00
|
|
|
var foundPkg *alpm.Package
|
|
|
|
var singleDb *alpm.Db
|
2018-03-10 19:14:37 +00:00
|
|
|
|
2018-03-13 21:36:42 +00:00
|
|
|
if db == "aur" {
|
|
|
|
dt.ToProcess.set(name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Check the repos for a matching dep
|
2018-03-16 19:30:14 +00:00
|
|
|
if db != "" {
|
|
|
|
singleDb, err = alpmHandle.SyncDbByName(db)
|
|
|
|
if err != nil {
|
|
|
|
return dt, err
|
|
|
|
}
|
|
|
|
foundPkg, err = singleDb.PkgCache().FindSatisfier(name)
|
|
|
|
} else {
|
|
|
|
foundPkg, err = syncDb.FindSatisfier(name)
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-03-16 19:30:14 +00:00
|
|
|
if err == nil {
|
|
|
|
repoTreeRecursive(foundPkg, dt, localDb, syncDb)
|
2018-02-27 20:37:52 +00:00
|
|
|
continue
|
2018-03-16 19:30:14 +00:00
|
|
|
} else {
|
|
|
|
//would be better to check the groups from singleDb if
|
|
|
|
//the user specified a db but theres no easy way to do
|
|
|
|
//it without making alpm_lists so dont bother for now
|
|
|
|
//db/group is probably a rare use case
|
|
|
|
_, err := syncDb.PkgCachebyGroup(name)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
dt.Groups.set(pkg)
|
|
|
|
continue
|
|
|
|
}
|
2018-02-27 20:37:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 21:36:42 +00:00
|
|
|
if db == "" {
|
2018-03-10 19:14:37 +00:00
|
|
|
dt.ToProcess.set(name)
|
|
|
|
} else {
|
|
|
|
dt.Missing.set(pkg)
|
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 19:30:14 +00:00
|
|
|
if len(dt.ToProcess) > 0 {
|
2018-04-10 23:45:58 +00:00
|
|
|
fmt.Println(bold(cyan("::") + bold(" Querying AUR...")))
|
2018-03-16 19:30:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 23:35:54 +00:00
|
|
|
err = depTreeRecursive(dt, localDb, syncDb, false)
|
2018-03-15 13:51:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return dt, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !cmdArgs.existsArg("d", "nodeps") {
|
|
|
|
err = checkVersions(dt)
|
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-04-11 03:43:51 +00:00
|
|
|
dt.Warnings.Print()
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return dt, err
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2017-08-07 13:43:25 +00:00
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Takes a repo package,
|
|
|
|
// gives all of the non installed deps,
|
|
|
|
// repeats on each sub dep.
|
2018-01-20 22:37:10 +00:00
|
|
|
func repoTreeRecursive(pkg *alpm.Package, dt *depTree, localDb *alpm.Db, syncDb alpm.DbList) (err error) {
|
2018-01-17 21:48:23 +00:00
|
|
|
_, exists := dt.Repo[pkg.Name()]
|
|
|
|
if exists {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
_, exists = dt.Provides[pkg.Name()]
|
|
|
|
if exists {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
dt.Repo[pkg.Name()] = pkg
|
2018-03-01 14:30:16 +00:00
|
|
|
(*pkg).Provides().ForEach(func(dep alpm.Depend) (err error) {
|
2018-03-29 05:01:02 +00:00
|
|
|
dt.Provides[dep.Name] = pkg.Name()
|
2018-01-22 10:59:15 +00:00
|
|
|
return nil
|
2018-03-01 14:30:16 +00:00
|
|
|
})
|
2018-01-17 21:48:23 +00:00
|
|
|
|
|
|
|
(*pkg).Depends().ForEach(func(dep alpm.Depend) (err error) {
|
|
|
|
_, exists := dt.Repo[dep.Name]
|
|
|
|
if exists {
|
2017-08-07 13:43:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
_, isInstalled := localDb.PkgCache().FindSatisfier(dep.String())
|
|
|
|
if isInstalled == nil {
|
|
|
|
return
|
2018-01-20 22:37:10 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
repoPkg, inRepos := syncDb.FindSatisfier(dep.String())
|
|
|
|
if inRepos == nil {
|
|
|
|
repoTreeRecursive(repoPkg, dt, localDb, syncDb)
|
|
|
|
return
|
2017-08-07 13:43:25 +00:00
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-02-13 17:52:33 +00:00
|
|
|
dt.Missing.set(dep.String())
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
return
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake bool) (err error) {
|
2018-02-17 23:35:54 +00:00
|
|
|
if len(dt.ToProcess) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-02-17 23:35:54 +00:00
|
|
|
nextProcess := make(stringSet)
|
|
|
|
currentProcess := make(stringSet)
|
2018-03-03 02:45:16 +00:00
|
|
|
// Strip version conditions
|
2018-03-15 14:21:08 +00:00
|
|
|
for _dep := range dt.ToProcess {
|
|
|
|
dep, _ := splitNameFromDep(_dep)
|
|
|
|
currentProcess.set(dep)
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Assume toprocess only contains aur stuff we have not seen
|
2018-04-11 03:43:51 +00:00
|
|
|
info, err := aurInfo(currentProcess.toSlice(), dt.Warnings)
|
2018-02-17 23:35:54 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Cache the results
|
2018-01-17 21:48:23 +00:00
|
|
|
for _, pkg := range info {
|
2018-03-22 18:11:00 +00:00
|
|
|
dt.Aur[pkg.Name] = pkg
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
for _, provide := range pkg.Provides {
|
|
|
|
name, _ := splitNameFromDep(provide)
|
|
|
|
dt.Provides[name] = pkg.Name
|
|
|
|
}
|
2017-08-07 13:43:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Loop through to process and check if we now have
|
|
|
|
// each packaged cached.
|
|
|
|
// If not cached, we assume it is missing.
|
2018-02-17 23:35:54 +00:00
|
|
|
for pkgName := range currentProcess {
|
2018-01-17 21:48:23 +00:00
|
|
|
pkg, exists := dt.Aur[pkgName]
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Did not get it in the request.
|
2018-01-17 21:48:23 +00:00
|
|
|
if !exists {
|
2018-02-17 23:35:54 +00:00
|
|
|
dt.Missing.set(pkgName)
|
2018-01-17 21:48:23 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// for each dep and makedep
|
2018-02-19 17:53:03 +00:00
|
|
|
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
2018-01-17 21:48:23 +00:00
|
|
|
for _, versionedDep := range deps {
|
2018-03-15 14:21:08 +00:00
|
|
|
dep, _ := splitNameFromDep(versionedDep)
|
2018-01-17 21:48:23 +00:00
|
|
|
|
|
|
|
_, exists = dt.Aur[dep]
|
2018-03-03 02:45:16 +00:00
|
|
|
// We have it cached so skip.
|
2018-01-17 21:48:23 +00:00
|
|
|
if exists {
|
|
|
|
continue
|
|
|
|
}
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-03-29 05:01:02 +00:00
|
|
|
_, exists = dt.Provides[dep]
|
|
|
|
// We have it cached so skip.
|
|
|
|
if exists {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
_, exists = dt.Repo[dep]
|
2018-03-03 02:45:16 +00:00
|
|
|
// We have it cached so skip.
|
2018-01-17 21:48:23 +00:00
|
|
|
if exists {
|
|
|
|
continue
|
|
|
|
}
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
_, exists = dt.Missing[dep]
|
2018-03-03 02:45:16 +00:00
|
|
|
// We know it does not resolve so skip.
|
2018-01-17 21:48:23 +00:00
|
|
|
if exists {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Check if already installed.
|
2018-01-17 21:48:23 +00:00
|
|
|
_, isInstalled := localDb.PkgCache().FindSatisfier(versionedDep)
|
2018-03-14 01:48:33 +00:00
|
|
|
if isInstalled == nil && config.ReBuild != "tree" {
|
2018-01-17 21:48:23 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Check the repos for a matching dep.
|
2018-01-17 21:48:23 +00:00
|
|
|
repoPkg, inRepos := syncDb.FindSatisfier(versionedDep)
|
|
|
|
if inRepos == nil {
|
2018-03-14 01:48:33 +00:00
|
|
|
if isInstalled == nil && config.ReBuild == "tree" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
repoTreeRecursive(repoPkg, dt, localDb, syncDb)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// If all else fails add it to next search.
|
2018-02-17 23:35:54 +00:00
|
|
|
nextProcess.set(versionedDep)
|
2018-01-17 21:48:23 +00:00
|
|
|
}
|
2017-08-07 13:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:48:23 +00:00
|
|
|
dt.ToProcess = nextProcess
|
|
|
|
depTreeRecursive(dt, localDb, syncDb, true)
|
2018-01-20 22:37:10 +00:00
|
|
|
|
2017-08-07 13:43:25 +00:00
|
|
|
return
|
|
|
|
}
|
2018-03-15 13:51:37 +00:00
|
|
|
|
|
|
|
func checkVersions(dt *depTree) error {
|
2018-03-17 02:05:16 +00:00
|
|
|
has := make(map[string][]string)
|
2018-04-03 00:25:47 +00:00
|
|
|
allDeps := make([]*gopkg.Dependency, 0)
|
|
|
|
|
|
|
|
localDb, err := alpmHandle.LocalDb()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-22 16:39:27 +00:00
|
|
|
|
2018-03-15 13:51:37 +00:00
|
|
|
for _, pkg := range dt.Aur {
|
|
|
|
for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} {
|
|
|
|
for _, dep := range deps {
|
2018-03-17 02:05:16 +00:00
|
|
|
_, _dep := splitNameFromDep(dep)
|
|
|
|
if _dep != "" {
|
2018-04-03 00:25:47 +00:00
|
|
|
deps, _ := gopkg.ParseDeps([]string{dep})
|
|
|
|
if deps[0] != nil {
|
|
|
|
allDeps = append(allDeps, deps[0])
|
|
|
|
}
|
2018-03-17 02:05:16 +00:00
|
|
|
}
|
2018-03-15 13:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 15:40:33 +00:00
|
|
|
addMapStringSlice(has, pkg.Name, pkg.Version)
|
2018-03-15 13:51:37 +00:00
|
|
|
|
2018-03-29 13:40:38 +00:00
|
|
|
if !isDevelName(pkg.Name) {
|
|
|
|
for _, name := range pkg.Provides {
|
|
|
|
_name, _ver := splitNameFromDep(name)
|
|
|
|
if _ver != "" {
|
|
|
|
addMapStringSlice(has, _name, _ver)
|
|
|
|
} else {
|
|
|
|
delete(has, _name)
|
|
|
|
}
|
2018-03-15 13:51:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range dt.Repo {
|
|
|
|
pkg.Depends().ForEach(func(dep alpm.Depend) error {
|
|
|
|
if dep.Mod != alpm.DepModAny {
|
2018-04-03 00:25:47 +00:00
|
|
|
deps, _ := gopkg.ParseDeps([]string{dep.String()})
|
|
|
|
if deps[0] != nil {
|
|
|
|
allDeps = append(allDeps, deps[0])
|
|
|
|
}
|
2018-03-15 13:51:37 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2018-03-22 15:40:33 +00:00
|
|
|
addMapStringSlice(has, pkg.Name(), pkg.Version())
|
2018-03-15 13:51:37 +00:00
|
|
|
|
|
|
|
pkg.Provides().ForEach(func(dep alpm.Depend) error {
|
|
|
|
if dep.Mod != alpm.DepModAny {
|
2018-03-22 15:40:33 +00:00
|
|
|
addMapStringSlice(has, dep.Name, dep.Version)
|
2018-03-17 02:05:16 +00:00
|
|
|
} else {
|
|
|
|
delete(has, dep.Name)
|
2018-03-15 13:51:37 +00:00
|
|
|
}
|
2018-03-17 02:05:16 +00:00
|
|
|
|
2018-03-15 13:51:37 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-03 00:25:47 +00:00
|
|
|
localDb.PkgCache().ForEach(func(pkg alpm.Package) error {
|
|
|
|
pkg.Provides().ForEach(func(dep alpm.Depend) error {
|
|
|
|
if dep.Mod != alpm.DepModAny {
|
|
|
|
addMapStringSlice(has, dep.Name, dep.Version)
|
|
|
|
} else {
|
|
|
|
delete(has, dep.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2018-03-15 13:51:37 +00:00
|
|
|
|
2018-04-03 00:25:47 +00:00
|
|
|
for _, dep := range allDeps {
|
2018-03-17 02:05:16 +00:00
|
|
|
satisfied := false
|
|
|
|
verStrs, ok := has[dep.Name]
|
2018-03-15 13:51:37 +00:00
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-17 02:05:16 +00:00
|
|
|
for _, verStr := range verStrs {
|
|
|
|
version, err := gopkg.NewCompleteVersion(verStr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if version.Satisfies(dep) {
|
|
|
|
satisfied = true
|
|
|
|
break
|
|
|
|
}
|
2018-03-15 13:51:37 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 02:05:16 +00:00
|
|
|
if !satisfied {
|
2018-03-15 13:51:37 +00:00
|
|
|
dt.Missing.set(dep.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|