mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 09:37:22 +01:00
allow pkgdest specification
This commit is contained in:
parent
351e352f64
commit
915799755b
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v11/pkg/db"
|
"github.com/Jguer/yay/v11/pkg/db"
|
||||||
"github.com/Jguer/yay/v11/pkg/dep"
|
"github.com/Jguer/yay/v11/pkg/dep"
|
||||||
@ -66,11 +67,12 @@ func installLocalPKGBUILD(
|
|||||||
preparer := &Preparer{dbExecutor: dbExecutor, cmdBuilder: config.Runtime.CmdBuilder}
|
preparer := &Preparer{dbExecutor: dbExecutor, cmdBuilder: config.Runtime.CmdBuilder}
|
||||||
installer := &Installer{dbExecutor: dbExecutor}
|
installer := &Installer{dbExecutor: dbExecutor}
|
||||||
|
|
||||||
if err := preparer.PrepareWorkspace(ctx, topoSorted); err != nil {
|
pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return installer.Install(ctx, cmdArgs, topoSorted)
|
return installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Preparer struct {
|
type Preparer struct {
|
||||||
@ -81,38 +83,44 @@ type Preparer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[string]*dep.InstallInfo,
|
func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[string]*dep.InstallInfo,
|
||||||
) error {
|
) (map[string]string, error) {
|
||||||
|
pkgBuildDirs := make(map[string]string, 0)
|
||||||
|
|
||||||
for _, layer := range targets {
|
for _, layer := range targets {
|
||||||
for pkgBase, info := range layer {
|
for pkgBase, info := range layer {
|
||||||
if info.Source == dep.AUR {
|
if info.Source == dep.AUR {
|
||||||
preper.aurBases = append(preper.aurBases, pkgBase)
|
preper.aurBases = append(preper.aurBases, pkgBase)
|
||||||
preper.pkgBuildDirs = append(preper.pkgBuildDirs, filepath.Join(config.BuildDir, pkgBase))
|
pkgBuildDirs[pkgBase] = filepath.Join(config.BuildDir, pkgBase)
|
||||||
} else if info.Source == dep.SrcInfo {
|
} else if info.Source == dep.SrcInfo {
|
||||||
preper.pkgBuildDirs = append(preper.pkgBuildDirs, *info.SrcinfoPath)
|
pkgBuildDirs[pkgBase] = *info.SrcinfoPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, errA := download.AURPKGBUILDRepos(ctx,
|
if _, errA := download.AURPKGBUILDRepos(ctx,
|
||||||
preper.cmdBuilder, preper.aurBases, config.AURURL, config.BuildDir, false); errA != nil {
|
preper.cmdBuilder, preper.aurBases, config.AURURL, config.BuildDir, false); errA != nil {
|
||||||
return errA
|
return nil, errA
|
||||||
}
|
}
|
||||||
|
|
||||||
if errP := downloadPKGBUILDSourceFanout(ctx, config.Runtime.CmdBuilder,
|
if errP := downloadPKGBUILDSourceFanout(ctx, config.Runtime.CmdBuilder,
|
||||||
preper.pkgBuildDirs, false, config.MaxConcurrentDownloads); errP != nil {
|
preper.pkgBuildDirs, false, config.MaxConcurrentDownloads); errP != nil {
|
||||||
text.Errorln(errP)
|
text.Errorln(errP)
|
||||||
}
|
}
|
||||||
return nil
|
return pkgBuildDirs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Installer struct {
|
type Installer struct {
|
||||||
dbExecutor db.Executor
|
dbExecutor db.Executor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (installer *Installer) Install(ctx context.Context, cmdArgs *parser.Arguments, targets []map[string]*dep.InstallInfo) error {
|
func (installer *Installer) Install(ctx context.Context,
|
||||||
|
cmdArgs *parser.Arguments,
|
||||||
|
targets []map[string]*dep.InstallInfo,
|
||||||
|
pkgBuildDirs map[string]string,
|
||||||
|
) error {
|
||||||
// Reorganize targets into layers of dependencies
|
// Reorganize targets into layers of dependencies
|
||||||
for i := len(targets) - 1; i >= 0; i-- {
|
for i := len(targets) - 1; i >= 0; i-- {
|
||||||
err := installer.handleLayer(ctx, cmdArgs, targets[i])
|
err := installer.handleLayer(ctx, cmdArgs, targets[i], pkgBuildDirs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// rollback
|
// rollback
|
||||||
return err
|
return err
|
||||||
@ -138,7 +146,9 @@ func (m *MapBySourceAndType) String() string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (installer *Installer) handleLayer(ctx context.Context, cmdArgs *parser.Arguments, layer map[string]*dep.InstallInfo) error {
|
func (installer *Installer) handleLayer(ctx context.Context,
|
||||||
|
cmdArgs *parser.Arguments, layer map[string]*dep.InstallInfo, pkgBuildDirs map[string]string,
|
||||||
|
) error {
|
||||||
// Install layer
|
// Install layer
|
||||||
depByTypeAndReason := make(MapBySourceAndType)
|
depByTypeAndReason := make(MapBySourceAndType)
|
||||||
for name, info := range layer {
|
for name, info := range layer {
|
||||||
@ -157,6 +167,8 @@ func (installer *Installer) handleLayer(ctx context.Context, cmdArgs *parser.Arg
|
|||||||
aurDeps, aurExp := mapset.NewSet[string](), mapset.NewSet[string]()
|
aurDeps, aurExp := mapset.NewSet[string](), mapset.NewSet[string]()
|
||||||
for source, reasons := range depByTypeAndReason {
|
for source, reasons := range depByTypeAndReason {
|
||||||
switch source {
|
switch source {
|
||||||
|
case dep.SrcInfo:
|
||||||
|
fallthrough
|
||||||
case dep.AUR:
|
case dep.AUR:
|
||||||
for reason, names := range reasons {
|
for reason, names := range reasons {
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
@ -205,7 +217,9 @@ func (installer *Installer) handleLayer(ctx context.Context, cmdArgs *parser.Arg
|
|||||||
return ErrInstallRepoPkgs
|
return ErrInstallRepoPkgs
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
errAur := installer.installAURPackages(ctx, cmdArgs, aurDeps, aurExp, pkgBuildDirs, false)
|
||||||
|
|
||||||
|
return errAur
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Installer) installAURPackages(ctx context.Context, cmdArgs *parser.Arguments, aurBaseDeps, aurBaseExp mapset.Set[string], pkgBuildDirs map[string]string, installIncompatible bool) error {
|
func (*Installer) installAURPackages(ctx context.Context, cmdArgs *parser.Arguments, aurBaseDeps, aurBaseExp mapset.Set[string], pkgBuildDirs map[string]string, installIncompatible bool) error {
|
||||||
@ -241,14 +255,12 @@ func (*Installer) installAURPackages(ctx context.Context, cmdArgs *parser.Argume
|
|||||||
return errors.New(gotext.Get("error making: %s", base))
|
return errors.New(gotext.Get("error making: %s", base))
|
||||||
}
|
}
|
||||||
|
|
||||||
for suffix, optional := range map[string]bool{"": false, "-debug": true} {
|
newDeps, newExp, err := getNewTargets(cmdArgs, pkgdests, aurBaseDeps.Contains(base))
|
||||||
newDeps, newExp, err := getNewTargets(cmdArgs, pkgdests, base+suffix, aurBaseDeps.Contains(base), optional)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
deps = append(deps, newDeps...)
|
|
||||||
exp = append(exp, newExp...)
|
|
||||||
}
|
}
|
||||||
|
deps = append(deps, newDeps...)
|
||||||
|
exp = append(exp, newExp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := doInstall(ctx, cmdArgs, deps, exp); err != nil {
|
if err := doInstall(ctx, cmdArgs, deps, exp); err != nil {
|
||||||
@ -258,11 +270,11 @@ func (*Installer) installAURPackages(ctx context.Context, cmdArgs *parser.Argume
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNewTargets(cmdArgs *parser.Arguments, pkgdests map[string]string, name string, isDep, optional bool,
|
func getNewTargets(cmdArgs *parser.Arguments, pkgdests map[string]string, isDep bool,
|
||||||
) (deps, exp []string, err error) {
|
) (deps, exp []string, err error) {
|
||||||
for pkgName, pkgDest := range pkgdests {
|
for pkgName, pkgDest := range pkgdests {
|
||||||
if _, errStat := os.Stat(pkgDest); os.IsNotExist(errStat) {
|
if _, errStat := os.Stat(pkgDest); os.IsNotExist(errStat) {
|
||||||
if optional {
|
if strings.HasSuffix(pkgName, "-debug") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,13 +286,13 @@ func getNewTargets(cmdArgs *parser.Arguments, pkgdests map[string]string, name s
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case cmdArgs.ExistsArg("asdeps", "asdep"):
|
case cmdArgs.ExistsArg("asdeps", "asdep"):
|
||||||
deps = append(deps, name)
|
deps = append(deps, pkgName)
|
||||||
case cmdArgs.ExistsArg("asexplicit", "asexp"):
|
case cmdArgs.ExistsArg("asexplicit", "asexp"):
|
||||||
exp = append(exp, name)
|
exp = append(exp, pkgName)
|
||||||
case isDep:
|
case isDep:
|
||||||
deps = append(deps, name)
|
deps = append(deps, pkgName)
|
||||||
default:
|
default:
|
||||||
exp = append(exp, name)
|
exp = append(exp, pkgName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,6 +304,10 @@ func (*Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Argum
|
|||||||
syncDeps, // repo targets that are deps
|
syncDeps, // repo targets that are deps
|
||||||
syncExp []string, // repo targets that are exp
|
syncExp []string, // repo targets that are exp
|
||||||
) error {
|
) error {
|
||||||
|
if len(repoTargets) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
arguments := cmdArgs.Copy()
|
arguments := cmdArgs.Copy()
|
||||||
arguments.DelArg("asdeps", "asdep")
|
arguments.DelArg("asdeps", "asdep")
|
||||||
arguments.DelArg("asexplicit", "asexp")
|
arguments.DelArg("asexplicit", "asexp")
|
||||||
|
Loading…
Reference in New Issue
Block a user