From 69a86c6a78c3d96daf66f08f5bf7042ff6752230 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Thu, 15 Mar 2018 13:51:37 +0000 Subject: [PATCH] Check versioned deps during the dep fetching process Check versioned deps such as `foo>1` `foo=2` `foo<3` --- dependencies.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ install.go | 9 +++++-- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/dependencies.go b/dependencies.go index ab6a6f87..fac66d20 100644 --- a/dependencies.go +++ b/dependencies.go @@ -5,6 +5,7 @@ import ( alpm "github.com/jguer/go-alpm" rpc "github.com/mikkeloscar/aur" + gopkg "github.com/mikkeloscar/gopkgbuild" ) type depTree struct { @@ -309,6 +310,13 @@ func getDepTree(pkgs []string) (*depTree, error) { } err = depTreeRecursive(dt, localDb, syncDb, false) + if err != nil { + return dt, err + } + + if !cmdArgs.existsArg("d", "nodeps") { + err = checkVersions(dt) + } return dt, err } @@ -445,3 +453,64 @@ func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake return } + +func checkVersions(dt *depTree) error { + depStrings := make([]string, 0) + has := make(map[string]string) + + for _, pkg := range dt.Aur { + for _, deps := range [3][]string{pkg.Depends, pkg.MakeDepends, pkg.CheckDepends} { + for _, dep := range deps { + depStrings = append(depStrings, dep) + } + } + + has[pkg.Name] = pkg.Version + + for _, name := range pkg.Provides { + _name, _ver := splitNameFromDep(name) + if _ver != "" { + has[_name] = _ver + } + } + } + + for _, pkg := range dt.Repo { + pkg.Depends().ForEach(func(dep alpm.Depend) error { + if dep.Mod != alpm.DepModAny { + has[dep.Name] = dep.Version + } + return nil + }) + + has[pkg.Name()] = pkg.Version() + + pkg.Provides().ForEach(func(dep alpm.Depend) error { + if dep.Mod != alpm.DepModAny { + has[dep.Name] = dep.Version + } + return nil + }) + + } + + deps, _ := gopkg.ParseDeps(depStrings) + + for _, dep := range deps { + verStr, ok := has[dep.Name] + if !ok { + continue + } + + version, err := gopkg.NewCompleteVersion(verStr) + if err != nil { + return err + } + + if !version.Satisfies(dep) { + dt.Missing.set(dep.String()) + } + } + + return nil +} diff --git a/install.go b/install.go index 6c273dcb..fdabc8e4 100644 --- a/install.go +++ b/install.go @@ -55,8 +55,13 @@ func install(parser *arguments) error { //only error if direct targets or deps are missing for missingName := range dt.Missing { if !remoteNamesCache.get(missingName) { - return fmt.Errorf(bold(red(arrow+" Error: ")) + - "Could not find all required package") + str := bold(red(arrow+" Error: ")) + "Could not find all required packages:" + + for name := range dt.Missing { + str += "\n\t" + name + } + + return fmt.Errorf("%s", str) } }