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"
|
2023-02-25 18:44:24 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-08-22 23:28:53 +02:00
|
|
|
"path/filepath"
|
2022-12-18 21:14:41 +01:00
|
|
|
"strings"
|
2022-08-21 07:14:52 +02:00
|
|
|
|
2023-03-07 22:04:06 +01: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
|
|
|
)
|
|
|
|
|
2023-02-25 18:44:24 +01: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
|
2022-12-18 21:14:41 +01:00
|
|
|
noCheck := strings.Contains(config.MFlags, "--nocheck")
|
2022-09-04 23:45:40 +02:00
|
|
|
|
2022-11-16 00:45:59 +01:00
|
|
|
if len(cmdArgs.Targets) < 1 {
|
|
|
|
return errors.New(gotext.Get("no target directories specified"))
|
2022-08-22 23:28:53 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 00:14:59 +01:00
|
|
|
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
|
|
|
|
cmdArgs.ExistsDouble("d", "nodeps"), noCheck, cmdArgs.ExistsArg("needed"),
|
|
|
|
config.Runtime.Logger.Child("grapher"))
|
2022-11-16 00:45:59 +01:00
|
|
|
graph := topo.New[string, *dep.InstallInfo]()
|
2023-02-25 18:44:24 +01:00
|
|
|
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
|
|
|
|
2023-02-25 18:44:24 +01:00
|
|
|
pkgbuild, err := gosrc.ParseFile(filepath.Join(targetDir, ".SRCINFO"))
|
2022-11-16 00:45:59 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
|
|
|
|
}
|
|
|
|
|
2023-02-25 18:44:24 +01:00
|
|
|
var errG error
|
|
|
|
graph, errG = grapher.GraphFromSrcInfo(ctx, graph, targetDir, pkgbuild)
|
2022-11-16 00:45:59 +01:00
|
|
|
if errG != nil {
|
2023-02-25 18:44:24 +01:00
|
|
|
return errG
|
2022-11-16 00:45:59 +01:00
|
|
|
}
|
2022-08-22 23:28:53 +02:00
|
|
|
}
|
|
|
|
|
2022-11-20 14:02:01 +01:00
|
|
|
opService := NewOperationService(ctx, config, dbExecutor)
|
2022-12-29 13:34:53 +01:00
|
|
|
multiErr := &multierror.MultiError{}
|
|
|
|
targets := graph.TopoSortedLayerMap(func(name string, ii *dep.InstallInfo) error {
|
|
|
|
if ii.Source == dep.Missing {
|
2023-02-25 18:44:24 +01:00
|
|
|
multiErr.Add(fmt.Errorf("%w: %s %s", ErrPackagesNotFound, name, ii.Version))
|
2022-12-29 13:34:53 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err := multiErr.Return(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-05 18:31:11 +01:00
|
|
|
return opService.Run(ctx, cmdArgs, targets, []string{})
|
2022-09-09 20:57:18 +02:00
|
|
|
}
|