2022-09-06 23:25:44 +02:00
|
|
|
package dep
|
|
|
|
|
|
|
|
import (
|
2022-11-08 01:32:21 +01:00
|
|
|
"context"
|
2022-09-06 23:25:44 +02:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
aurc "github.com/Jguer/aur"
|
|
|
|
alpm "github.com/Jguer/go-alpm/v2"
|
|
|
|
gosrc "github.com/Morganamilo/go-srcinfo"
|
|
|
|
mapset "github.com/deckarep/golang-set/v2"
|
|
|
|
"github.com/leonelquinteros/gotext"
|
|
|
|
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/db"
|
2023-07-23 22:20:05 +02:00
|
|
|
"github.com/Jguer/yay/v12/pkg/dep/topo"
|
2023-03-07 22:04:06 +01:00
|
|
|
"github.com/Jguer/yay/v12/pkg/intrange"
|
|
|
|
aur "github.com/Jguer/yay/v12/pkg/query"
|
|
|
|
"github.com/Jguer/yay/v12/pkg/text"
|
2022-09-06 23:25:44 +02:00
|
|
|
)
|
|
|
|
|
2022-09-09 17:38:48 +02:00
|
|
|
type InstallInfo struct {
|
2023-02-17 20:01:26 +01:00
|
|
|
Source Source
|
|
|
|
Reason Reason
|
|
|
|
Version string
|
|
|
|
LocalVersion string
|
|
|
|
SrcinfoPath *string
|
|
|
|
AURBase *string
|
|
|
|
SyncDBName *string
|
|
|
|
|
2023-05-01 18:21:40 +02:00
|
|
|
IsGroup bool
|
2023-02-17 20:01:26 +01:00
|
|
|
Upgrade bool
|
|
|
|
Devel bool
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i *InstallInfo) String() string {
|
|
|
|
return fmt.Sprintf("InstallInfo{Source: %v, Reason: %v}", i.Source, i.Reason)
|
|
|
|
}
|
|
|
|
|
2022-09-07 01:03:29 +02:00
|
|
|
type (
|
2022-09-09 17:38:48 +02:00
|
|
|
Reason int
|
|
|
|
Source int
|
2022-09-07 01:03:29 +02:00
|
|
|
)
|
|
|
|
|
2022-09-09 17:38:48 +02:00
|
|
|
func (r Reason) String() string {
|
2022-09-20 00:01:19 +02:00
|
|
|
return ReasonNames[r]
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s Source) String() string {
|
2022-09-20 00:01:19 +02:00
|
|
|
return SourceNames[s]
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
|
|
|
|
2022-09-07 01:03:29 +02:00
|
|
|
const (
|
2022-09-09 17:38:48 +02:00
|
|
|
Explicit Reason = iota // 0
|
|
|
|
Dep // 1
|
|
|
|
MakeDep // 2
|
|
|
|
CheckDep // 3
|
2022-09-07 01:03:29 +02:00
|
|
|
)
|
|
|
|
|
2022-09-20 00:01:19 +02:00
|
|
|
var ReasonNames = map[Reason]string{
|
|
|
|
Explicit: gotext.Get("Explicit"),
|
|
|
|
Dep: gotext.Get("Dependency"),
|
|
|
|
MakeDep: gotext.Get("Make Dependency"),
|
|
|
|
CheckDep: gotext.Get("Check Dependency"),
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
|
|
|
|
2022-09-07 01:03:29 +02:00
|
|
|
const (
|
2022-09-09 17:38:48 +02:00
|
|
|
AUR Source = iota
|
2022-09-07 01:03:29 +02:00
|
|
|
Sync
|
|
|
|
Local
|
2022-09-09 17:38:48 +02:00
|
|
|
SrcInfo
|
2022-09-07 01:03:29 +02:00
|
|
|
Missing
|
|
|
|
)
|
|
|
|
|
2022-09-20 00:01:19 +02:00
|
|
|
var SourceNames = map[Source]string{
|
|
|
|
AUR: gotext.Get("AUR"),
|
|
|
|
Sync: gotext.Get("Sync"),
|
|
|
|
Local: gotext.Get("Local"),
|
|
|
|
SrcInfo: gotext.Get("SRCINFO"),
|
|
|
|
Missing: gotext.Get("Missing"),
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var bgColorMap = map[Source]string{
|
2022-09-07 01:03:29 +02:00
|
|
|
AUR: "lightblue",
|
|
|
|
Sync: "lemonchiffon",
|
|
|
|
Local: "darkolivegreen1",
|
|
|
|
Missing: "tomato",
|
|
|
|
}
|
|
|
|
|
2022-09-09 17:38:48 +02:00
|
|
|
var colorMap = map[Reason]string{
|
2022-09-07 01:03:29 +02:00
|
|
|
Explicit: "black",
|
|
|
|
Dep: "deeppink",
|
|
|
|
MakeDep: "navyblue",
|
|
|
|
CheckDep: "forestgreen",
|
|
|
|
}
|
|
|
|
|
2022-09-06 23:25:44 +02:00
|
|
|
type Grapher struct {
|
2023-02-21 00:14:59 +01:00
|
|
|
logger *text.Logger
|
|
|
|
providerCache map[string][]aur.Pkg
|
|
|
|
|
2022-12-18 21:14:41 +01:00
|
|
|
dbExecutor db.Executor
|
2023-02-21 00:14:59 +01:00
|
|
|
aurClient aurc.QueryClient
|
2022-12-18 21:14:41 +01:00
|
|
|
fullGraph bool // If true, the graph will include all dependencies including already installed ones or repo
|
2023-02-21 00:14:59 +01:00
|
|
|
noConfirm bool // If true, the graph will not prompt for confirmation
|
|
|
|
noDeps bool // If true, the graph will not include dependencies
|
|
|
|
noCheckDeps bool // If true, the graph will not include check dependencies
|
|
|
|
needed bool // If true, the graph will only include packages that are not installed
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-20 12:20:48 +01:00
|
|
|
func NewGrapher(dbExecutor db.Executor, aurCache aurc.QueryClient,
|
2023-02-21 00:14:59 +01:00
|
|
|
fullGraph, noConfirm, noDeps, noCheckDeps, needed bool,
|
|
|
|
logger *text.Logger,
|
2022-10-28 00:38:11 +02:00
|
|
|
) *Grapher {
|
2022-09-06 23:25:44 +02:00
|
|
|
return &Grapher{
|
2022-11-14 00:21:36 +01:00
|
|
|
dbExecutor: dbExecutor,
|
2023-02-21 00:14:59 +01:00
|
|
|
aurClient: aurCache,
|
2022-11-14 00:21:36 +01:00
|
|
|
fullGraph: fullGraph,
|
|
|
|
noConfirm: noConfirm,
|
2022-12-18 21:14:41 +01:00
|
|
|
noDeps: noDeps,
|
|
|
|
noCheckDeps: noCheckDeps,
|
2023-02-21 00:14:59 +01:00
|
|
|
needed: needed,
|
|
|
|
providerCache: make(map[string][]aurc.Pkg, 5),
|
|
|
|
logger: logger,
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-23 22:20:05 +02:00
|
|
|
func NewGraph() *topo.Graph[string, *InstallInfo] {
|
|
|
|
return topo.New[string, *InstallInfo]()
|
|
|
|
}
|
|
|
|
|
2022-11-08 01:37:54 +01:00
|
|
|
func (g *Grapher) GraphFromTargets(ctx context.Context,
|
|
|
|
graph *topo.Graph[string, *InstallInfo], targets []string,
|
|
|
|
) (*topo.Graph[string, *InstallInfo], error) {
|
2022-11-02 00:37:27 +01:00
|
|
|
if graph == nil {
|
2023-07-23 22:20:05 +02:00
|
|
|
graph = NewGraph()
|
2022-11-02 00:37:27 +01:00
|
|
|
}
|
2022-09-07 00:01:23 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
aurTargets := make([]string, 0, len(targets))
|
|
|
|
|
2022-10-28 00:38:11 +02:00
|
|
|
for _, targetString := range targets {
|
2023-02-21 00:14:59 +01:00
|
|
|
target := ToTarget(targetString)
|
2022-10-28 00:38:11 +02:00
|
|
|
|
|
|
|
switch target.DB {
|
2022-11-13 14:29:00 +01:00
|
|
|
case "": // unspecified db
|
2023-04-01 12:33:05 +02:00
|
|
|
if pkg := g.dbExecutor.SyncSatisfier(target.Name); pkg != nil {
|
2023-07-06 08:53:46 +02:00
|
|
|
g.GraphSyncPkg(ctx, graph, pkg, nil)
|
2023-02-17 20:01:26 +01:00
|
|
|
|
2022-11-10 01:48:58 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-11-20 03:47:23 +01:00
|
|
|
groupPackages := g.dbExecutor.PackagesFromGroup(target.Name)
|
|
|
|
if len(groupPackages) > 0 {
|
|
|
|
dbName := groupPackages[0].DB().Name()
|
2023-07-06 08:53:46 +02:00
|
|
|
g.GraphSyncGroup(ctx, graph, target.Name, dbName)
|
2022-11-20 03:47:23 +01:00
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-11-10 01:48:58 +01:00
|
|
|
fallthrough
|
2022-10-28 00:38:11 +02:00
|
|
|
case "aur":
|
2023-02-21 00:14:59 +01:00
|
|
|
aurTargets = append(aurTargets, target.Name)
|
2022-10-28 00:38:11 +02:00
|
|
|
default:
|
2023-07-06 08:53:46 +02:00
|
|
|
pkg, err := g.dbExecutor.SatisfierFromDB(target.Name, target.DB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-06-11 18:16:05 +02:00
|
|
|
}
|
2023-07-06 08:53:46 +02:00
|
|
|
if pkg != nil {
|
|
|
|
g.GraphSyncPkg(ctx, graph, pkg, nil)
|
2023-06-11 18:16:05 +02:00
|
|
|
|
2023-07-06 08:53:46 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
groupPackages, err := g.dbExecutor.PackagesFromGroupAndDB(target.Name, target.DB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(groupPackages) > 0 {
|
|
|
|
g.GraphSyncGroup(ctx, graph, target.Name, target.DB)
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
g.logger.Errorln(gotext.Get("No package found for"), " ", target)
|
2022-10-28 00:38:11 +02:00
|
|
|
}
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
2022-10-28 00:38:11 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
var errA error
|
|
|
|
graph, errA = g.GraphFromAUR(ctx, graph, aurTargets)
|
|
|
|
if errA != nil {
|
|
|
|
return nil, errA
|
2022-10-28 00:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return graph, nil
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
func (g *Grapher) pickSrcInfoPkgs(pkgs []*aurc.Pkg) ([]*aurc.Pkg, error) {
|
|
|
|
final := make([]*aurc.Pkg, 0, len(pkgs))
|
2023-01-24 00:54:15 +01:00
|
|
|
for i := range pkgs {
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Println(text.Magenta(strconv.Itoa(i+1)+" ") + text.Bold(pkgs[i].Name) +
|
|
|
|
" " + text.Cyan(pkgs[i].Version))
|
|
|
|
g.logger.Println(" " + pkgs[i].Description)
|
2023-01-24 00:54:15 +01:00
|
|
|
}
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Infoln(gotext.Get("Packages to exclude") + " (eg: \"1 2 3\", \"1-3\", \"^4\"):")
|
2023-01-24 00:54:15 +01:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
numberBuf, err := g.logger.GetInput("", g.noConfirm)
|
2023-01-24 00:54:15 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
include, exclude, _, otherExclude := intrange.ParseNumberMenu(numberBuf)
|
2023-07-23 19:29:01 +02:00
|
|
|
isInclude := len(exclude) == 0 && otherExclude.Cardinality() == 0
|
2023-01-24 00:54:15 +01:00
|
|
|
|
|
|
|
for i := 1; i <= len(pkgs); i++ {
|
|
|
|
target := i - 1
|
|
|
|
|
|
|
|
if isInclude && !include.Get(i) {
|
|
|
|
final = append(final, pkgs[target])
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isInclude && (exclude.Get(i)) {
|
|
|
|
final = append(final, pkgs[target])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return final, nil
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
func (g *Grapher) addAurPkgProvides(pkg *aurc.Pkg, graph *topo.Graph[string, *InstallInfo]) {
|
|
|
|
for i := range pkg.Provides {
|
|
|
|
depName, mod, version := splitDep(pkg.Provides[i])
|
|
|
|
g.logger.Debugln(pkg.String() + " provides: " + depName)
|
|
|
|
graph.Provides(depName, &alpm.Depend{
|
|
|
|
Name: depName,
|
|
|
|
Version: version,
|
|
|
|
Mod: aurDepModToAlpmDep(mod),
|
|
|
|
}, pkg.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Grapher) GraphFromSrcInfos(ctx context.Context, graph *topo.Graph[string, *InstallInfo],
|
|
|
|
srcInfos map[string]*gosrc.Srcinfo,
|
2022-10-28 00:38:11 +02:00
|
|
|
) (*topo.Graph[string, *InstallInfo], error) {
|
|
|
|
if graph == nil {
|
2023-07-23 22:20:05 +02:00
|
|
|
graph = NewGraph()
|
2022-10-28 00:38:11 +02:00
|
|
|
}
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
aurPkgsAdded := []*aurc.Pkg{}
|
|
|
|
for pkgBuildDir, pkgbuild := range srcInfos {
|
|
|
|
pkgBuildDir := pkgBuildDir
|
2022-09-06 23:38:47 +02:00
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
aurPkgs, err := makeAURPKGFromSrcinfo(g.dbExecutor, pkgbuild)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-01-24 00:54:15 +01:00
|
|
|
}
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
if len(aurPkgs) > 1 {
|
|
|
|
var errPick error
|
|
|
|
aurPkgs, errPick = g.pickSrcInfoPkgs(aurPkgs)
|
|
|
|
if errPick != nil {
|
|
|
|
return nil, errPick
|
|
|
|
}
|
|
|
|
}
|
2022-09-09 17:38:48 +02:00
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
for _, pkg := range aurPkgs {
|
|
|
|
pkg := pkg
|
2022-09-09 17:38:48 +02:00
|
|
|
|
2023-06-11 18:16:05 +02:00
|
|
|
reason := Explicit
|
|
|
|
if pkg := g.dbExecutor.LocalPackage(pkg.Name); pkg != nil {
|
|
|
|
reason = Reason(pkg.Reason())
|
|
|
|
}
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
graph.AddNode(pkg.Name)
|
|
|
|
|
|
|
|
g.addAurPkgProvides(pkg, graph)
|
|
|
|
|
|
|
|
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
|
2023-06-11 18:16:05 +02:00
|
|
|
Color: colorMap[reason],
|
2023-06-03 15:53:33 +02:00
|
|
|
Background: bgColorMap[AUR],
|
|
|
|
Value: &InstallInfo{
|
|
|
|
Source: SrcInfo,
|
2023-06-11 18:16:05 +02:00
|
|
|
Reason: reason,
|
2023-06-03 15:53:33 +02:00
|
|
|
SrcinfoPath: &pkgBuildDir,
|
|
|
|
AURBase: &pkg.PackageBase,
|
|
|
|
Version: pkg.Version,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
aurPkgsAdded = append(aurPkgsAdded, aurPkgs...)
|
2022-09-06 23:38:47 +02:00
|
|
|
}
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
g.AddDepsForPkgs(ctx, aurPkgsAdded, graph)
|
|
|
|
|
2022-09-06 23:38:47 +02:00
|
|
|
return graph, nil
|
|
|
|
}
|
|
|
|
|
2023-05-23 23:18:41 +02:00
|
|
|
func (g *Grapher) AddDepsForPkgs(ctx context.Context, pkgs []*aur.Pkg, graph *topo.Graph[string, *InstallInfo]) {
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
g.addDepNodes(ctx, pkg, graph)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 01:32:21 +01:00
|
|
|
func (g *Grapher) addDepNodes(ctx context.Context, pkg *aur.Pkg, graph *topo.Graph[string, *InstallInfo]) {
|
2022-09-07 01:03:29 +02:00
|
|
|
if len(pkg.MakeDepends) > 0 {
|
2022-11-08 01:32:21 +01:00
|
|
|
g.addNodes(ctx, graph, pkg.Name, pkg.MakeDepends, MakeDep)
|
2022-09-07 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2022-12-18 21:14:41 +01:00
|
|
|
if !g.noDeps && len(pkg.Depends) > 0 {
|
2022-11-08 01:32:21 +01:00
|
|
|
g.addNodes(ctx, graph, pkg.Name, pkg.Depends, Dep)
|
2022-09-07 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2022-12-18 21:14:41 +01:00
|
|
|
if !g.noCheckDeps && !g.noDeps && len(pkg.CheckDepends) > 0 {
|
2022-11-08 01:32:21 +01:00
|
|
|
g.addNodes(ctx, graph, pkg.Name, pkg.CheckDepends, CheckDep)
|
2022-09-07 01:03:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 20:01:26 +01:00
|
|
|
func (g *Grapher) GraphSyncPkg(ctx context.Context,
|
|
|
|
graph *topo.Graph[string, *InstallInfo],
|
2023-07-06 08:53:46 +02:00
|
|
|
pkg alpm.IPackage, upgradeInfo *db.SyncUpgrade,
|
2023-02-17 20:01:26 +01:00
|
|
|
) *topo.Graph[string, *InstallInfo] {
|
|
|
|
if graph == nil {
|
2023-07-23 22:20:05 +02:00
|
|
|
graph = NewGraph()
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
graph.AddNode(pkg.Name())
|
2023-05-01 17:56:42 +02:00
|
|
|
_ = pkg.Provides().ForEach(func(p *alpm.Depend) error {
|
|
|
|
g.logger.Debugln(pkg.Name() + " provides: " + p.String())
|
|
|
|
graph.Provides(p.Name, p, pkg.Name())
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2023-07-06 08:53:46 +02:00
|
|
|
dbName := pkg.DB().Name()
|
|
|
|
info := &InstallInfo{
|
|
|
|
Source: Sync,
|
|
|
|
Reason: Explicit,
|
|
|
|
Version: pkg.Version(),
|
|
|
|
SyncDBName: &dbName,
|
|
|
|
}
|
|
|
|
|
|
|
|
if upgradeInfo == nil {
|
|
|
|
if localPkg := g.dbExecutor.LocalPackage(pkg.Name()); localPkg != nil {
|
|
|
|
info.Reason = Reason(localPkg.Reason())
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info.Upgrade = true
|
|
|
|
info.Reason = Reason(upgradeInfo.Reason)
|
|
|
|
info.LocalVersion = upgradeInfo.LocalVersion
|
|
|
|
}
|
|
|
|
|
2023-02-17 20:01:26 +01:00
|
|
|
g.ValidateAndSetNodeInfo(graph, pkg.Name(), &topo.NodeInfo[*InstallInfo]{
|
2023-07-06 08:53:46 +02:00
|
|
|
Color: colorMap[info.Reason],
|
|
|
|
Background: bgColorMap[info.Source],
|
|
|
|
Value: info,
|
|
|
|
})
|
|
|
|
|
|
|
|
return graph
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Grapher) GraphSyncGroup(ctx context.Context,
|
|
|
|
graph *topo.Graph[string, *InstallInfo],
|
|
|
|
groupName, dbName string,
|
|
|
|
) *topo.Graph[string, *InstallInfo] {
|
|
|
|
if graph == nil {
|
2023-07-23 22:20:05 +02:00
|
|
|
graph = NewGraph()
|
2023-07-06 08:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
graph.AddNode(groupName)
|
|
|
|
|
|
|
|
g.ValidateAndSetNodeInfo(graph, groupName, &topo.NodeInfo[*InstallInfo]{
|
|
|
|
Color: colorMap[Explicit],
|
2023-02-17 20:01:26 +01:00
|
|
|
Background: bgColorMap[Sync],
|
2023-07-06 08:53:46 +02:00
|
|
|
Value: &InstallInfo{
|
|
|
|
Source: Sync,
|
|
|
|
Reason: Explicit,
|
|
|
|
Version: "",
|
|
|
|
SyncDBName: &dbName,
|
|
|
|
IsGroup: true,
|
|
|
|
},
|
2023-02-17 20:01:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
return graph
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Grapher) GraphAURTarget(ctx context.Context,
|
|
|
|
graph *topo.Graph[string, *InstallInfo],
|
|
|
|
pkg *aurc.Pkg, instalInfo *InstallInfo,
|
|
|
|
) *topo.Graph[string, *InstallInfo] {
|
|
|
|
if graph == nil {
|
2023-07-23 22:20:05 +02:00
|
|
|
graph = NewGraph()
|
2023-02-17 20:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
graph.AddNode(pkg.Name)
|
2023-05-01 17:56:42 +02:00
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
g.addAurPkgProvides(pkg, graph)
|
2023-05-01 17:56:42 +02:00
|
|
|
|
2023-02-17 20:01:26 +01:00
|
|
|
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
|
2023-04-27 09:04:09 +02:00
|
|
|
Color: colorMap[instalInfo.Reason],
|
2023-02-17 20:01:26 +01:00
|
|
|
Background: bgColorMap[AUR],
|
|
|
|
Value: instalInfo,
|
|
|
|
})
|
|
|
|
|
|
|
|
return graph
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
func (g *Grapher) GraphFromAUR(ctx context.Context,
|
2022-11-10 01:48:58 +01:00
|
|
|
graph *topo.Graph[string, *InstallInfo],
|
|
|
|
targets []string,
|
|
|
|
) (*topo.Graph[string, *InstallInfo], error) {
|
2022-10-28 00:38:11 +02:00
|
|
|
if graph == nil {
|
2023-07-23 22:20:05 +02:00
|
|
|
graph = NewGraph()
|
2022-10-28 00:38:11 +02:00
|
|
|
}
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
if len(targets) == 0 {
|
|
|
|
return graph, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
aurPkgs, errCache := g.aurClient.Get(ctx, &aurc.Query{By: aurc.Name, Needles: targets})
|
|
|
|
if errCache != nil {
|
2023-02-25 20:03:27 +01:00
|
|
|
g.logger.Errorln(errCache)
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range aurPkgs {
|
|
|
|
pkg := &aurPkgs[i]
|
|
|
|
if _, ok := g.providerCache[pkg.Name]; !ok {
|
|
|
|
g.providerCache[pkg.Name] = []aurc.Pkg{*pkg}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 23:18:41 +02:00
|
|
|
aurPkgsAdded := []*aurc.Pkg{}
|
|
|
|
|
2022-09-06 23:25:44 +02:00
|
|
|
for _, target := range targets {
|
2023-02-21 00:14:59 +01:00
|
|
|
if cachedProvidePkg, ok := g.providerCache[target]; ok {
|
|
|
|
aurPkgs = cachedProvidePkg
|
|
|
|
} else {
|
|
|
|
var errA error
|
|
|
|
aurPkgs, errA = g.aurClient.Get(ctx, &aurc.Query{By: aurc.Provides, Needles: []string{target}, Contains: true})
|
|
|
|
if errA != nil {
|
2023-05-08 23:43:50 +02:00
|
|
|
g.logger.Errorln(gotext.Get("Failed to find AUR package for"), " ", target, ":", errA)
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-28 00:38:11 +02:00
|
|
|
if len(aurPkgs) == 0 {
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Errorln(gotext.Get("No AUR package found for"), " ", target)
|
2022-10-28 00:38:11 +02:00
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
aurPkg := &aurPkgs[0]
|
|
|
|
if len(aurPkgs) > 1 {
|
|
|
|
chosen := g.provideMenu(target, aurPkgs)
|
|
|
|
aurPkg = chosen
|
|
|
|
g.providerCache[target] = []aurc.Pkg{*aurPkg}
|
|
|
|
}
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-06-11 18:16:05 +02:00
|
|
|
reason := Explicit
|
|
|
|
if pkg := g.dbExecutor.LocalPackage(aurPkg.Name); pkg != nil {
|
|
|
|
reason = Reason(pkg.Reason())
|
|
|
|
|
|
|
|
if g.needed {
|
2023-02-21 00:14:59 +01:00
|
|
|
if db.VerCmp(pkg.Version(), aurPkg.Version) >= 0 {
|
|
|
|
g.logger.Warnln(gotext.Get("%s is up to date -- skipping", text.Cyan(pkg.Name()+"-"+pkg.Version())))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
graph = g.GraphAURTarget(ctx, graph, aurPkg, &InstallInfo{
|
|
|
|
AURBase: &aurPkg.PackageBase,
|
2023-06-11 18:16:05 +02:00
|
|
|
Reason: reason,
|
2023-02-17 20:01:26 +01:00
|
|
|
Source: AUR,
|
2023-02-21 00:14:59 +01:00
|
|
|
Version: aurPkg.Version,
|
2022-09-09 17:38:48 +02:00
|
|
|
})
|
2023-05-23 23:18:41 +02:00
|
|
|
aurPkgsAdded = append(aurPkgsAdded, aurPkg)
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
2023-05-23 23:18:41 +02:00
|
|
|
g.AddDepsForPkgs(ctx, aurPkgsAdded, graph)
|
|
|
|
|
2022-09-06 23:25:44 +02:00
|
|
|
return graph, nil
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
// Removes found deps from the deps mapset and returns the found deps.
|
|
|
|
func (g *Grapher) findDepsFromAUR(ctx context.Context,
|
|
|
|
deps mapset.Set[string],
|
|
|
|
) []aurc.Pkg {
|
|
|
|
pkgsToAdd := make([]aurc.Pkg, 0, deps.Cardinality())
|
|
|
|
if deps.Cardinality() == 0 {
|
|
|
|
return []aurc.Pkg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
missingNeedles := make([]string, 0, deps.Cardinality())
|
|
|
|
for _, depString := range deps.ToSlice() {
|
|
|
|
if _, ok := g.providerCache[depString]; !ok {
|
|
|
|
depName, _, _ := splitDep(depString)
|
|
|
|
missingNeedles = append(missingNeedles, depName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(missingNeedles) != 0 {
|
|
|
|
g.logger.Debugln("deps to find", missingNeedles)
|
|
|
|
// provider search is more demanding than a simple search
|
|
|
|
// try to find name match if possible and then try to find provides.
|
|
|
|
aurPkgs, errCache := g.aurClient.Get(ctx, &aurc.Query{
|
|
|
|
By: aurc.Name, Needles: missingNeedles, Contains: false,
|
|
|
|
})
|
|
|
|
if errCache != nil {
|
2023-02-25 20:03:27 +01:00
|
|
|
g.logger.Errorln(errCache)
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range aurPkgs {
|
|
|
|
pkg := &aurPkgs[i]
|
2023-06-19 10:13:47 +02:00
|
|
|
if deps.Contains(pkg.Name) {
|
|
|
|
g.providerCache[pkg.Name] = append(g.providerCache[pkg.Name], *pkg)
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
for _, val := range pkg.Provides {
|
2023-06-19 10:13:47 +02:00
|
|
|
if val == pkg.Name {
|
|
|
|
continue
|
|
|
|
}
|
2023-02-21 00:14:59 +01:00
|
|
|
if deps.Contains(val) {
|
|
|
|
g.providerCache[val] = append(g.providerCache[val], *pkg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, depString := range deps.ToSlice() {
|
|
|
|
var aurPkgs []aurc.Pkg
|
|
|
|
depName, _, _ := splitDep(depString)
|
|
|
|
|
|
|
|
if cachedProvidePkg, ok := g.providerCache[depString]; ok {
|
|
|
|
aurPkgs = cachedProvidePkg
|
|
|
|
} else {
|
|
|
|
var errA error
|
|
|
|
aurPkgs, errA = g.aurClient.Get(ctx, &aurc.Query{By: aurc.Provides, Needles: []string{depName}, Contains: true})
|
|
|
|
if errA != nil {
|
|
|
|
g.logger.Errorln(gotext.Get("Failed to find AUR package for"), depString, ":", errA)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove packages that don't satisfy the dependency
|
|
|
|
for i := 0; i < len(aurPkgs); i++ {
|
|
|
|
if !satisfiesAur(depString, &aurPkgs[i]) {
|
|
|
|
aurPkgs = append(aurPkgs[:i], aurPkgs[i+1:]...)
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(aurPkgs) == 0 {
|
|
|
|
g.logger.Errorln(gotext.Get("No AUR package found for"), " ", depString)
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg := aurPkgs[0]
|
|
|
|
if len(aurPkgs) > 1 {
|
|
|
|
chosen := g.provideMenu(depString, aurPkgs)
|
|
|
|
pkg = *chosen
|
|
|
|
}
|
|
|
|
|
|
|
|
g.providerCache[depString] = []aurc.Pkg{pkg}
|
|
|
|
deps.Remove(depString)
|
|
|
|
pkgsToAdd = append(pkgsToAdd, pkg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkgsToAdd
|
|
|
|
}
|
|
|
|
|
2022-09-09 17:38:48 +02:00
|
|
|
func (g *Grapher) ValidateAndSetNodeInfo(graph *topo.Graph[string, *InstallInfo],
|
|
|
|
node string, nodeInfo *topo.NodeInfo[*InstallInfo],
|
|
|
|
) {
|
|
|
|
info := graph.GetNodeInfo(node)
|
2022-09-17 14:31:54 +02:00
|
|
|
if info != nil && info.Value != nil {
|
2023-04-27 09:04:09 +02:00
|
|
|
if info.Value.Reason < nodeInfo.Value.Reason {
|
2023-03-05 18:31:11 +01:00
|
|
|
return // refuse to downgrade reason
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
2023-04-27 09:04:09 +02:00
|
|
|
|
|
|
|
if info.Value.Upgrade {
|
|
|
|
return // refuse to overwrite an upgrade
|
|
|
|
}
|
2022-09-09 17:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
graph.SetNodeInfo(node, nodeInfo)
|
|
|
|
}
|
|
|
|
|
2022-09-06 23:25:44 +02:00
|
|
|
func (g *Grapher) addNodes(
|
2022-11-08 01:32:21 +01:00
|
|
|
ctx context.Context,
|
2022-09-09 17:38:48 +02:00
|
|
|
graph *topo.Graph[string, *InstallInfo],
|
2022-09-06 23:25:44 +02:00
|
|
|
parentPkgName string,
|
|
|
|
deps []string,
|
2022-09-09 17:38:48 +02:00
|
|
|
depType Reason,
|
2022-09-06 23:25:44 +02:00
|
|
|
) {
|
2023-02-21 00:14:59 +01:00
|
|
|
targetsToFind := mapset.NewThreadUnsafeSet(deps...)
|
|
|
|
// Check if in graph already
|
|
|
|
for _, depString := range targetsToFind.ToSlice() {
|
2023-03-05 18:31:11 +01:00
|
|
|
depName, _, _ := splitDep(depString)
|
2023-05-01 17:56:42 +02:00
|
|
|
if !graph.Exists(depName) && !graph.ProvidesExists(depName) {
|
2022-09-06 23:25:44 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-05-01 17:56:42 +02:00
|
|
|
if graph.Exists(depName) {
|
|
|
|
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
|
|
|
g.logger.Warnln(depString, parentPkgName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
targetsToFind.Remove(depString)
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-05-01 17:56:42 +02:00
|
|
|
if p := graph.GetProviderNode(depName); p != nil {
|
|
|
|
if provideSatisfies(p.String(), depString, p.Version) {
|
|
|
|
if err := graph.DependOn(p.Provider, parentPkgName); err != nil {
|
|
|
|
g.logger.Warnln(p.Provider, parentPkgName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
targetsToFind.Remove(depString)
|
|
|
|
}
|
|
|
|
}
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check installed
|
|
|
|
for _, depString := range targetsToFind.ToSlice() {
|
|
|
|
depName, _, _ := splitDep(depString)
|
|
|
|
if !g.dbExecutor.LocalSatisfierExists(depString) {
|
2022-09-06 23:25:44 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
if g.fullGraph {
|
2022-09-09 17:38:48 +02:00
|
|
|
g.ValidateAndSetNodeInfo(
|
|
|
|
graph,
|
2023-02-21 00:14:59 +01:00
|
|
|
depName,
|
|
|
|
&topo.NodeInfo[*InstallInfo]{Color: colorMap[depType], Background: bgColorMap[Local]})
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
|
|
|
g.logger.Warnln(depName, parentPkgName, err)
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
2023-02-21 00:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
targetsToFind.Remove(depString)
|
|
|
|
}
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
// Check Sync
|
|
|
|
for _, depString := range targetsToFind.ToSlice() {
|
|
|
|
alpmPkg := g.dbExecutor.SyncSatisfier(depString)
|
|
|
|
if alpmPkg == nil {
|
2022-09-06 23:25:44 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
if err := graph.DependOn(alpmPkg.Name(), parentPkgName); err != nil {
|
|
|
|
g.logger.Warnln("repo dep warn:", depString, parentPkgName, err)
|
2022-11-14 00:21:36 +01:00
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
dbName := alpmPkg.DB().Name()
|
|
|
|
g.ValidateAndSetNodeInfo(
|
|
|
|
graph,
|
|
|
|
alpmPkg.Name(),
|
|
|
|
&topo.NodeInfo[*InstallInfo]{
|
|
|
|
Color: colorMap[depType],
|
|
|
|
Background: bgColorMap[Sync],
|
|
|
|
Value: &InstallInfo{
|
|
|
|
Source: Sync,
|
|
|
|
Reason: depType,
|
|
|
|
Version: alpmPkg.Version(),
|
|
|
|
SyncDBName: &dbName,
|
|
|
|
},
|
|
|
|
})
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
if newDeps := alpmPkg.Depends().Slice(); len(newDeps) != 0 && g.fullGraph {
|
|
|
|
newDepsSlice := make([]string, 0, len(newDeps))
|
|
|
|
for _, newDep := range newDeps {
|
|
|
|
newDepsSlice = append(newDepsSlice, newDep.Name)
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
g.addNodes(ctx, graph, alpmPkg.Name(), newDepsSlice, Dep)
|
|
|
|
}
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
targetsToFind.Remove(depString)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check AUR
|
|
|
|
pkgsToAdd := g.findDepsFromAUR(ctx, targetsToFind)
|
|
|
|
for i := range pkgsToAdd {
|
|
|
|
aurPkg := &pkgsToAdd[i]
|
|
|
|
if err := graph.DependOn(aurPkg.Name, parentPkgName); err != nil {
|
|
|
|
g.logger.Warnln("aur dep warn:", aurPkg.Name, parentPkgName, err)
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
2022-09-07 01:03:29 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
graph.SetNodeInfo(
|
|
|
|
aurPkg.Name,
|
|
|
|
&topo.NodeInfo[*InstallInfo]{
|
|
|
|
Color: colorMap[depType],
|
|
|
|
Background: bgColorMap[AUR],
|
|
|
|
Value: &InstallInfo{
|
|
|
|
Source: AUR,
|
|
|
|
Reason: depType,
|
|
|
|
AURBase: &aurPkg.PackageBase,
|
|
|
|
Version: aurPkg.Version,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
g.addDepNodes(ctx, aurPkg, graph)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add missing to graph
|
|
|
|
for _, depString := range targetsToFind.ToSlice() {
|
|
|
|
depName, mod, ver := splitDep(depString)
|
2022-09-07 01:03:29 +02:00
|
|
|
// no dep found. add as missing
|
2023-06-11 18:10:48 +02:00
|
|
|
if err := graph.DependOn(depName, parentPkgName); err != nil {
|
|
|
|
g.logger.Warnln("missing dep warn:", depString, parentPkgName, err)
|
|
|
|
}
|
2022-12-29 13:34:53 +01:00
|
|
|
graph.SetNodeInfo(depName, &topo.NodeInfo[*InstallInfo]{
|
|
|
|
Color: colorMap[depType],
|
|
|
|
Background: bgColorMap[Missing],
|
|
|
|
Value: &InstallInfo{
|
|
|
|
Source: Missing,
|
|
|
|
Reason: depType,
|
|
|
|
Version: fmt.Sprintf("%s%s", mod, ver),
|
|
|
|
},
|
|
|
|
})
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
func (g *Grapher) provideMenu(dep string, options []aur.Pkg) *aur.Pkg {
|
2022-09-06 23:25:44 +02:00
|
|
|
size := len(options)
|
|
|
|
if size == 1 {
|
2022-12-29 19:42:43 +01:00
|
|
|
return &options[0]
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
str := text.Bold(gotext.Get("There are %d providers available for %s:", size, dep))
|
|
|
|
str += "\n"
|
|
|
|
|
|
|
|
size = 1
|
2023-02-21 00:14:59 +01:00
|
|
|
str += g.logger.SprintOperationInfo(gotext.Get("Repository AUR"), "\n ")
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2022-12-29 19:42:43 +01:00
|
|
|
for i := range options {
|
|
|
|
str += fmt.Sprintf("%d) %s ", size, options[i].Name)
|
2022-09-06 23:25:44 +02:00
|
|
|
size++
|
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.OperationInfoln(str)
|
2022-09-06 23:25:44 +02:00
|
|
|
|
|
|
|
for {
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Println(gotext.Get("\nEnter a number (default=1): "))
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
if g.noConfirm {
|
|
|
|
g.logger.Println("1")
|
2022-09-06 23:25:44 +02:00
|
|
|
|
2022-12-29 19:42:43 +01:00
|
|
|
return &options[0]
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
numberBuf, err := g.logger.GetInput("", false)
|
2022-09-06 23:25:44 +02:00
|
|
|
if err != nil {
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Errorln(err)
|
2022-09-06 23:25:44 +02:00
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if numberBuf == "" {
|
2022-12-29 19:42:43 +01:00
|
|
|
return &options[0]
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
num, err := strconv.Atoi(numberBuf)
|
|
|
|
if err != nil {
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Errorln(gotext.Get("invalid number: %s", numberBuf))
|
2022-09-06 23:25:44 +02:00
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if num < 1 || num >= size {
|
2023-02-21 00:14:59 +01:00
|
|
|
g.logger.Errorln(gotext.Get("invalid value: %d is not between %d and %d",
|
|
|
|
num, 1, size-1))
|
2022-09-06 23:25:44 +02:00
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-12-29 19:42:43 +01:00
|
|
|
return &options[num-1]
|
2022-09-06 23:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-06 23:38:47 +02:00
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]*aur.Pkg, error) {
|
|
|
|
pkgs := make([]*aur.Pkg, 0, 1)
|
2022-09-06 23:38:47 +02:00
|
|
|
|
|
|
|
alpmArch, err := dbExecutor.AlpmArchitectures()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
alpmArch = append(alpmArch, "") // srcinfo assumes no value as ""
|
|
|
|
|
2023-01-24 00:54:15 +01:00
|
|
|
getDesc := func(pkg *gosrc.Package) string {
|
|
|
|
if pkg.Pkgdesc != "" {
|
|
|
|
return pkg.Pkgdesc
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcInfo.Pkgdesc
|
|
|
|
}
|
|
|
|
|
2022-11-15 15:44:50 +01:00
|
|
|
for i := range srcInfo.Packages {
|
|
|
|
pkg := &srcInfo.Packages[i]
|
|
|
|
|
2023-06-03 15:53:33 +02:00
|
|
|
pkgs = append(pkgs, &aur.Pkg{
|
2022-09-06 23:38:47 +02:00
|
|
|
ID: 0,
|
|
|
|
Name: pkg.Pkgname,
|
|
|
|
PackageBaseID: 0,
|
|
|
|
PackageBase: srcInfo.Pkgbase,
|
|
|
|
Version: srcInfo.Version(),
|
2023-01-24 00:54:15 +01:00
|
|
|
Description: getDesc(pkg),
|
2022-09-06 23:38:47 +02:00
|
|
|
URL: pkg.URL,
|
2022-09-07 00:01:23 +02:00
|
|
|
Depends: append(archStringToString(alpmArch, pkg.Depends),
|
|
|
|
archStringToString(alpmArch, srcInfo.Package.Depends)...),
|
|
|
|
MakeDepends: archStringToString(alpmArch, srcInfo.PackageBase.MakeDepends),
|
|
|
|
CheckDepends: archStringToString(alpmArch, srcInfo.PackageBase.CheckDepends),
|
|
|
|
Conflicts: append(archStringToString(alpmArch, pkg.Conflicts),
|
|
|
|
archStringToString(alpmArch, srcInfo.Package.Conflicts)...),
|
|
|
|
Provides: append(archStringToString(alpmArch, pkg.Provides),
|
|
|
|
archStringToString(alpmArch, srcInfo.Package.Provides)...),
|
|
|
|
Replaces: append(archStringToString(alpmArch, pkg.Replaces),
|
|
|
|
archStringToString(alpmArch, srcInfo.Package.Replaces)...),
|
|
|
|
OptDepends: []string{},
|
|
|
|
Groups: pkg.Groups,
|
|
|
|
License: pkg.License,
|
|
|
|
Keywords: []string{},
|
2022-09-06 23:38:47 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkgs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func archStringToString(alpmArches []string, archString []gosrc.ArchString) []string {
|
|
|
|
pkgs := make([]string, 0, len(archString))
|
|
|
|
|
|
|
|
for _, arch := range archString {
|
|
|
|
if db.ArchIsSupported(alpmArches, arch.Arch) {
|
|
|
|
pkgs = append(pkgs, arch.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pkgs
|
|
|
|
}
|
2023-05-01 17:56:42 +02:00
|
|
|
|
|
|
|
func aurDepModToAlpmDep(mod string) alpm.DepMod {
|
|
|
|
switch mod {
|
|
|
|
case "=":
|
|
|
|
return alpm.DepModEq
|
|
|
|
case ">=":
|
|
|
|
return alpm.DepModGE
|
|
|
|
case "<=":
|
|
|
|
return alpm.DepModLE
|
|
|
|
case ">":
|
|
|
|
return alpm.DepModGT
|
|
|
|
case "<":
|
|
|
|
return alpm.DepModLT
|
|
|
|
}
|
|
|
|
return alpm.DepModAny
|
|
|
|
}
|