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.
137 lines
1.9 KiB
Go
137 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
type mapStringSlice map[string][]string
|
|
type mapStringSet map[string]stringSet
|
|
|
|
type intRange struct {
|
|
min int
|
|
max int
|
|
}
|
|
|
|
func makeIntRange(min, max int) intRange {
|
|
return intRange{
|
|
min,
|
|
max,
|
|
}
|
|
}
|
|
|
|
func (r intRange) get(n int) bool {
|
|
return n >= r.min && n <= r.max
|
|
}
|
|
|
|
type intRanges []intRange
|
|
|
|
func (rs intRanges) get(n int) bool {
|
|
for _, r := range rs {
|
|
if r.get(n) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func min(a, b int) int {
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func max(a, b int) int {
|
|
if a < b {
|
|
return b
|
|
}
|
|
return a
|
|
}
|
|
|
|
func (mss mapStringSet) Add(n string, v string) {
|
|
_, ok := mss[n]
|
|
if !ok {
|
|
mss[n] = make(stringSet)
|
|
}
|
|
mss[n].set(v)
|
|
}
|
|
|
|
func (mss mapStringSlice) Add(n string, v string) {
|
|
_, ok := mss[n]
|
|
if !ok {
|
|
mss[n] = make([]string, 0, 1)
|
|
}
|
|
mss[n] = append(mss[n], v)
|
|
}
|
|
|
|
func completeFileName(dir, name string) (string, error) {
|
|
files, err := ioutil.ReadDir(dir)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
for _, file := range files {
|
|
if file.IsDir() {
|
|
continue
|
|
}
|
|
|
|
if strings.HasPrefix(file.Name(), name) {
|
|
return filepath.Join(dir, file.Name()), nil
|
|
}
|
|
}
|
|
|
|
return "", nil
|
|
}
|
|
|
|
func lessRunes(iRunes, jRunes []rune) bool {
|
|
max := len(iRunes)
|
|
if max > len(jRunes) {
|
|
max = len(jRunes)
|
|
}
|
|
|
|
for idx := 0; idx < max; idx++ {
|
|
ir := iRunes[idx]
|
|
jr := jRunes[idx]
|
|
|
|
lir := unicode.ToLower(ir)
|
|
ljr := unicode.ToLower(jr)
|
|
|
|
if lir != ljr {
|
|
return lir < ljr
|
|
}
|
|
|
|
// the lowercase runes are the same, so compare the original
|
|
if ir != jr {
|
|
return ir < jr
|
|
}
|
|
}
|
|
|
|
return len(iRunes) < len(jRunes)
|
|
}
|
|
|
|
func stringSliceEqual(a, b []string) bool {
|
|
if a == nil && b == nil {
|
|
return true
|
|
}
|
|
|
|
if a == nil || b == nil {
|
|
return false
|
|
}
|
|
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
|
|
for i := 0; i < len(a); i++ {
|
|
if a[i] != b[i] {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|