diff --git a/aur_install.go b/aur_install.go index fd7d7566..d6fd7c5d 100644 --- a/aur_install.go +++ b/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, diff --git a/cmd.go b/cmd.go index 43a26838..3dbe31c4 100644 --- a/cmd.go +++ b/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) diff --git a/install.go b/install.go index 718540f8..b6f995b1 100644 --- a/install.go +++ b/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, diff --git a/local_install.go b/local_install.go index b61ff62a..e7a51012 100644 --- a/local_install.go +++ b/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 } diff --git a/pkg/cmd/graph/main.go b/pkg/cmd/graph/main.go index c6fe5acc..19ed8df5 100644 --- a/pkg/cmd/graph/main.go +++ b/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 } diff --git a/pkg/dep/depGraph.go b/pkg/dep/depGraph.go index b7f95620..d3f7d1b0 100644 --- a/pkg/dep/depGraph.go +++ b/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) } diff --git a/pkg/dep/depPool.go b/pkg/dep/depPool.go index 845d4a97..748a752b 100644 --- a/pkg/dep/depPool.go +++ b/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 diff --git a/pkg/dep/target_handler.go b/pkg/dep/target_handler.go new file mode 100644 index 00000000..5b90320a --- /dev/null +++ b/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() +} diff --git a/pkg/text/print.go b/pkg/text/print.go index c6893c01..c87067c7 100644 --- a/pkg/text/print.go +++ b/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{}) { diff --git a/preparer.go b/preparer.go index 64fd31ec..11a6db48 100644 --- a/preparer.go +++ b/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{} } diff --git a/sync.go b/sync.go index fec69c64..05d8a2d2 100644 --- a/sync.go +++ b/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 }