Skip to content

Commit

Permalink
feat(new_engine): add support for noDeps and noCheckDeps (Jguer#1861)
Browse files Browse the repository at this point in the history
* feat(new engine): add support for noDeps and noCheckDeps

* test(new engine): Add tests for -dd and normal split package resolution
  • Loading branch information
Jguer authored Dec 18, 2022
1 parent 0b1ae93 commit 3eb9eb0
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 36 deletions.
8 changes: 4 additions & 4 deletions aur_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestInstaller_InstallNeeded(t *testing.T) {
return tc.isInstalled
}

mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFunc: isCorrectInstalledOverride}
mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFn: isCorrectInstalledOverride}
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
cmdBuilder := &exe.CmdBuilder{
MakepkgBin: makepkgBin,
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) {
return false
}

mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFunc: isCorrectInstalledOverride}
mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFn: isCorrectInstalledOverride}
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
cmdBuilder := &exe.CmdBuilder{
MakepkgBin: makepkgBin,
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestInstaller_CompileFailed(t *testing.T) {
return false
}

mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFunc: isCorrectInstalledOverride}
mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFn: isCorrectInstalledOverride}
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
cmdBuilder := &exe.CmdBuilder{
MakepkgBin: makepkgBin,
Expand Down Expand Up @@ -706,7 +706,7 @@ func TestInstaller_InstallSplitPackage(t *testing.T) {
return false
}

mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFunc: isCorrectInstalledOverride}
mockDB := &mock.DBExecutor{IsCorrectVersionInstalledFn: isCorrectInstalledOverride}
mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
cmdBuilder := &exe.CmdBuilder{
MakepkgBin: makepkgBin,
Expand Down
4 changes: 3 additions & 1 deletion local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"os"
"path/filepath"
"strings"

"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/dep"
Expand All @@ -27,12 +28,13 @@ func installLocalPKGBUILD(
dbExecutor db.Executor,
) error {
aurCache := config.Runtime.AURCache
noCheck := strings.Contains(config.MFlags, "--nocheck")

if len(cmdArgs.Targets) < 1 {
return errors.New(gotext.Get("no target directories specified"))
}

grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout)
grapher := dep.NewGrapher(dbExecutor, aurCache, false, settings.NoConfirm, os.Stdout, cmdArgs.ExistsDouble("d", "nodeps"), noCheck)
graph := topo.New[string, *dep.InstallInfo]()
for _, target := range cmdArgs.Targets {
var errG error
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/graph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func handleCmd() error {
return errors.Wrap(err, gotext.Get("failed to retrieve aur Cache"))
}

grapher := dep.NewGrapher(dbExecutor, aurCache, true, settings.NoConfirm, os.Stdout)
grapher := dep.NewGrapher(dbExecutor, aurCache, true, settings.NoConfirm, os.Stdout, cmdArgs.ExistsDouble("d", "nodeps"), false)

return graphPackage(context.Background(), grapher, cmdArgs.Targets)
}
Expand Down
51 changes: 34 additions & 17 deletions pkg/db/mock/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,76 @@ type (

type DBExecutor struct {
db.Executor
IsCorrectVersionInstalledFunc func(string, string) bool
IsCorrectVersionInstalledFn func(string, string) bool
SyncPackageFn func(string) IPackage
PackagesFromGroupFn func(string) []IPackage
LocalSatisfierExistsFn func(string) bool
SyncSatisfierFn func(string) IPackage
}

func (t DBExecutor) AlpmArchitectures() ([]string, error) {
func (t *DBExecutor) AlpmArchitectures() ([]string, error) {
panic("implement me")
}

func (t DBExecutor) BiggestPackages() []IPackage {
func (t *DBExecutor) BiggestPackages() []IPackage {
panic("implement me")
}

func (t DBExecutor) Cleanup() {
func (t *DBExecutor) Cleanup() {
panic("implement me")
}

func (t DBExecutor) IsCorrectVersionInstalled(s, s2 string) bool {
if t.IsCorrectVersionInstalledFunc != nil {
return t.IsCorrectVersionInstalledFunc(s, s2)
func (t *DBExecutor) IsCorrectVersionInstalled(s, s2 string) bool {
if t.IsCorrectVersionInstalledFn != nil {
return t.IsCorrectVersionInstalledFn(s, s2)
}
panic("implement me")
}

func (t DBExecutor) LastBuildTime() time.Time {
func (t *DBExecutor) LastBuildTime() time.Time {
panic("implement me")
}

func (t DBExecutor) LocalPackage(s string) IPackage {
func (t *DBExecutor) LocalPackage(s string) IPackage {
return nil
}

func (t DBExecutor) LocalPackages() []IPackage {
func (t *DBExecutor) LocalPackages() []IPackage {
panic("implement me")
}

func (t DBExecutor) LocalSatisfierExists(s string) bool {
func (t *DBExecutor) LocalSatisfierExists(s string) bool {
if t.LocalSatisfierExistsFn != nil {
return t.LocalSatisfierExistsFn(s)
}
panic("implement me")
}

func (t DBExecutor) PackageConflicts(iPackage IPackage) []Depend {
func (t *DBExecutor) PackageConflicts(iPackage IPackage) []Depend {
panic("implement me")
}

func (t DBExecutor) PackageDepends(iPackage IPackage) []Depend {
func (t *DBExecutor) PackageDepends(iPackage IPackage) []Depend {
panic("implement me")
}

func (t DBExecutor) PackageGroups(iPackage IPackage) []string {
func (t *DBExecutor) PackageGroups(iPackage IPackage) []string {
return []string{}
}

func (t DBExecutor) PackageOptionalDepends(iPackage IPackage) []Depend {
func (t *DBExecutor) PackageOptionalDepends(iPackage IPackage) []Depend {
panic("implement me")
}

func (t DBExecutor) PackageProvides(iPackage IPackage) []Depend {
func (t *DBExecutor) PackageProvides(iPackage IPackage) []Depend {
panic("implement me")
}

func (t DBExecutor) PackagesFromGroup(s string) []IPackage {
func (t *DBExecutor) PackagesFromGroup(s string) []IPackage {
if t.PackagesFromGroupFn != nil {
return t.PackagesFromGroupFn(s)
}

panic("implement me")
}

Expand All @@ -95,6 +106,9 @@ func (t DBExecutor) SatisfierFromDB(s, s2 string) IPackage {
}

func (t DBExecutor) SyncPackage(s string) IPackage {
if t.SyncPackageFn != nil {
return t.SyncPackageFn(s)
}
panic("implement me")
}

Expand All @@ -103,6 +117,9 @@ func (t DBExecutor) SyncPackages(s ...string) []IPackage {
}

func (t DBExecutor) SyncSatisfier(s string) IPackage {
if t.SyncSatisfierFn != nil {
return t.SyncSatisfierFn(s)
}
panic("implement me")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/db/mock/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p *Package) Conflicts() alpm.DependList {

// Depends returns the package's dependency list.
func (p *Package) Depends() alpm.DependList {
panic("not implemented") // TODO: Implement
return alpm.DependList{}
}

// Depends returns the package's optional dependency list.
Expand Down
26 changes: 17 additions & 9 deletions pkg/dep/depGraph.go → pkg/dep/dep_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,33 @@ var colorMap = map[Reason]string{
CheckDep: "forestgreen",
}

type AURCache interface {
Get(ctx context.Context, query *metadata.AURQuery) ([]*aurc.Pkg, error)
}

type Grapher struct {
dbExecutor db.Executor
aurCache *metadata.Client
fullGraph bool // If true, the graph will include all dependencies including already installed ones or repo
noConfirm bool
w io.Writer // output writer
dbExecutor db.Executor
aurCache AURCache
fullGraph bool // If true, the graph will include all dependencies including already installed ones or repo
noConfirm bool
noDeps bool // If true, the graph will not include dependencies
noCheckDeps bool // If true, the graph will not include dependencies
w io.Writer // output writer

providerCache map[string]*aur.Pkg
}

func NewGrapher(dbExecutor db.Executor, aurCache *metadata.Client,
fullGraph, noConfirm bool, output io.Writer,
func NewGrapher(dbExecutor db.Executor, aurCache AURCache,
fullGraph, noConfirm bool, output io.Writer, noDeps bool, noCheckDeps bool,
) *Grapher {
return &Grapher{
dbExecutor: dbExecutor,
aurCache: aurCache,
fullGraph: fullGraph,
noConfirm: noConfirm,
w: output,
noDeps: noDeps,
noCheckDeps: noCheckDeps,
providerCache: make(map[string]*aurc.Pkg, 5),
}
}
Expand Down Expand Up @@ -226,11 +234,11 @@ func (g *Grapher) addDepNodes(ctx context.Context, pkg *aur.Pkg, graph *topo.Gra
g.addNodes(ctx, graph, pkg.Name, pkg.MakeDepends, MakeDep)
}

if !false && len(pkg.Depends) > 0 {
if !g.noDeps && len(pkg.Depends) > 0 {
g.addNodes(ctx, graph, pkg.Name, pkg.Depends, Dep)
}

if !false && len(pkg.CheckDepends) > 0 {
if !g.noCheckDeps && !g.noDeps && len(pkg.CheckDepends) > 0 {
g.addNodes(ctx, graph, pkg.Name, pkg.CheckDepends, CheckDep)
}
}
Expand Down
Loading

0 comments on commit 3eb9eb0

Please sign in to comment.