local_install.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. "os"
  7. "path/filepath"
  8. "github.com/Jguer/yay/v11/pkg/db"
  9. "github.com/Jguer/yay/v11/pkg/dep"
  10. "github.com/Jguer/yay/v11/pkg/settings"
  11. "github.com/Jguer/yay/v11/pkg/settings/parser"
  12. "github.com/Jguer/yay/v11/pkg/text"
  13. gosrc "github.com/Morganamilo/go-srcinfo"
  14. "github.com/leonelquinteros/gotext"
  15. "github.com/pkg/errors"
  16. )
  17. var ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
  18. func installLocalPKGBUILD(
  19. ctx context.Context,
  20. config *settings.Configuration,
  21. cmdArgs *parser.Arguments,
  22. dbExecutor db.Executor,
  23. ) error {
  24. aurCache := config.Runtime.AURCache
  25. wd, err := os.Getwd()
  26. if err != nil {
  27. return errors.Wrap(err, gotext.Get("failed to retrieve working directory"))
  28. }
  29. if len(cmdArgs.Targets) > 1 {
  30. return errors.New(gotext.Get("only one target is allowed"))
  31. }
  32. if len(cmdArgs.Targets) == 1 {
  33. wd = cmdArgs.Targets[0]
  34. }
  35. pkgbuild, err := gosrc.ParseFile(filepath.Join(wd, ".SRCINFO"))
  36. if err != nil {
  37. return errors.Wrap(err, gotext.Get("failed to parse .SRCINFO"))
  38. }
  39. grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
  40. graph, err := grapher.GraphFromSrcInfo(ctx, nil, wd, pkgbuild)
  41. if err != nil {
  42. return err
  43. }
  44. topoSorted := graph.TopoSortedLayerMap()
  45. preparer := &Preparer{
  46. dbExecutor: dbExecutor,
  47. cmdBuilder: config.Runtime.CmdBuilder,
  48. config: config,
  49. }
  50. installer := &Installer{dbExecutor: dbExecutor}
  51. if errP := preparer.Present(os.Stdout, topoSorted); errP != nil {
  52. return errP
  53. }
  54. if cleanFunc := preparer.ShouldCleanMakeDeps(); cleanFunc != nil {
  55. installer.AddPostInstallHook(cleanFunc)
  56. }
  57. pkgBuildDirs, err := preparer.PrepareWorkspace(ctx, topoSorted)
  58. if err != nil {
  59. return err
  60. }
  61. if cleanAURDirsFunc := preparer.ShouldCleanAURDirs(pkgBuildDirs); cleanAURDirsFunc != nil {
  62. installer.AddPostInstallHook(cleanAURDirsFunc)
  63. }
  64. if err = installer.Install(ctx, cmdArgs, topoSorted, pkgBuildDirs); err != nil {
  65. if errHook := installer.RunPostInstallHooks(ctx); errHook != nil {
  66. text.Errorln(errHook)
  67. }
  68. return err
  69. }
  70. return installer.RunPostInstallHooks(ctx)
  71. }