Quellcode durchsuchen

add support for target install

jguer vor 2 Jahren
Ursprung
Commit
ba935ccf95
11 geänderte Dateien mit 144 neuen und 65 gelöschten Zeilen
  1. 25 15
      aur_install.go
  2. 1 1
      cmd.go
  3. 17 8
      install.go
  4. 1 1
      local_install.go
  5. 1 1
      pkg/cmd/graph/main.go
  6. 54 4
      pkg/dep/depGraph.go
  7. 0 31
      pkg/dep/depPool.go
  8. 34 0
      pkg/dep/target_handler.go
  9. 2 2
      pkg/text/print.go
  10. 8 1
      preparer.go
  11. 1 1
      sync.go

+ 25 - 15
aur_install.go

@@ -113,7 +113,8 @@ func (installer *Installer) installAURPackages(ctx context.Context,
 	nameToBase, pkgBuildDirsByBase map[string]string,
 	installIncompatible bool,
 ) error {
-	deps, exp := make([]string, 0, aurDepNames.Cardinality()), make([]string, 0, aurExpNames.Cardinality())
+	deps, exps := make([]string, 0, aurDepNames.Cardinality()), make([]string, 0, aurExpNames.Cardinality())
+	pkgArchives := make([]string, 0, len(exps)+len(deps))
 
 	for _, name := range aurDepNames.Union(aurExpNames).ToSlice() {
 		base := nameToBase[name]
@@ -147,22 +148,30 @@ func (installer *Installer) installAURPackages(ctx context.Context,
 			return fmt.Errorf("%s - %w", gotext.Get("error making: %s", base), errMake)
 		}
 
-		names, err := installer.getNewTargets(pkgdests, name)
+		newPKGArchives, hasDebug, err := installer.getNewTargets(pkgdests, name)
 		if err != nil {
 			return err
 		}
 
-		isDep := installer.isDep(cmdArgs, aurExpNames, name)
+		pkgArchives = append(pkgArchives, newPKGArchives...)
 
-		if isDep {
-			deps = append(deps, names...)
+		if isDep := installer.isDep(cmdArgs, aurExpNames, name); isDep {
+			deps = append(deps, name)
 		} else {
-			exp = append(exp, names...)
+			exps = append(exps, name)
+		}
+
+		if hasDebug {
+			deps = append(deps, name+"-debug")
 		}
 	}
 
-	if err := doInstall(ctx, cmdArgs, deps, exp); err != nil {
-		return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v %v", deps, exp), err)
+	if err := installPkgArchive(ctx, cmdArgs, pkgArchives); err != nil {
+		return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v", pkgArchives), err)
+	}
+
+	if err := setInstallReason(ctx, cmdArgs, deps, exps); err != nil {
+		return fmt.Errorf("%s - %w", fmt.Sprintf(gotext.Get("error installing:")+" %v", pkgArchives), err)
 	}
 
 	return nil
@@ -182,28 +191,29 @@ func (*Installer) isDep(cmdArgs *parser.Arguments, aurExpNames mapset.Set[string
 }
 
 func (installer *Installer) getNewTargets(pkgdests map[string]string, name string,
-) ([]string, error) {
+) ([]string, bool, error) {
 	pkgdest, ok := pkgdests[name]
-	names := make([]string, 0, 2)
 	if !ok {
-		return nil, &PkgDestNotInListError{name: name}
+		return nil, false, &PkgDestNotInListError{name: name}
 	}
 
+	pkgFiles := make([]string, 0, 2)
+
 	if _, errStat := os.Stat(pkgdest); os.IsNotExist(errStat) {
-		return nil, &UnableToFindPkgDestError{name: name, pkgDest: pkgdest}
+		return nil, false, &UnableToFindPkgDestError{name: name, pkgDest: pkgdest}
 	}
 
-	names = append(names, name)
+	pkgFiles = append(pkgFiles, pkgdest)
 
 	debugName := pkgdest + "-debug"
 	pkgdestDebug, ok := pkgdests[debugName]
 	if ok {
 		if _, errStat := os.Stat(pkgdestDebug); errStat == nil {
-			names = append(names, debugName)
+			pkgFiles = append(pkgFiles, debugName)
 		}
 	}
 
-	return names, nil
+	return pkgFiles, ok, nil
 }
 
 func (*Installer) installSyncPackages(ctx context.Context, cmdArgs *parser.Arguments,

+ 1 - 1
cmd.go

@@ -416,7 +416,7 @@ func displayNumberMenu(ctx context.Context, pkgS []string, dbExecutor db.Executo
 	}
 
 	if config.NewInstallEngine {
-		return syncInstall(ctx, config, cmdArgs, dbExecutor)
+		return syncInstall(ctx, config, arguments, dbExecutor)
 	}
 
 	return install(ctx, arguments, dbExecutor, true)

+ 17 - 8
install.go

@@ -629,7 +629,7 @@ func buildInstallPkgbuilds(
 		}
 
 		if !satisfied || !config.BatchInstall {
-			err = doInstall(ctx, cmdArgs, deps, exp)
+			err = installPkgArchive(ctx, cmdArgs, append(deps, exp...))
 
 			deps = make([]string, 0)
 			exp = make([]string, 0)
@@ -768,7 +768,7 @@ func buildInstallPkgbuilds(
 		wg.Wait()
 	}
 
-	err = doInstall(ctx, cmdArgs, deps, exp)
+	err = installPkgArchive(ctx, cmdArgs, append(deps, exp...))
 	if err != nil {
 		go config.Runtime.VCSStore.RemovePackage([]string{do.Aur[len(do.Aur)-1].String()})
 	}
@@ -778,7 +778,7 @@ func buildInstallPkgbuilds(
 	return err
 }
 
-func doInstall(ctx context.Context, cmdArgs *parser.Arguments, pkgDeps, pkgExp []string) error {
+func installPkgArchive(ctx context.Context, cmdArgs *parser.Arguments, pkgArchives []string) error {
 	arguments := cmdArgs.Copy()
 	arguments.ClearTargets()
 	arguments.Op = "U"
@@ -790,13 +790,14 @@ func doInstall(ctx context.Context, cmdArgs *parser.Arguments, pkgDeps, pkgExp [
 	arguments.DelArg("y", "refresh")
 	arguments.DelArg("u", "sysupgrade")
 	arguments.DelArg("w", "downloadonly")
+	arguments.DelArg("asdeps", "asdep")
+	arguments.DelArg("asexplicit", "asexp")
 
-	if len(pkgDeps)+len(pkgExp) == 0 {
+	if len(pkgArchives) == 0 {
 		return nil
 	}
 
-	arguments.AddTarget(pkgDeps...)
-	arguments.AddTarget(pkgExp...)
+	arguments.AddTarget(pkgArchives...)
 
 	if errShow := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
 		arguments, config.Runtime.Mode, settings.NoConfirm)); errShow != nil {
@@ -807,11 +808,19 @@ func doInstall(ctx context.Context, cmdArgs *parser.Arguments, pkgDeps, pkgExp [
 		fmt.Fprintln(os.Stderr, errStore)
 	}
 
-	if errDeps := asdeps(ctx, cmdArgs, pkgDeps); errDeps != nil {
+	return nil
+}
+
+func setInstallReason(ctx context.Context, cmdArgs *parser.Arguments, deps, exps []string) error {
+	if len(deps)+len(exps) == 0 {
+		return nil
+	}
+
+	if errDeps := asdeps(ctx, cmdArgs, deps); errDeps != nil {
 		return errDeps
 	}
 
-	return asexp(ctx, cmdArgs, pkgExp)
+	return asexp(ctx, cmdArgs, exps)
 }
 
 func doAddTarget(dp *dep.Pool, localNamesCache, remoteNamesCache stringset.StringSet,

+ 1 - 1
local_install.go

@@ -51,7 +51,7 @@ func installLocalPKGBUILD(
 
 	grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
 
-	graph, err := grapher.GraphFromSrcInfo(wd, pkgbuild)
+	graph, err := grapher.GraphFromSrcInfo(nil, wd, pkgbuild)
 	if err != nil {
 		return err
 	}

+ 1 - 1
pkg/cmd/graph/main.go

@@ -84,7 +84,7 @@ func graphPackage(
 		return errors.New(gotext.Get("only one target is allowed"))
 	}
 
-	graph, err := grapher.GraphFromAURCache([]string{targets[0]})
+	graph, err := grapher.GraphFromAURCache(nil, []string{targets[0]})
 	if err != nil {
 		return err
 	}

+ 54 - 4
pkg/dep/depGraph.go

@@ -94,7 +94,9 @@ type Grapher struct {
 	w          io.Writer // output writer
 }
 
-func NewGrapher(dbExecutor db.Executor, aurCache *metadata.AURCache, fullGraph, noConfirm bool, output io.Writer) *Grapher {
+func NewGrapher(dbExecutor db.Executor, aurCache *metadata.AURCache,
+	fullGraph, noConfirm bool, output io.Writer,
+) *Grapher {
 	return &Grapher{
 		dbExecutor: dbExecutor,
 		aurCache:   aurCache,
@@ -104,9 +106,48 @@ func NewGrapher(dbExecutor db.Executor, aurCache *metadata.AURCache, fullGraph,
 	}
 }
 
-func (g *Grapher) GraphFromSrcInfo(pkgBuildDir string, pkgbuild *gosrc.Srcinfo) (*topo.Graph[string, *InstallInfo], error) {
+func (g *Grapher) GraphFromTargets(targets []string) (*topo.Graph[string, *InstallInfo], error) {
 	graph := topo.New[string, *InstallInfo]()
 
+	for _, targetString := range targets {
+		var (
+			err    error
+			target = ToTarget(targetString)
+		)
+
+		switch target.DB {
+		case "aur":
+			graph, err = g.GraphFromAURCache(graph, []string{target.Name})
+		default:
+			graph.AddNode(target.Name)
+			g.ValidateAndSetNodeInfo(graph, target.Name, &topo.NodeInfo[*InstallInfo]{
+				Color:      colorMap[Explicit],
+				Background: bgColorMap[AUR],
+				Value: &InstallInfo{
+					Source:     Sync,
+					Reason:     Explicit,
+					Version:    target.Version,
+					SyncDBName: &target.DB,
+				},
+			})
+		}
+
+		if err != nil {
+			return nil, err
+		}
+	}
+
+	fmt.Println(graph)
+	return graph, nil
+}
+
+func (g *Grapher) GraphFromSrcInfo(graph *topo.Graph[string, *InstallInfo], pkgBuildDir string,
+	pkgbuild *gosrc.Srcinfo,
+) (*topo.Graph[string, *InstallInfo], error) {
+	if graph == nil {
+		graph = topo.New[string, *InstallInfo]()
+	}
+
 	aurPkgs, err := makeAURPKGFromSrcinfo(g.dbExecutor, pkgbuild)
 	if err != nil {
 		return nil, err
@@ -147,11 +188,19 @@ func (g *Grapher) addDepNodes(pkg *aur.Pkg, graph *topo.Graph[string, *InstallIn
 	}
 }
 
-func (g *Grapher) GraphFromAURCache(targets []string) (*topo.Graph[string, *InstallInfo], error) {
-	graph := topo.New[string, *InstallInfo]()
+func (g *Grapher) GraphFromAURCache(graph *topo.Graph[string, *InstallInfo], targets []string) (*topo.Graph[string, *InstallInfo], error) {
+	if graph == nil {
+		graph = topo.New[string, *InstallInfo]()
+	}
 
 	for _, target := range targets {
 		aurPkgs, _ := g.aurCache.FindPackage(target)
+		if len(aurPkgs) == 0 {
+			text.Errorln("No AUR package found for", target)
+
+			continue
+		}
+
 		pkg := provideMenu(g.w, target, aurPkgs, g.noConfirm)
 
 		g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
@@ -165,6 +214,7 @@ func (g *Grapher) GraphFromAURCache(targets []string) (*topo.Graph[string, *Inst
 			},
 		})
 
+		graph.AddNode(pkg.Name)
 		g.addDepNodes(pkg, graph)
 	}
 

+ 0 - 31
pkg/dep/depPool.go

@@ -21,37 +21,6 @@ import (
 	"github.com/Jguer/yay/v11/pkg/text"
 )
 
-type Target struct {
-	DB      string
-	Name    string
-	Mod     string
-	Version string
-}
-
-func ToTarget(pkg string) Target {
-	dbName, depString := text.SplitDBFromName(pkg)
-	name, mod, depVersion := splitDep(depString)
-
-	return Target{
-		DB:      dbName,
-		Name:    name,
-		Mod:     mod,
-		Version: depVersion,
-	}
-}
-
-func (t Target) DepString() string {
-	return t.Name + t.Mod + t.Version
-}
-
-func (t Target) String() string {
-	if t.DB != "" {
-		return t.DB + "/" + t.DepString()
-	}
-
-	return t.DepString()
-}
-
 type Pool struct {
 	Targets      []Target
 	Explicit     stringset.StringSet

+ 34 - 0
pkg/dep/target_handler.go

@@ -0,0 +1,34 @@
+package dep
+
+import "github.com/Jguer/yay/v11/pkg/text"
+
+type Target struct {
+	DB      string
+	Name    string
+	Mod     string
+	Version string
+}
+
+func ToTarget(pkg string) Target {
+	dbName, depString := text.SplitDBFromName(pkg)
+	name, mod, depVersion := splitDep(depString)
+
+	return Target{
+		DB:      dbName,
+		Name:    name,
+		Mod:     mod,
+		Version: depVersion,
+	}
+}
+
+func (t Target) DepString() string {
+	return t.Name + t.Mod + t.Version
+}
+
+func (t Target) String() string {
+	if t.DB != "" {
+		return t.DB + "/" + t.DepString()
+	}
+
+	return t.DepString()
+}

+ 2 - 2
pkg/text/print.go

@@ -28,8 +28,8 @@ func Debugln(a ...interface{}) {
 		return
 	}
 
-	fmt.Fprint(os.Stdout, append([]interface{}{Bold(yellow("[DEBUG] "))}, a...)...)
-	fmt.Fprintln(os.Stdout, ResetCode)
+	fmt.Fprintln(os.Stdout, append([]interface{}{Bold(yellow("[DEBUG] "))}, a...)...)
+	fmt.Fprint(os.Stdout, ResetCode)
 }
 
 func OperationInfoln(a ...interface{}) {

+ 8 - 1
preparer.go

@@ -55,7 +55,14 @@ func (preper *Preparer) Present(w io.Writer, targets []map[string]*dep.InstallIn
 		for pkgName, info := range layer {
 			source := dep.SourceNames[info.Source]
 			reason := dep.ReasonNames[info.Reason]
-			pkgStr := text.Cyan(fmt.Sprintf("%s-%s", pkgName, info.Version))
+
+			var pkgStr string
+			if info.Version != "" {
+				pkgStr = text.Cyan(fmt.Sprintf("%s-%s", pkgName, info.Version))
+			} else {
+				pkgStr = text.Cyan(pkgName)
+			}
+
 			if _, ok := pkgsBySourceAndReason[source]; !ok {
 				pkgsBySourceAndReason[source] = map[string][]string{}
 			}

+ 1 - 1
sync.go

@@ -26,7 +26,7 @@ func syncInstall(ctx context.Context,
 
 	grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
 
-	graph, err := grapher.GraphFromAURCache(cmdArgs.Targets)
+	graph, err := grapher.GraphFromTargets(cmdArgs.Targets)
 	if err != nil {
 		return err
 	}