yay/local_install.go

88 lines
2.2 KiB
Go
Raw Normal View History

2022-09-09 20:57:18 +02:00
// Experimental code for install local with dependency refactoring
// Not at feature parity with install.go
2022-08-21 07:14:52 +02:00
package main
import (
"context"
2022-08-22 23:28:53 +02:00
"os"
"path/filepath"
2022-08-21 07:14:52 +02:00
"github.com/Jguer/yay/v11/pkg/db"
2022-08-22 23:28:53 +02:00
"github.com/Jguer/yay/v11/pkg/dep"
2022-09-06 23:38:47 +02:00
"github.com/Jguer/yay/v11/pkg/settings"
2022-08-21 07:14:52 +02:00
"github.com/Jguer/yay/v11/pkg/settings/parser"
2022-09-11 23:15:31 +02:00
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/topo"
2022-09-11 23:15:31 +02:00
gosrc "github.com/Morganamilo/go-srcinfo"
2022-11-15 15:44:50 +01:00
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
2022-08-21 07:14:52 +02:00
)
2022-09-09 20:57:18 +02:00
var ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
2022-08-21 07:14:52 +02:00
func installLocalPKGBUILD(
ctx context.Context,
2022-11-15 16:22:57 +01:00
config *settings.Configuration,
2022-08-21 07:14:52 +02:00
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
) error {
2022-11-15 16:22:57 +01:00
aurCache := config.Runtime.AURCache
2022-09-04 23:45:40 +02:00
if len(cmdArgs.Targets) < 1 {
return errors.New(gotext.Get("no target directories specified"))
2022-08-22 23:28:53 +02:00
}
2022-09-06 23:38:47 +02:00
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
graph := topo.New[string, *dep.InstallInfo]()
for _, target := range cmdArgs.Targets {
var errG error
2022-09-06 23:38:47 +02:00
pkgbuild, err := gosrc.ParseFile(filepath.Join(target, ".SRCINFO"))
if err != nil {
return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
}
graph, errG = grapher.GraphFromSrcInfo(ctx, graph, target, pkgbuild)
if errG != nil {
return err
}
2022-08-22 23:28:53 +02:00
}
2022-09-09 17:38:48 +02:00
topoSorted := graph.TopoSortedLayerMap()
2022-08-22 23:28:53 +02:00
2022-09-20 00:01:19 +02:00
preparer := &Preparer{
dbExecutor: dbExecutor,
cmdBuilder: config.Runtime.CmdBuilder,
config: config,
}
2022-09-09 17:38:48 +02:00
installer := &Installer{dbExecutor: dbExecutor}
2022-11-15 15:44:50 +01:00
if errP := preparer.Present(os.Stdout, topoSorted); errP != nil {
return errP
2022-09-20 00:01:19 +02:00
}
2022-11-15 15:44:50 +01:00
if cleanFunc := preparer.ShouldCleanMakeDeps(); cleanFunc != nil {
2022-09-20 00:01:19 +02:00
installer.AddPostInstallHook(cleanFunc)
}
2022-09-12 00:10:19 +02:00
pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
if err != nil {
2022-09-09 20:57:18 +02:00
return err
}
2022-11-15 15:44:50 +01:00
if cleanAURDirsFunc := preparer.ShouldCleanAURDirs(pkgBuildDirs); cleanAURDirsFunc != nil {
2022-11-14 01:14:13 +01:00
installer.AddPostInstallHook(cleanAURDirsFunc)
}
2022-09-20 00:44:06 +02:00
if err = installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs); err != nil {
2022-09-20 00:01:19 +02:00
if errHook := installer.RunPostInstallHooks(ctx); errHook != nil {
text.Errorln(errHook)
}
return err
}
return installer.RunPostInstallHooks(ctx)
2022-09-09 20:57:18 +02:00
}