yay/local_install.go

95 lines
2.3 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-04 23:45:40 +02:00
"github.com/Jguer/yay/v11/pkg/metadata"
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"
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,
cmdArgs *parser.Arguments,
dbExecutor db.Executor,
) error {
2022-09-06 23:38:47 +02:00
aurCache, err := metadata.NewAURCache(filepath.Join(config.BuildDir, "aur.json"))
2022-09-04 23:45:40 +02:00
if err != nil {
return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
}
2022-08-22 23:28:53 +02:00
wd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, gotext.Get("failed to retrieve working directory"))
}
if len(cmdArgs.Targets) > 1 {
return errors.New(gotext.Get("only one target is allowed"))
}
if len(cmdArgs.Targets) == 1 {
wd = cmdArgs.Targets[0]
}
pkgbuild, err := gosrc.ParseFile(filepath.Join(wd, ".SRCINFO"))
if err != nil {
return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
}
2022-09-06 23:38:47 +02:00
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
2022-11-08 01:32:21 +01:00
graph, err := grapher.GraphFromSrcInfo(ctx, nil, wd, pkgbuild)
2022-08-22 23:28:53 +02:00
if err != nil {
return err
}
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
}