yay/local_install.go

106 lines
3.0 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"
"fmt"
"os"
2022-08-22 23:28:53 +02:00
"path/filepath"
"strings"
2022-08-21 07:14:52 +02:00
"github.com/Jguer/yay/v12/pkg/db"
"github.com/Jguer/yay/v12/pkg/dep"
"github.com/Jguer/yay/v12/pkg/multierror"
"github.com/Jguer/yay/v12/pkg/settings"
"github.com/Jguer/yay/v12/pkg/settings/exe"
"github.com/Jguer/yay/v12/pkg/settings/parser"
"github.com/Jguer/yay/v12/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
)
var (
ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
ErrNoBuildFiles = errors.New(gotext.Get("cannot find PKGBUILD and .SRCINFO in directory"))
)
func srcinfoExists(ctx context.Context,
cmdBuilder exe.ICmdBuilder, targetDir string,
) error {
srcInfoDir := filepath.Join(targetDir, ".SRCINFO")
pkgbuildDir := filepath.Join(targetDir, "PKGBUILD")
if _, err := os.Stat(srcInfoDir); err == nil {
if _, err := os.Stat(pkgbuildDir); err == nil {
return nil
}
}
if _, err := os.Stat(pkgbuildDir); err == nil {
// run makepkg to generate .SRCINFO
srcinfo, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildMakepkgCmd(ctx, targetDir, "--printsrcinfo"))
if err != nil {
return fmt.Errorf("unable to generate .SRCINFO: %w - %s", err, stderr)
}
if err := os.WriteFile(srcInfoDir, []byte(srcinfo), 0o600); err != nil {
return fmt.Errorf("unable to write .SRCINFO: %w", err)
}
return nil
}
return fmt.Errorf("%w: %s", ErrNoBuildFiles, targetDir)
}
2022-09-09 20:57:18 +02:00
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
noCheck := strings.Contains(config.MFlags, "--nocheck")
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
}
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
cmdArgs.ExistsDouble("d", "nodeps"), noCheck, cmdArgs.ExistsArg("needed"),
config.Runtime.Logger.Child("grapher"))
graph := topo.New[string, *dep.InstallInfo]()
for _, targetDir := range cmdArgs.Targets {
if err := srcinfoExists(ctx, config.Runtime.CmdBuilder, targetDir); err != nil {
return err
}
2022-09-06 23:38:47 +02:00
pkgbuild, err := gosrc.ParseFile(filepath.Join(targetDir, ".SRCINFO"))
if err != nil {
return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
}
var errG error
graph, errG = grapher.GraphFromSrcInfo(ctx, graph, targetDir, pkgbuild)
if errG != nil {
return errG
}
2022-08-22 23:28:53 +02:00
}
opService := NewOperationService(ctx, config, dbExecutor)
multiErr := &multierror.MultiError{}
targets := graph.TopoSortedLayerMap(func(name string, ii *dep.InstallInfo) error {
if ii.Source == dep.Missing {
multiErr.Add(fmt.Errorf("%w: %s %s", ErrPackagesNotFound, name, ii.Version))
}
return nil
})
if err := multiErr.Return(); err != nil {
return err
}
return opService.Run(ctx, cmdArgs, targets, []string{})
2022-09-09 20:57:18 +02:00
}