mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 01:27:21 +01:00
b2d3eb5c49
This is a rewrite of the dependency system, It aims to be cleaner written, with a better idea of what is needed from the start, meaning less new code being hacked on for things that were not thought about. This version also aims to use as many small functions as possible, for cleaner code and better testing. Added dep.go: general dependency functions Added depPool.go: Replacement of depTree, dependencies were never ordered so a tree did not really make sense. Instead the term pool makes more sense. Added depOrder.go: Replacement of depCatagories, This simply orders the dependencies, dependencies are still catagorized as repo and AUR but I believe this to be a better name Added depCheck.go: Replaces conflicts.go and also contains the missing dependency code This version is mostly the same as the old version with a few improvments: Missing packages will print the full dependency tree Versioned dependency checking errors should be fixed Make depends should be calculated properly Experimental AUR provide searcher This code has been added along side the old code for testing and is not currently used by the install process. Once the install process is moved to use this code, the old code will be removed.
105 lines
1.8 KiB
Go
105 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
alpm "github.com/jguer/go-alpm"
|
|
rpc "github.com/mikkeloscar/aur"
|
|
)
|
|
|
|
func splitDep(dep string) (string, string, string) {
|
|
mod := ""
|
|
|
|
split := strings.FieldsFunc(dep, func(c rune) bool {
|
|
match := c == '>' || c == '<' || c == '='
|
|
|
|
if match {
|
|
mod += string(c)
|
|
}
|
|
|
|
return match
|
|
})
|
|
|
|
if len(split) == 1 {
|
|
return split[0], "", ""
|
|
}
|
|
|
|
return split[0], mod, split[1]
|
|
}
|
|
|
|
func pkgSatisfies(name, version, dep string) bool {
|
|
depName, depMod, depVersion := splitDep(dep)
|
|
|
|
if depName != name {
|
|
return false
|
|
}
|
|
|
|
return verSatisfies(version, depMod, depVersion)
|
|
}
|
|
|
|
func provideSatisfies(provide, dep string) bool {
|
|
depName, depMod, depVersion := splitDep(dep)
|
|
provideName, provideMod, provideVersion := splitDep(provide)
|
|
|
|
if provideName != depName {
|
|
return false
|
|
}
|
|
|
|
// Unversioned provieds can not satisfy a versioned dep
|
|
if provideMod == "" && depMod != "" {
|
|
return false
|
|
}
|
|
|
|
return verSatisfies(provideVersion, depMod, depVersion)
|
|
}
|
|
|
|
func verSatisfies(ver1, mod, ver2 string) bool {
|
|
switch mod {
|
|
case "=":
|
|
return alpm.VerCmp(ver1, ver2) == 0
|
|
case "<":
|
|
return alpm.VerCmp(ver1, ver2) < 0
|
|
case "<=":
|
|
return alpm.VerCmp(ver1, ver2) <= 0
|
|
case ">":
|
|
return alpm.VerCmp(ver1, ver2) > 0
|
|
case ">=":
|
|
return alpm.VerCmp(ver1, ver2) >= 0
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
|
|
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
|
return true
|
|
}
|
|
|
|
for _, provide := range pkg.Provides {
|
|
if provideSatisfies(provide, dep) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func satisfiesRepo(dep string, pkg *alpm.Package) bool {
|
|
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
|
|
return true
|
|
}
|
|
|
|
if pkg.Provides().ForEach(func(provide alpm.Depend) error {
|
|
if provideSatisfies(provide.String(), dep) {
|
|
return fmt.Errorf("")
|
|
}
|
|
|
|
return nil
|
|
}) != nil {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|