local_install.go 2.3 KB

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