local_install.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Experimental code for install local with dependency refactoring
  2. // Not at feature parity with install.go
  3. package main
  4. import (
  5. "context"
  6. "path/filepath"
  7. "strings"
  8. "github.com/Jguer/yay/v11/pkg/db"
  9. "github.com/Jguer/yay/v11/pkg/dep"
  10. "github.com/Jguer/yay/v11/pkg/multierror"
  11. "github.com/Jguer/yay/v11/pkg/settings"
  12. "github.com/Jguer/yay/v11/pkg/settings/parser"
  13. "github.com/Jguer/yay/v11/pkg/topo"
  14. gosrc "github.com/Morganamilo/go-srcinfo"
  15. "github.com/leonelquinteros/gotext"
  16. "github.com/pkg/errors"
  17. )
  18. var ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
  19. func installLocalPKGBUILD(
  20. ctx context.Context,
  21. config *settings.Configuration,
  22. cmdArgs *parser.Arguments,
  23. dbExecutor db.Executor,
  24. ) error {
  25. aurCache := config.Runtime.AURCache
  26. noCheck := strings.Contains(config.MFlags, "--nocheck")
  27. if len(cmdArgs.Targets) < 1 {
  28. return errors.New(gotext.Get("no target directories specified"))
  29. }
  30. grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm,
  31. cmdArgs.ExistsDouble("d", "nodeps"), noCheck, cmdArgs.ExistsArg("needed"),
  32. config.Runtime.Logger.Child("grapher"))
  33. graph := topo.New[string, *dep.InstallInfo]()
  34. for _, target := range cmdArgs.Targets {
  35. var errG error
  36. pkgbuild, err := gosrc.ParseFile(filepath.Join(target, ".SRCINFO"))
  37. if err != nil {
  38. return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
  39. }
  40. graph, errG = grapher.GraphFromSrcInfo(ctx, graph, target, pkgbuild)
  41. if errG != nil {
  42. return err
  43. }
  44. }
  45. opService := NewOperationService(ctx, config, dbExecutor)
  46. multiErr := &multierror.MultiError{}
  47. targets := graph.TopoSortedLayerMap(func(name string, ii *dep.InstallInfo) error {
  48. if ii.Source == dep.Missing {
  49. multiErr.Add(errors.New(gotext.Get("could not find %s%s", name, ii.Version)))
  50. }
  51. return nil
  52. })
  53. if err := multiErr.Return(); err != nil {
  54. return err
  55. }
  56. return opService.Run(ctx, cmdArgs, targets)
  57. }