|
@@ -5,13 +5,16 @@ package main
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io"
|
|
"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"
|
|
"github.com/Jguer/yay/v11/pkg/download"
|
|
"github.com/Jguer/yay/v11/pkg/download"
|
|
"github.com/Jguer/yay/v11/pkg/metadata"
|
|
"github.com/Jguer/yay/v11/pkg/metadata"
|
|
|
|
+ "github.com/Jguer/yay/v11/pkg/multierror"
|
|
"github.com/Jguer/yay/v11/pkg/settings"
|
|
"github.com/Jguer/yay/v11/pkg/settings"
|
|
"github.com/Jguer/yay/v11/pkg/settings/exe"
|
|
"github.com/Jguer/yay/v11/pkg/settings/exe"
|
|
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
|
"github.com/Jguer/yay/v11/pkg/settings/parser"
|
|
@@ -63,41 +66,120 @@ func installLocalPKGBUILD(
|
|
topoSorted := graph.TopoSortedLayerMap()
|
|
topoSorted := graph.TopoSortedLayerMap()
|
|
fmt.Println(topoSorted, len(topoSorted))
|
|
fmt.Println(topoSorted, len(topoSorted))
|
|
|
|
|
|
- preparer := &Preparer{dbExecutor: dbExecutor, cmdBuilder: config.Runtime.CmdBuilder}
|
|
|
|
|
|
+ preparer := &Preparer{
|
|
|
|
+ dbExecutor: dbExecutor,
|
|
|
|
+ cmdBuilder: config.Runtime.CmdBuilder,
|
|
|
|
+ config: config,
|
|
|
|
+ }
|
|
installer := &Installer{dbExecutor: dbExecutor}
|
|
installer := &Installer{dbExecutor: dbExecutor}
|
|
|
|
|
|
|
|
+ err = preparer.Present(os.Stdout, topoSorted)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cleanFunc := preparer.ShouldCleanMakeDeps(ctx)
|
|
|
|
+ if cleanFunc != nil {
|
|
|
|
+ installer.AddPostInstallHook(cleanFunc)
|
|
|
|
+ }
|
|
|
|
+
|
|
pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
|
|
pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- return installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs)
|
|
|
|
|
|
+ err = installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs)
|
|
|
|
+ if err != nil {
|
|
|
|
+ if errHook := installer.RunPostInstallHooks(ctx); errHook != nil {
|
|
|
|
+ text.Errorln(errHook)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return installer.RunPostInstallHooks(ctx)
|
|
}
|
|
}
|
|
|
|
|
|
type Preparer struct {
|
|
type Preparer struct {
|
|
- dbExecutor db.Executor
|
|
|
|
- cmdBuilder exe.ICmdBuilder
|
|
|
|
- aurBases []string
|
|
|
|
|
|
+ dbExecutor db.Executor
|
|
|
|
+ cmdBuilder exe.ICmdBuilder
|
|
|
|
+ config *settings.Configuration
|
|
|
|
+
|
|
pkgBuildDirs []string
|
|
pkgBuildDirs []string
|
|
|
|
+ makeDeps []string
|
|
}
|
|
}
|
|
|
|
|
|
-func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[string]*dep.InstallInfo,
|
|
|
|
-) (map[string]string, error) {
|
|
|
|
|
|
+func (preper *Preparer) ShouldCleanMakeDeps(ctx context.Context) PostInstallHookFunc {
|
|
|
|
+ if len(preper.makeDeps) == 0 {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch preper.config.RemoveMake {
|
|
|
|
+ case "yes":
|
|
|
|
+ break
|
|
|
|
+ case "no":
|
|
|
|
+ return nil
|
|
|
|
+ default:
|
|
|
|
+ if !text.ContinueTask(os.Stdin, gotext.Get("Remove make dependencies after install?"), false, settings.NoConfirm) {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return func(ctx context.Context) error {
|
|
|
|
+ return removeMake(ctx, preper.config.Runtime.CmdBuilder, preper.makeDeps)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (preper *Preparer) Present(w io.Writer, targets []map[string]*dep.InstallInfo) error {
|
|
|
|
+ pkgsBySourceAndReason := map[string]map[string][]string{}
|
|
|
|
+
|
|
|
|
+ for _, layer := range targets {
|
|
|
|
+ for pkgName, info := range layer {
|
|
|
|
+ source := dep.SourceNames[info.Source]
|
|
|
|
+ reason := dep.ReasonNames[info.Reason]
|
|
|
|
+ pkgStr := text.Cyan(fmt.Sprintf("%s-%s", pkgName, info.Version))
|
|
|
|
+ if _, ok := pkgsBySourceAndReason[source]; !ok {
|
|
|
|
+ pkgsBySourceAndReason[source] = map[string][]string{}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pkgsBySourceAndReason[source][reason] = append(pkgsBySourceAndReason[source][reason], pkgStr)
|
|
|
|
+ if info.Reason == dep.MakeDep {
|
|
|
|
+ preper.makeDeps = append(preper.makeDeps, pkgName)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for source, pkgsByReason := range pkgsBySourceAndReason {
|
|
|
|
+ for reason, pkgs := range pkgsByReason {
|
|
|
|
+ fmt.Fprintf(w, text.Bold("%s %s (%d):")+" %s\n",
|
|
|
|
+ source,
|
|
|
|
+ reason,
|
|
|
|
+ len(pkgs),
|
|
|
|
+ strings.Join(pkgs, ", "))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[string]*dep.InstallInfo) (map[string]string, error) {
|
|
|
|
+ aurBases := mapset.NewThreadUnsafeSet[string]()
|
|
pkgBuildDirs := make(map[string]string, 0)
|
|
pkgBuildDirs := make(map[string]string, 0)
|
|
|
|
|
|
for _, layer := range targets {
|
|
for _, layer := range targets {
|
|
- for pkgBase, info := range layer {
|
|
|
|
|
|
+ for pkgName, info := range layer {
|
|
if info.Source == dep.AUR {
|
|
if info.Source == dep.AUR {
|
|
- preper.aurBases = append(preper.aurBases, pkgBase)
|
|
|
|
- pkgBuildDirs[pkgBase] = filepath.Join(config.BuildDir, pkgBase)
|
|
|
|
|
|
+ pkgBase := *info.AURBase
|
|
|
|
+ aurBases.Add(pkgBase)
|
|
|
|
+ pkgBuildDirs[pkgName] = filepath.Join(config.BuildDir, pkgBase)
|
|
} else if info.Source == dep.SrcInfo {
|
|
} else if info.Source == dep.SrcInfo {
|
|
- pkgBuildDirs[pkgBase] = *info.SrcinfoPath
|
|
|
|
|
|
+ pkgBuildDirs[pkgName] = *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, aurBases.ToSlice(), config.AURURL, config.BuildDir, false); errA != nil {
|
|
return nil, errA
|
|
return nil, errA
|
|
}
|
|
}
|
|
|
|
|
|
@@ -108,8 +190,26 @@ func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[stri
|
|
return pkgBuildDirs, nil
|
|
return pkgBuildDirs, nil
|
|
}
|
|
}
|
|
|
|
|
|
-type Installer struct {
|
|
|
|
- dbExecutor db.Executor
|
|
|
|
|
|
+type (
|
|
|
|
+ PostInstallHookFunc func(ctx context.Context) error
|
|
|
|
+ Installer struct {
|
|
|
|
+ dbExecutor db.Executor
|
|
|
|
+ postInstallHooks []PostInstallHookFunc
|
|
|
|
+ }
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func (installer *Installer) AddPostInstallHook(hook PostInstallHookFunc) {
|
|
|
|
+ installer.postInstallHooks = append(installer.postInstallHooks, hook)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (Installer *Installer) RunPostInstallHooks(ctx context.Context) error {
|
|
|
|
+ var errMulti multierror.MultiError
|
|
|
|
+ for _, hook := range Installer.postInstallHooks {
|
|
|
|
+ if err := hook(ctx); err != nil {
|
|
|
|
+ errMulti.Add(err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return errMulti.Return()
|
|
}
|
|
}
|
|
|
|
|
|
func (installer *Installer) Install(ctx context.Context,
|
|
func (installer *Installer) Install(ctx context.Context,
|