yay/sync.go

68 lines
1.6 KiB
Go
Raw Normal View History

2022-09-20 00:01:19 +02:00
package main
import (
"context"
"os"
"path/filepath"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/metadata"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
)
func syncInstall(ctx context.Context,
config *settings.Configuration,
cmdArgs *parser.Arguments, dbExecutor db.Executor,
) error {
aurCache, err := metadata.NewAURCache(filepath.Join(config.BuildDir, "aur.json"))
if err != nil {
return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
}
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
2022-10-28 00:38:11 +02:00
graph, err := grapher.GraphFromTargets(cmdArgs.Targets)
2022-09-20 00:01:19 +02:00
if err != nil {
return err
}
topoSorted := graph.TopoSortedLayerMap()
preparer := &Preparer{
dbExecutor: dbExecutor,
cmdBuilder: config.Runtime.CmdBuilder,
config: config,
}
installer := &Installer{dbExecutor: dbExecutor}
2022-09-20 00:44:06 +02:00
if err = preparer.Present(os.Stdout, topoSorted); err != nil {
2022-09-20 00:01:19 +02:00
return err
}
cleanFunc := preparer.ShouldCleanMakeDeps(ctx)
if cleanFunc != nil {
installer.AddPostInstallHook(cleanFunc)
}
pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
if err != nil {
return err
}
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)
}