Skip to content

Commit

Permalink
feat(new_engine): add support for --nocombinedupgrade (#2083)
Browse files Browse the repository at this point in the history
* feat(new_engine): add support for --nocombinedupgrade

* update en.po
  • Loading branch information
Jguer authored Apr 6, 2023
1 parent d9b5779 commit ce0cb35
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 27 deletions.
4 changes: 3 additions & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ func earlyPacmanCall(ctx context.Context, cfg *settings.Configuration,

func earlyRefresh(ctx context.Context, cfg *settings.Configuration, cmdBuilder exe.ICmdBuilder, cmdArgs *parser.Arguments) error {
arguments := cmdArgs.Copy()
arguments.DelArg("u", "sysupgrade")
if cfg.CombinedUpgrade {
arguments.DelArg("u", "sysupgrade")
}
arguments.DelArg("s", "search")
arguments.DelArg("i", "info")
arguments.DelArg("l", "list")
Expand Down
2 changes: 1 addition & 1 deletion pkg/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func DefaultConfig(version string) *Configuration {
DiffMenu: true,
EditMenu: false,
UseAsk: false,
CombinedUpgrade: false,
CombinedUpgrade: true,
SeparateSources: true,
NewInstallEngine: true,
Version: version,
Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (u *UpgradeService) UserExcludeUpgrades(graph *topo.Graph[string, *dep.Inst

allUp := UpSlice{Up: append(repoUp.Up, aurUp.Up...), Repos: append(repoUp.Repos, aurUp.Repos...)}

u.log.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade.")))
u.log.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade/install.")))
allUp.Print(u.log)

u.log.Infoln(gotext.Get("Packages to exclude: (eg: \"1 2 3\", \"1-3\", \"^4\" or repo name)"))
Expand Down
51 changes: 27 additions & 24 deletions po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ msgid "%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"
msgstr ""

#: aur_install.go:274
#: install.go:739
#: install.go:741
msgid "%s already made -- skipping build"
msgstr ""

Expand All @@ -51,13 +51,13 @@ msgstr ""
msgid "%s is present."
msgstr ""

#: aur_install.go:271
#: install.go:725
#: pkg/dep/dep_graph.go:385
#: aur_install.go:271
#: install.go:727
msgid "%s is up to date -- skipping"
msgstr ""

#: install.go:640
#: install.go:642
msgid "%s not satisfied, flushing install queue"
msgstr ""

Expand Down Expand Up @@ -144,8 +144,8 @@ msgstr ""
msgid "Check Deps"
msgstr ""

#: upgrade.go:95
#: pkg/upgrade/service.go:78
#: upgrade.go:95
msgid "Checking development packages..."
msgstr ""

Expand Down Expand Up @@ -381,8 +381,8 @@ msgstr ""
msgid "Packages to cleanBuild?"
msgstr ""

#: upgrade.go:213
#: pkg/dep/dep_graph.go:215
#: upgrade.go:213
msgid "Packages to exclude"
msgstr ""

Expand All @@ -395,10 +395,13 @@ msgid "Packages to install (eg: 1 2 3, 1-3 or ^4)"
msgstr ""

#: upgrade.go:210
#: pkg/upgrade/service.go:252
msgid "Packages to upgrade."
msgstr ""

#: pkg/upgrade/service.go:252
msgid "Packages to upgrade/install."
msgstr ""

#: print.go:42
msgid "Popularity"
msgstr ""
Expand Down Expand Up @@ -428,22 +431,22 @@ msgstr ""
msgid "Repository AUR"
msgstr ""

#: print.go:25
#: pkg/db/ialpm/alpm.go:191
#: print.go:25
msgid "Repository"
msgstr ""

#: pkg/dep/dep_graph.go:77
msgid "SRCINFO"
msgstr ""

#: upgrade.go:73
#: pkg/upgrade/service.go:63
#: upgrade.go:73
msgid "Searching AUR for updates..."
msgstr ""

#: upgrade.go:62
#: pkg/upgrade/service.go:142
#: upgrade.go:62
msgid "Searching databases for updates..."
msgstr ""

Expand Down Expand Up @@ -471,14 +474,14 @@ msgstr ""
msgid "Ten biggest packages:"
msgstr ""

#: install.go:493
#: install.go:495
#: sync.go:183
msgid "The following packages are not compatible with your architecture:"
msgstr ""

#: pkg/db/ialpm/alpm.go:179
#: pkg/dep/depPool.go:499
#: pkg/dep/dep_graph.go:627
#: pkg/db/ialpm/alpm.go:179
msgid "There are %d providers available for %s:"
msgstr ""

Expand All @@ -494,7 +497,7 @@ msgstr ""
msgid "Total installed packages: %s"
msgstr ""

#: install.go:501
#: install.go:503
#: sync.go:191
msgid "Try to build them anyway?"
msgstr ""
Expand Down Expand Up @@ -542,9 +545,9 @@ msgstr ""
msgid "\nBuild directory:"
msgstr ""

#: pkg/db/ialpm/alpm.go:201
#: pkg/dep/depPool.go:513
#: pkg/dep/dep_graph.go:641
#: pkg/db/ialpm/alpm.go:201
msgid "\nEnter a number (default=1): "
msgstr ""

Expand All @@ -560,7 +563,7 @@ msgstr ""
msgid "cannot find PKGBUILD and .SRCINFO in directory"
msgstr ""

#: install.go:530
#: install.go:532
msgid "cannot find package name: %v"
msgstr ""

Expand All @@ -580,7 +583,7 @@ msgstr ""
msgid "could not find any package archives listed in %s"
msgstr ""

#: install.go:786
#: install.go:788
msgid "could not find srcinfo for: %s"
msgstr ""

Expand Down Expand Up @@ -618,14 +621,14 @@ msgstr ""

#: aur_install.go:204
#: aur_install.go:208
#: install.go:681
#: install.go:722
#: install.go:736
#: install.go:750
#: install.go:683
#: install.go:724
#: install.go:738
#: install.go:752
msgid "error making: %s"
msgstr ""

#: install.go:586
#: install.go:588
msgid "error merging %s: %s"
msgstr ""

Expand All @@ -639,7 +642,7 @@ msgid "error refreshing databases"
msgstr ""

#: clean.go:220
#: install.go:579
#: install.go:581
msgid "error resetting %s: %s"
msgstr ""

Expand Down Expand Up @@ -687,9 +690,9 @@ msgstr ""
msgid "input too long"
msgstr ""

#: pkg/db/ialpm/alpm.go:222
#: pkg/dep/depPool.go:533
#: pkg/dep/dep_graph.go:662
#: pkg/db/ialpm/alpm.go:222
msgid "invalid number: %s"
msgstr ""

Expand All @@ -705,9 +708,9 @@ msgstr ""
msgid "invalid repository"
msgstr ""

#: pkg/db/ialpm/alpm.go:227
#: pkg/dep/depPool.go:538
#: pkg/dep/dep_graph.go:668
#: pkg/db/ialpm/alpm.go:227
msgid "invalid value: %d is not between %d and %d"
msgstr ""

Expand Down
118 changes: 118 additions & 0 deletions sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,121 @@ func sanitizeCall(s, tmpDir, makepkg, pacman, git string) string {

return s
}

func TestSyncUpgrade_NoCombinedUpgrade(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
combinedUpgrade bool
want []string
}{
{
name: "combined upgrade",
combinedUpgrade: true,
want: []string{"pacman -S -y -u --config /etc/pacman.conf --"},
},
{
name: "no combined upgrade",
combinedUpgrade: false,
want: []string{"pacman -S -y --config /etc/pacman.conf --"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
makepkgBin := t.TempDir() + "/makepkg"
pacmanBin := t.TempDir() + "/pacman"
gitBin := t.TempDir() + "/git"
f, err := os.OpenFile(makepkgBin, os.O_RDONLY|os.O_CREATE, 0o755)
require.NoError(t, err)
require.NoError(t, f.Close())

f, err = os.OpenFile(pacmanBin, os.O_RDONLY|os.O_CREATE, 0o755)
require.NoError(t, err)
require.NoError(t, f.Close())

f, err = os.OpenFile(gitBin, os.O_RDONLY|os.O_CREATE, 0o755)
require.NoError(t, err)
require.NoError(t, f.Close())

captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) {
return "", "", nil
}

showOverride := func(cmd *exec.Cmd) error {
return nil
}

mockRunner := &exe.MockRunner{CaptureFn: captureOverride, ShowFn: showOverride}
cmdBuilder := &exe.CmdBuilder{
MakepkgBin: makepkgBin,
SudoBin: "su",
PacmanBin: pacmanBin,
PacmanConfigPath: "/etc/pacman.conf",
GitBin: "git",
Runner: mockRunner,
SudoLoopEnabled: false,
}

cmdArgs := parser.MakeArguments()
cmdArgs.AddArg("S")
cmdArgs.AddArg("y")
cmdArgs.AddArg("u")

db := &mock.DBExecutor{
AlpmArchitecturesFn: func() ([]string, error) {
return []string{"x86_64"}, nil
},
RefreshHandleFn: func() error {
return nil
},
ReposFn: func() []string {
return []string{"core"}
},
InstalledRemotePackagesFn: func() map[string]alpm.IPackage {
return map[string]alpm.IPackage{}
},
InstalledRemotePackageNamesFn: func() []string {
return []string{}
},
SyncUpgradesFn: func(
bool,
) (map[string]db.SyncUpgrade, error) {
return map[string]db.SyncUpgrade{}, nil
},
}

cfg := &settings.Configuration{
NewInstallEngine: true,
RemoveMake: "no",
CombinedUpgrade: false,
Runtime: &settings.Runtime{
Logger: text.NewLogger(io.Discard, strings.NewReader("1\n"), true, "test"),
CmdBuilder: cmdBuilder,
VCSStore: &vcs.Mock{},
AURCache: &mockaur.MockAUR{
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
return []aur.Pkg{}, nil
},
},
},
}

err = handleCmd(context.Background(), cfg, cmdArgs, db)
require.NoError(t, err)

require.Len(t, mockRunner.ShowCalls, len(tc.want))
require.Len(t, mockRunner.CaptureCalls, 0)

for i, call := range mockRunner.ShowCalls {
show := call.Args[0].(*exec.Cmd).String()
show = strings.ReplaceAll(show, pacmanBin, "pacman")

// options are in a different order on different systems and on CI root user is used
assert.Subset(t, strings.Split(show, " "), strings.Split(tc.want[i], " "), fmt.Sprintf("%d - %s", i, show))
}
})
}
}

0 comments on commit ce0cb35

Please sign in to comment.