From b0aa5bf05bbfcee665276fa78f1a8d0c8769dcb8 Mon Sep 17 00:00:00 2001 From: jdholtz Date: Thu, 7 Sep 2023 11:28:06 -0500 Subject: [PATCH 1/3] feat(install): add --nocleanbuild to keep pkg/ and src/ directories for AUR packages Providing this flag during installation of AUR packages allows for keeping the src/ and pkg/ directories produced my makepkg. If the user wants to delete the directories, they can either select to cleanBuild in the cleanmenu or run the installation without the --nocleanbuild flag (yay will only remove the directories if the package is rebuilt) --- cmd.go | 1 + completions/bash | 2 +- completions/fish | 1 + completions/zsh | 1 + doc/yay.8 | 4 + local_install_test.go | 45 ++++--- pkg/settings/args.go | 2 + pkg/settings/config.go | 2 + pkg/settings/exe/cmd_builder.go | 7 ++ pkg/settings/exe/mock.go | 5 + pkg/settings/parser/parser.go | 1 + pkg/sync/build/installer.go | 16 ++- pkg/sync/build/installer_test.go | 179 +++++++++++++++++++++++----- pkg/sync/workdir/aur_source.go | 6 +- pkg/sync/workdir/aur_source_test.go | 61 ++++++++-- sync_test.go | 11 +- 16 files changed, 273 insertions(+), 71 deletions(-) diff --git a/cmd.go b/cmd.go index 304bb69da..32bb4504b 100644 --- a/cmd.go +++ b/cmd.go @@ -102,6 +102,7 @@ Permanent configuration options: --cleanafter Remove package sources after successful install --nocleanafter Do not remove package sources after successful build + --nocleanbuild Do not remove pkg/ and src/ after building packages --bottomup Shows AUR's packages first and then repository's --topdown Shows repository's packages first and then AUR's --singlelineresults List each search result on its own line diff --git a/completions/bash b/completions/bash index f29c68b59..6a1ba7f55 100644 --- a/completions/bash +++ b/completions/bash @@ -72,7 +72,7 @@ _yay() { makepkg pacman git gpg gpgflags config requestsplitn sudoloop nosudoloop redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild sortby singlelineresults doublelineresults answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff - noansweredit noanswerupgrade cleanmenu diffmenu editmenu cleanafter nocleanafter + noansweredit noanswerupgrade cleanmenu diffmenu editmenu cleanafter nocleanafter nocleanbuild nocleanmenu nodiffmenu provides noprovides pgpfetch nopgpfetch useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf nomakepkgconf askremovemake askyesremovemake removemake noremovemake completioninterval aururl aurrpcurl diff --git a/completions/fish b/completions/fish index 58f5d55f2..2eaa843c4 100644 --- a/completions/fish +++ b/completions/fish @@ -231,6 +231,7 @@ complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg developme complete -c $progname -n "not $noopt" -l nodevel -d 'Disable development version checking' -f complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f complete -c $progname -n "not $noopt" -l nocleanafter -d 'Disable package sources cleaning' -f +complete -c $progname -n "not $noopt" -l nocleanbuild -d 'Do not remove pkg/ and src/ directories after building packages' -f complete -c $progname -n "not $noopt" -l timeupdate -d 'Check package modification date and version' -f complete -c $progname -n "not $noopt" -l notimeupdate -d 'Check only package version change' -f complete -c $progname -n "not $noopt" -l redownload -d 'Redownload PKGBUILD of package even if up-to-date' -f diff --git a/completions/zsh b/completions/zsh index 77621a5a1..f0d6c9524 100644 --- a/completions/zsh +++ b/completions/zsh @@ -86,6 +86,7 @@ _pacman_opts_common=( '--nodevel[Disable development version checking]' '--cleanafter[Clean package sources after successful build]' '--nocleanafter[Disable package sources cleaning after successful build]' + '--nocleanbuild[Do not remove pkg/ and src/ after building packages]' '--timeupdate[Check packages modification date and version]' '--notimeupdate[Check only package version change]' '--redownload[Always download pkgbuilds of targets]' diff --git a/doc/yay.8 b/doc/yay.8 index b368f2dbe..ba5c2254e 100644 --- a/doc/yay.8 +++ b/doc/yay.8 @@ -384,6 +384,10 @@ instead of having to reclone the entire repo. .B \-\-nocleanafter Do not remove package sources after successful Install. +.TP +.B \-\-nocleanbuild +Do not remove pkg/ and src/ after building packages + .TP .B \-\-timeupdate During sysupgrade also compare the build time of installed packages against diff --git a/local_install_test.go b/local_install_test.go index 9cf70549d..685c0f8c9 100644 --- a/local_install_test.go +++ b/local_install_test.go @@ -56,16 +56,16 @@ func TestIntegrationLocalInstall(t *testing.T) { } wantShow := []string{ - "makepkg --verifysource --skippgpcheck -Ccf", + "makepkg --verifysource --skippgpcheck -f -Cc", "pacman -S --config /etc/pacman.conf -- community/dotnet-sdk-6.0 community/dotnet-runtime-6.0", "pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 dotnet-sdk-6.0", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin-server jellyfin-web", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin", @@ -104,6 +104,7 @@ func TestIntegrationLocalInstall(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -233,6 +234,7 @@ func TestIntegrationLocalInstallMissingDep(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -324,14 +326,14 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) { } wantShow := []string{ - "makepkg --verifysource --skippgpcheck -Ccf", + "makepkg --verifysource --skippgpcheck -f -Cc", "pacman -S --config /etc/pacman.conf -- community/dotnet-sdk-6.0 community/dotnet-runtime-6.0", "pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 dotnet-sdk-6.0", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", } @@ -368,6 +370,7 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -492,16 +495,16 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) { } wantShow := []string{ - "makepkg --verifysource --skippgpcheck -Ccf", + "makepkg --verifysource --skippgpcheck -f -Cc", "pacman -S --config /etc/pacman.conf -- community/dotnet-sdk-6.0 community/dotnet-runtime-6.0", "pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 dotnet-sdk-6.0", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin-server jellyfin-web", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin", @@ -546,6 +549,7 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -684,6 +688,7 @@ func TestIntegrationLocalInstallMissingFiles(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -783,12 +788,12 @@ func TestIntegrationLocalInstallWithDepsProvides(t *testing.T) { } wantShow := []string{ - "makepkg --verifysource --skippgpcheck -Ccf", - "makepkg --nobuild -fC --ignorearch", + "makepkg --verifysource --skippgpcheck -f -Cc", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/ceph-libs-bin-17.2.6-2-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- ceph-libs-bin", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/ceph-bin-17.2.6-2-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- ceph-bin", @@ -826,6 +831,7 @@ func TestIntegrationLocalInstallWithDepsProvides(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -910,13 +916,13 @@ func TestIntegrationLocalInstallTwoSrcInfosWithDeps(t *testing.T) { } wantShow := []string{ - "makepkg --verifysource --skippgpcheck -Ccf", - "makepkg --verifysource --skippgpcheck -Ccf", - "makepkg --nobuild -fC --ignorearch", + "makepkg --verifysource --skippgpcheck -f -Cc", + "makepkg --verifysource --skippgpcheck -f -Cc", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir1/libzip-git-1.9.2.r166.gd2c47d0f-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- libzip-git", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir2/gourou-0.8.1-4-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- gourou", @@ -965,6 +971,7 @@ func TestIntegrationLocalInstallTwoSrcInfosWithDeps(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } diff --git a/pkg/settings/args.go b/pkg/settings/args.go index 92fcac56e..4470b0c8c 100644 --- a/pkg/settings/args.go +++ b/pkg/settings/args.go @@ -53,6 +53,8 @@ func (c *Configuration) handleOption(option, value string) bool { c.CleanAfter = true case "noafterclean", "nocleanafter": c.CleanAfter = false + case "nocleanbuild": + c.CleanBuild = false case "debug": c.Debug = true return false diff --git a/pkg/settings/config.go b/pkg/settings/config.go index 23a1e7e08..21384b176 100644 --- a/pkg/settings/config.go +++ b/pkg/settings/config.go @@ -56,6 +56,7 @@ type Configuration struct { TimeUpdate bool `json:"timeupdate"` Devel bool `json:"devel"` CleanAfter bool `json:"cleanAfter"` + CleanBuild bool `json:"cleanBuild"` Provides bool `json:"provides"` PGPFetch bool `json:"pgpfetch"` CleanMenu bool `json:"cleanmenu"` @@ -193,6 +194,7 @@ func DefaultConfig(version string) *Configuration { AURURL: "https://aur.archlinux.org", BuildDir: os.ExpandEnv("$HOME/.cache/yay"), CleanAfter: false, + CleanBuild: true, Editor: "", EditorFlags: "", Devel: false, diff --git a/pkg/settings/exe/cmd_builder.go b/pkg/settings/exe/cmd_builder.go index 624b7b037..541866c5d 100644 --- a/pkg/settings/exe/cmd_builder.go +++ b/pkg/settings/exe/cmd_builder.go @@ -39,10 +39,12 @@ type ICmdBuilder interface { BuildMakepkgCmd(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd BuildPacmanCmd(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd AddMakepkgFlag(string) + GetCleanBuild() bool SudoLoop() } type CmdBuilder struct { + CleanBuild bool GitBin string GitFlags []string GPGBin string @@ -62,6 +64,7 @@ type CmdBuilder struct { func NewCmdBuilder(cfg *settings.Configuration, runner Runner, logger *text.Logger, dbPath string) *CmdBuilder { return &CmdBuilder{ + CleanBuild: cfg.CleanBuild, GitBin: cfg.GitBin, GitFlags: strings.Fields(cfg.GitFlags), GPGBin: cfg.GpgBin, @@ -296,3 +299,7 @@ func (c *CmdBuilder) Show(cmd *exec.Cmd) error { func (c *CmdBuilder) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) { return c.Runner.Capture(cmd) } + +func (c *CmdBuilder) GetCleanBuild() bool { + return c.CleanBuild +} diff --git a/pkg/settings/exe/mock.go b/pkg/settings/exe/mock.go index cbf323821..95c7b8371 100644 --- a/pkg/settings/exe/mock.go +++ b/pkg/settings/exe/mock.go @@ -25,6 +25,7 @@ type MockBuilder struct { BuildMakepkgCmdCalls []Call BuildMakepkgCmdFn func(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd BuildPacmanCmdFn func(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd + GetCleanBuildFn func() bool } type MockRunner struct { @@ -95,6 +96,10 @@ func (m *MockBuilder) Show(cmd *exec.Cmd) error { return m.Runner.Show(cmd) } +func (m *MockBuilder) GetCleanBuild() bool { + return true +} + func (m *MockRunner) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) { m.CaptureCallsMu.Lock() m.CaptureCalls = append(m.CaptureCalls, Call{ diff --git a/pkg/settings/parser/parser.go b/pkg/settings/parser/parser.go index 6e7166b17..cb96a7c7c 100644 --- a/pkg/settings/parser/parser.go +++ b/pkg/settings/parser/parser.go @@ -378,6 +378,7 @@ func isArg(arg string) bool { case "save": case "afterclean", "cleanafter": case "noafterclean", "nocleanafter": + case "nocleanbuild": case "devel": case "nodevel": case "timeupdate": diff --git a/pkg/sync/build/installer.go b/pkg/sync/build/installer.go index 66988cd30..4169abee9 100644 --- a/pkg/sync/build/installer.go +++ b/pkg/sync/build/installer.go @@ -277,7 +277,11 @@ func (installer *Installer) buildPkg(ctx context.Context, dir, base string, installIncompatible, needed, isTarget bool, ) (map[string]string, error) { - args := []string{"--nobuild", "-fC"} + args := []string{"--nobuild", "-f"} + + if installer.exeCmd.GetCleanBuild() { + args = append(args, "-C") + } if installIncompatible { args = append(args, "--ignorearch") @@ -296,19 +300,23 @@ func (installer *Installer) buildPkg(ctx context.Context, switch { case needed && installer.pkgsAreAlreadyInstalled(pkgdests, pkgVersion) || installer.downloadOnly: - args = []string{"-c", "--nobuild", "--noextract", "--ignorearch"} + args = []string{"--nobuild", "--noextract", "--ignorearch"} pkgdests = map[string]string{} installer.log.Warnln(gotext.Get("%s is up to date -- skipping", text.Cyan(base+"-"+pkgVersion))) case installer.skipAlreadyBuiltPkg(isTarget, pkgdests): - args = []string{"-c", "--nobuild", "--noextract", "--ignorearch"} + args = []string{"--nobuild", "--noextract", "--ignorearch"} installer.log.Warnln(gotext.Get("%s already made -- skipping build", text.Cyan(base+"-"+pkgVersion))) default: - args = []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"} + args = []string{"-f", "--noconfirm", "--noextract", "--noprepare", "--holdver"} if installIncompatible { args = append(args, "--ignorearch") } } + if installer.exeCmd.GetCleanBuild() { + args = append(args, "-c") + } + errMake := installer.exeCmd.Show( installer.exeCmd.BuildMakepkgCmd(ctx, dir, args...)) diff --git a/pkg/sync/build/installer_test.go b/pkg/sync/build/installer_test.go index a16d433dc..33b819d09 100644 --- a/pkg/sync/build/installer_test.go +++ b/pkg/sync/build/installer_test.go @@ -56,8 +56,8 @@ func TestInstaller_InstallNeeded(t *testing.T) { isInstalled: false, isBuilt: false, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --needed --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config -- yay", }, @@ -68,7 +68,7 @@ func TestInstaller_InstallNeeded(t *testing.T) { isInstalled: false, isBuilt: true, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --needed --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config -- yay", @@ -80,7 +80,7 @@ func TestInstaller_InstallNeeded(t *testing.T) { isInstalled: true, isBuilt: false, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", }, wantCapture: []string{"makepkg --packagelist"}, @@ -128,6 +128,7 @@ func TestInstaller_InstallNeeded(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -212,8 +213,8 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { wantShow: []string{ "pacman -S --config /etc/pacman.conf -- core/linux", "pacman -D -q --asdeps --config /etc/pacman.conf -- linux", - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- yay", }, @@ -241,8 +242,8 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { wantShow: []string{ "pacman -S --config /etc/pacman.conf -- core/linux", "pacman -D -q --asdeps --config /etc/pacman.conf -- linux", - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- yay", }, @@ -293,10 +294,10 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { { desc: "same layer -- aur", wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config /etc/pacman.conf -- pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- yay", }, @@ -323,12 +324,12 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { { desc: "different layer -- aur", wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config /etc/pacman.conf -- pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-server-10.8.8-1-x86_64.pkg.tar.zst", "pacman -D -q --asdeps --config /etc/pacman.conf -- jellyfin-server", - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config /etc/pacman.conf -- pacman -U --config /etc/pacman.conf -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- yay", }, @@ -374,13 +375,13 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { } showOverride := func(cmd *exec.Cmd) error { - if strings.Contains(cmd.String(), "makepkg -cf --noconfirm") && cmd.Dir == tmpDir { + if strings.Contains(cmd.String(), "makepkg -f --noconfirm") && cmd.Dir == tmpDir { f, err := os.OpenFile(pkgTar, os.O_RDONLY|os.O_CREATE, 0o666) require.NoError(td, err) require.NoError(td, f.Close()) } - if strings.Contains(cmd.String(), "makepkg -cf --noconfirm") && cmd.Dir == tmpDirJfin { + if strings.Contains(cmd.String(), "makepkg -f --noconfirm") && cmd.Dir == tmpDirJfin { f, err := os.OpenFile(jfinPkgTar, os.O_RDONLY|os.O_CREATE, 0o666) require.NoError(td, err) require.NoError(td, f.Close()) @@ -403,6 +404,7 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { PacmanBin: pacmanBin, PacmanConfigPath: "/etc/pacman.conf", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -456,6 +458,7 @@ func TestInstaller_RunPostHooks(t *testing.T) { PacmanBin: "pacman", PacmanConfigPath: "/etc/pacman.conf", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -570,7 +573,7 @@ func TestInstaller_CompileFailed(t *testing.T) { } showOverride := func(cmd *exec.Cmd) error { - if tc.failBuild && strings.Contains(cmd.String(), "makepkg -cf --noconfirm") && cmd.Dir == tmpDir { + if tc.failBuild && strings.Contains(cmd.String(), "makepkg -f --noconfirm") && cmd.Dir == tmpDir { return errors.New("makepkg failed") } return nil @@ -587,6 +590,7 @@ func TestInstaller_CompileFailed(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -694,13 +698,13 @@ func TestInstaller_InstallSplitPackage(t *testing.T) { wantShow: []string{ "pacman -S --config /etc/pacman.conf -- community/dotnet-runtime-6.0 community/aspnet-runtime community/dotnet-sdk-6.0", "pacman -D -q --asdeps --config /etc/pacman.conf -- dotnet-runtime-6.0 aspnet-runtime dotnet-sdk-6.0", - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-web-10.8.4-1-x86_64.pkg.tar.zst /testdir/jellyfin-server-10.8.4-1-x86_64.pkg.tar.zst", "pacman -D -q --asdeps --config /etc/pacman.conf -- jellyfin-server jellyfin-web", - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/jellyfin-10.8.4-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config /etc/pacman.conf -- jellyfin", @@ -747,6 +751,7 @@ func TestInstaller_InstallSplitPackage(t *testing.T) { PacmanBin: pacmanBin, PacmanConfigPath: "/etc/pacman.conf", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -818,7 +823,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) { isInstalled: false, isBuilt: false, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", }, wantCapture: []string{"makepkg --packagelist"}, @@ -828,7 +833,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) { isInstalled: false, isBuilt: true, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", }, wantCapture: []string{"makepkg --packagelist"}, @@ -838,7 +843,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) { isInstalled: true, isBuilt: false, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", }, wantCapture: []string{"makepkg --packagelist"}, @@ -886,6 +891,7 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -990,6 +996,7 @@ func TestInstaller_InstallGroup(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -1075,7 +1082,7 @@ func TestInstaller_InstallRebuild(t *testing.T) { isBuilt: true, isInstalled: false, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config -- yay", @@ -1099,8 +1106,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { isBuilt: true, isInstalled: false, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config -- yay", }, @@ -1123,8 +1130,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { isInstalled: true, isBuilt: true, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asexplicit --config -- yay", }, @@ -1147,8 +1154,8 @@ func TestInstaller_InstallRebuild(t *testing.T) { isInstalled: true, isBuilt: true, wantShow: []string{ - "makepkg --nobuild -fC --ignorearch", - "makepkg -cf --noconfirm --noextract --noprepare --holdver --ignorearch", + "makepkg --nobuild -f -C --ignorearch", + "makepkg -f -c --noconfirm --noextract --noprepare --holdver --ignorearch", "pacman -U --config -- /testdir/yay-91.0.0-1-x86_64.pkg.tar.zst", "pacman -D -q --asdeps --config -- yay", }, @@ -1208,6 +1215,7 @@ func TestInstaller_InstallRebuild(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -1295,6 +1303,7 @@ func TestInstaller_InstallUpgrade(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -1337,3 +1346,107 @@ func TestInstaller_InstallUpgrade(t *testing.T) { }) } } + +func TestInstaller_NoCleanBuild(t *testing.T) { + t.Parallel() + + makepkgBin := t.TempDir() + "/makepkg" + pacmanBin := t.TempDir() + "/pacman" + 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()) + + type testCase struct { + desc string + wantShow []string + targets []map[string]*dep.InstallInfo + } + + tmpDir := t.TempDir() + + testCases := []testCase{ + { + desc: "--nocleanbuild", + wantShow: []string{ + "makepkg --nobuild -f --ignorearch", + "makepkg --nobuild --noextract --ignorearch", + "pacman -U --config -- /testdir/yay-92.0.0-1-x86_64.pkg.tar.zst", + "pacman -D -q --asexplicit --config -- yay", + }, + targets: []map[string]*dep.InstallInfo{ + { + "yay": { + Source: dep.AUR, + Reason: dep.Explicit, + Version: "92.0.0-1", + SrcinfoPath: ptrString(tmpDir + "/.SRCINFO"), + AURBase: ptrString("yay"), + }, + }, + }, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.desc, func(td *testing.T) { + tmpDir := td.TempDir() + pkgTar := tmpDir + "/yay-92.0.0-1-x86_64.pkg.tar.zst" + + captureOverride := func(cmd *exec.Cmd) (stdout string, stderr string, err error) { + return pkgTar, "", nil + } + + // create a mock file + f, err := os.OpenFile(pkgTar, os.O_RDONLY|os.O_CREATE, 0o666) + require.NoError(td, err) + require.NoError(td, f.Close()) + + mockDB := &mock.DBExecutor{} + mockRunner := &exe.MockRunner{CaptureFn: captureOverride} + cmdBuilder := &exe.CmdBuilder{ + MakepkgBin: makepkgBin, + SudoBin: "su", + PacmanBin: pacmanBin, + Runner: mockRunner, + CleanBuild: false, + SudoLoopEnabled: false, + } + + installer := NewInstaller(mockDB, cmdBuilder, &vcs.Mock{}, parser.ModeAny, + parser.RebuildModeNo, false, newTestLogger()) + + cmdArgs := parser.MakeArguments() + cmdArgs.AddTarget("yay") + + pkgBuildDirs := map[string]string{ + "yay": tmpDir, + } + + errI := installer.Install(context.Background(), cmdArgs, tc.targets, pkgBuildDirs, []string{}, false) + require.NoError(td, errI) + + require.Len(td, mockRunner.ShowCalls, len(tc.wantShow)) + + for i, call := range mockRunner.ShowCalls { + show := call.Args[0].(*exec.Cmd).String() + show = strings.ReplaceAll(show, tmpDir, "/testdir") // replace the temp dir with a static path + show = strings.ReplaceAll(show, makepkgBin, "makepkg") + show = strings.ReplaceAll(show, pacmanBin, "pacman") + + // options are in a different order on different systems and on CI root user is used + assert.Subset(td, strings.Split(show, " "), strings.Split(tc.wantShow[i], " "), show) + + // Only assert makepkg commands don't have clean arguments + if strings.HasPrefix(show, "makepkg") { + assert.NotContains(td, show, "-c") + assert.NotContains(td, show, "-C") + } + } + }) + } +} diff --git a/pkg/sync/workdir/aur_source.go b/pkg/sync/workdir/aur_source.go index b517095b8..821cbc741 100644 --- a/pkg/sync/workdir/aur_source.go +++ b/pkg/sync/workdir/aur_source.go @@ -32,7 +32,11 @@ func (e *ErrDownloadSource) Unwrap() error { func downloadPKGBUILDSource(ctx context.Context, cmdBuilder exe.ICmdBuilder, pkgBuildDir string, installIncompatible bool, ) error { - args := []string{"--verifysource", "--skippgpcheck", "-Ccf"} + args := []string{"--verifysource", "--skippgpcheck", "-f"} + + if cmdBuilder.GetCleanBuild() { + args = append(args, "-Cc") + } if installIncompatible { args = append(args, "--ignorearch") diff --git a/pkg/sync/workdir/aur_source_test.go b/pkg/sync/workdir/aur_source_test.go index 266ddac80..0f20f43da 100644 --- a/pkg/sync/workdir/aur_source_test.go +++ b/pkg/sync/workdir/aur_source_test.go @@ -33,6 +33,10 @@ func (z *TestMakepkgBuilder) BuildMakepkgCmd(ctx context.Context, dir string, ex assert.Contains(z.test, cmd.String(), z.want) } + if !z.GetCleanBuild() { + assert.NotContains(z.test, cmd.String(), "-Cc") + } + if z.wantDir != "" { assert.Equal(z.test, z.wantDir, cmd.Dir) } @@ -46,20 +50,54 @@ func (z *TestMakepkgBuilder) Show(cmd *exec.Cmd) error { return z.showError } +func (z *TestMakepkgBuilder) GetCleanBuild() bool { + return z.parentBuilder.CleanBuild +} + // GIVEN 1 package // WHEN downloadPKGBUILDSource is called // THEN 1 call should be made to makepkg with the specified parameters and dir func Test_downloadPKGBUILDSource(t *testing.T) { t.Parallel() - cmdBuilder := &TestMakepkgBuilder{ - parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg"}, - test: t, - want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -Ccf", - wantDir: "/tmp/yay-bin", + + type testCase struct { + desc string + cleanBuild bool + want string + } + + testCases := []testCase{ + { + desc: "cleanbuild", + cleanBuild: true, + want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc", + }, + { + desc: "nocleanbuild", + cleanBuild: false, + want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f", + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.desc, func(td *testing.T) { + cmdBuilder := &TestMakepkgBuilder{ + parentBuilder: &exe.CmdBuilder{ + MakepkgConfPath: "/etc/not.conf", + MakepkgFlags: []string{"--nocheck"}, + MakepkgBin: "makepkg", + CleanBuild: tc.cleanBuild, + }, + test: t, + want: tc.want, + wantDir: "/tmp/yay-bin", + } + err := downloadPKGBUILDSource(context.Background(), cmdBuilder, filepath.Join("/tmp", "yay-bin"), false) + assert.NoError(t, err) + assert.Equal(t, 1, int(cmdBuilder.passes)) + }) } - err := downloadPKGBUILDSource(context.Background(), cmdBuilder, filepath.Join("/tmp", "yay-bin"), false) - assert.NoError(t, err) - assert.Equal(t, 1, int(cmdBuilder.passes)) } // GIVEN 1 package @@ -68,9 +106,9 @@ func Test_downloadPKGBUILDSource(t *testing.T) { func Test_downloadPKGBUILDSourceError(t *testing.T) { t.Parallel() cmdBuilder := &TestMakepkgBuilder{ - parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg"}, + parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", CleanBuild: true}, test: t, - want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -Ccf", + want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc", wantDir: "/tmp/yay-bin", showError: &exec.ExitError{}, } @@ -98,6 +136,7 @@ func Test_downloadPKGBUILDSourceFanout(t *testing.T) { parentBuilder: &exe.CmdBuilder{ MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", + CleanBuild: true, }, test: t, } @@ -118,6 +157,7 @@ func Test_downloadPKGBUILDSourceFanoutNoCC(t *testing.T) { parentBuilder: &exe.CmdBuilder{ MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", + CleanBuild: true, }, test: t, } @@ -138,6 +178,7 @@ func Test_downloadPKGBUILDSourceFanoutError(t *testing.T) { parentBuilder: &exe.CmdBuilder{ MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", + CleanBuild: true, }, test: t, showError: &exec.ExitError{}, diff --git a/sync_test.go b/sync_test.go index 973b16e42..977686677 100644 --- a/sync_test.go +++ b/sync_test.go @@ -64,6 +64,7 @@ func TestSyncUpgrade(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -176,6 +177,7 @@ func TestSyncUpgrade_IgnoreAll(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -287,6 +289,7 @@ func TestSyncUpgrade_IgnoreOne(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -460,6 +463,7 @@ pkgname = python-vosk PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } @@ -552,11 +556,11 @@ pkgname = python-vosk } wantShow := []string{ "pacman -S -y --config /etc/pacman.conf --", - "makepkg --verifysource --skippgpcheck -Ccf", "makepkg --nobuild -fC --ignorearch", + "makepkg --verifysource --skippgpcheck -f -Cc", "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/vosk-api-0.3.45-1-x86_64.pkg.tar.zst", - "makepkg --nobuild -fC --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", - "makepkg --nobuild -fC --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", + "makepkg --nobuild -f -C --ignorearch", "makepkg -c --nobuild --noextract --ignorearch", "pacman -U --config /etc/pacman.conf -- /testdir/vosk-api-0.3.45-1-x86_64.pkg.tar.zst /testdir/python-vosk-0.3.45-1-x86_64.pkg.tar.zst", "pacman -D -q --asdeps --config /etc/pacman.conf -- vosk-api", "pacman -D -q --asexplicit --config /etc/pacman.conf -- python-vosk", @@ -665,6 +669,7 @@ func TestSyncUpgrade_NoCombinedUpgrade(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, + CleanBuild: true, SudoLoopEnabled: false, } From 4514c5a2601b5d9d422259988a6e5e1eec4d46cc Mon Sep 17 00:00:00 2001 From: jdholtz Date: Thu, 7 Sep 2023 11:57:53 -0500 Subject: [PATCH 2/3] fix(completion): simplify description for --nocleanbuild in fish This makes the description consistent with the descriptions in the man page, --help, and zsh completion. --- completions/fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/fish b/completions/fish index 2eaa843c4..b62aae391 100644 --- a/completions/fish +++ b/completions/fish @@ -231,7 +231,7 @@ complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg developme complete -c $progname -n "not $noopt" -l nodevel -d 'Disable development version checking' -f complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f complete -c $progname -n "not $noopt" -l nocleanafter -d 'Disable package sources cleaning' -f -complete -c $progname -n "not $noopt" -l nocleanbuild -d 'Do not remove pkg/ and src/ directories after building packages' -f +complete -c $progname -n "not $noopt" -l nocleanbuild -d 'Do not remove pkg/ and src/ after building packages' -f complete -c $progname -n "not $noopt" -l timeupdate -d 'Check package modification date and version' -f complete -c $progname -n "not $noopt" -l notimeupdate -d 'Check only package version change' -f complete -c $progname -n "not $noopt" -l redownload -d 'Redownload PKGBUILD of package even if up-to-date' -f From 519471b959a94debbbc3a7fc0a59798d984dd3d9 Mon Sep 17 00:00:00 2001 From: jdholtz Date: Fri, 15 Sep 2023 10:24:10 -0500 Subject: [PATCH 3/3] refactor(install): Rename --nocleanbuild to --keepsrc This naming scheme is more familiar to users since it is the name of the flag in Paru. --- cmd.go | 2 +- completions/bash | 2 +- completions/fish | 2 +- completions/zsh | 2 +- doc/yay.8 | 4 ++-- local_install_test.go | 7 ------- pkg/settings/args.go | 4 ++-- pkg/settings/config.go | 4 ++-- pkg/settings/exe/cmd_builder.go | 10 +++++----- pkg/settings/exe/mock.go | 6 +++--- pkg/settings/parser/parser.go | 2 +- pkg/sync/build/installer.go | 4 ++-- pkg/sync/build/installer_test.go | 15 +++----------- pkg/sync/workdir/aur_source.go | 2 +- pkg/sync/workdir/aur_source_test.go | 31 +++++++++++++---------------- sync_test.go | 5 ----- 16 files changed, 39 insertions(+), 63 deletions(-) diff --git a/cmd.go b/cmd.go index 32bb4504b..6b233d121 100644 --- a/cmd.go +++ b/cmd.go @@ -102,7 +102,7 @@ Permanent configuration options: --cleanafter Remove package sources after successful install --nocleanafter Do not remove package sources after successful build - --nocleanbuild Do not remove pkg/ and src/ after building packages + --keepsrc Keep pkg/ and src/ after building packages --bottomup Shows AUR's packages first and then repository's --topdown Shows repository's packages first and then AUR's --singlelineresults List each search result on its own line diff --git a/completions/bash b/completions/bash index 6a1ba7f55..23743edb9 100644 --- a/completions/bash +++ b/completions/bash @@ -72,7 +72,7 @@ _yay() { makepkg pacman git gpg gpgflags config requestsplitn sudoloop nosudoloop redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild sortby singlelineresults doublelineresults answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff - noansweredit noanswerupgrade cleanmenu diffmenu editmenu cleanafter nocleanafter nocleanbuild + noansweredit noanswerupgrade cleanmenu diffmenu editmenu cleanafter nocleanafter keepsrc nocleanmenu nodiffmenu provides noprovides pgpfetch nopgpfetch useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf nomakepkgconf askremovemake askyesremovemake removemake noremovemake completioninterval aururl aurrpcurl diff --git a/completions/fish b/completions/fish index b62aae391..eb89d0b19 100644 --- a/completions/fish +++ b/completions/fish @@ -231,7 +231,7 @@ complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg developme complete -c $progname -n "not $noopt" -l nodevel -d 'Disable development version checking' -f complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f complete -c $progname -n "not $noopt" -l nocleanafter -d 'Disable package sources cleaning' -f -complete -c $progname -n "not $noopt" -l nocleanbuild -d 'Do not remove pkg/ and src/ after building packages' -f +complete -c $progname -n "not $noopt" -l keepsrc -d 'Keep pkg/ and src/ after building packages' -f complete -c $progname -n "not $noopt" -l timeupdate -d 'Check package modification date and version' -f complete -c $progname -n "not $noopt" -l notimeupdate -d 'Check only package version change' -f complete -c $progname -n "not $noopt" -l redownload -d 'Redownload PKGBUILD of package even if up-to-date' -f diff --git a/completions/zsh b/completions/zsh index f0d6c9524..e1f1ec438 100644 --- a/completions/zsh +++ b/completions/zsh @@ -86,7 +86,7 @@ _pacman_opts_common=( '--nodevel[Disable development version checking]' '--cleanafter[Clean package sources after successful build]' '--nocleanafter[Disable package sources cleaning after successful build]' - '--nocleanbuild[Do not remove pkg/ and src/ after building packages]' + '--keepsrc[Keep pkg/ and src/ after building packages]' '--timeupdate[Check packages modification date and version]' '--notimeupdate[Check only package version change]' '--redownload[Always download pkgbuilds of targets]' diff --git a/doc/yay.8 b/doc/yay.8 index ba5c2254e..884865840 100644 --- a/doc/yay.8 +++ b/doc/yay.8 @@ -385,8 +385,8 @@ instead of having to reclone the entire repo. Do not remove package sources after successful Install. .TP -.B \-\-nocleanbuild -Do not remove pkg/ and src/ after building packages +.B \-\-keepsrc +Keep pkg/ and src/ after building packages .TP .B \-\-timeupdate diff --git a/local_install_test.go b/local_install_test.go index 685c0f8c9..c9d2fa5e4 100644 --- a/local_install_test.go +++ b/local_install_test.go @@ -104,7 +104,6 @@ func TestIntegrationLocalInstall(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -234,7 +233,6 @@ func TestIntegrationLocalInstallMissingDep(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -370,7 +368,6 @@ func TestIntegrationLocalInstallNeeded(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -549,7 +546,6 @@ func TestIntegrationLocalInstallGenerateSRCINFO(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -688,7 +684,6 @@ func TestIntegrationLocalInstallMissingFiles(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -831,7 +826,6 @@ func TestIntegrationLocalInstallWithDepsProvides(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -971,7 +965,6 @@ func TestIntegrationLocalInstallTwoSrcInfosWithDeps(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } diff --git a/pkg/settings/args.go b/pkg/settings/args.go index 4470b0c8c..ddcf84ab5 100644 --- a/pkg/settings/args.go +++ b/pkg/settings/args.go @@ -53,8 +53,8 @@ func (c *Configuration) handleOption(option, value string) bool { c.CleanAfter = true case "noafterclean", "nocleanafter": c.CleanAfter = false - case "nocleanbuild": - c.CleanBuild = false + case "keepsrc": + c.KeepSrc = true case "debug": c.Debug = true return false diff --git a/pkg/settings/config.go b/pkg/settings/config.go index 21384b176..e342e0ed6 100644 --- a/pkg/settings/config.go +++ b/pkg/settings/config.go @@ -56,7 +56,7 @@ type Configuration struct { TimeUpdate bool `json:"timeupdate"` Devel bool `json:"devel"` CleanAfter bool `json:"cleanAfter"` - CleanBuild bool `json:"cleanBuild"` + KeepSrc bool `json:"keepSrc"` Provides bool `json:"provides"` PGPFetch bool `json:"pgpfetch"` CleanMenu bool `json:"cleanmenu"` @@ -194,7 +194,7 @@ func DefaultConfig(version string) *Configuration { AURURL: "https://aur.archlinux.org", BuildDir: os.ExpandEnv("$HOME/.cache/yay"), CleanAfter: false, - CleanBuild: true, + KeepSrc: false, Editor: "", EditorFlags: "", Devel: false, diff --git a/pkg/settings/exe/cmd_builder.go b/pkg/settings/exe/cmd_builder.go index 541866c5d..f11201ba1 100644 --- a/pkg/settings/exe/cmd_builder.go +++ b/pkg/settings/exe/cmd_builder.go @@ -39,12 +39,11 @@ type ICmdBuilder interface { BuildMakepkgCmd(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd BuildPacmanCmd(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd AddMakepkgFlag(string) - GetCleanBuild() bool + GetKeepSrc() bool SudoLoop() } type CmdBuilder struct { - CleanBuild bool GitBin string GitFlags []string GPGBin string @@ -58,13 +57,13 @@ type CmdBuilder struct { PacmanBin string PacmanConfigPath string PacmanDBPath string + KeepSrc bool Runner Runner Log *text.Logger } func NewCmdBuilder(cfg *settings.Configuration, runner Runner, logger *text.Logger, dbPath string) *CmdBuilder { return &CmdBuilder{ - CleanBuild: cfg.CleanBuild, GitBin: cfg.GitBin, GitFlags: strings.Fields(cfg.GitFlags), GPGBin: cfg.GpgBin, @@ -78,6 +77,7 @@ func NewCmdBuilder(cfg *settings.Configuration, runner Runner, logger *text.Logg PacmanBin: cfg.PacmanBin, PacmanConfigPath: cfg.PacmanConf, PacmanDBPath: dbPath, + KeepSrc: cfg.KeepSrc, Runner: runner, Log: logger, } @@ -300,6 +300,6 @@ func (c *CmdBuilder) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) { return c.Runner.Capture(cmd) } -func (c *CmdBuilder) GetCleanBuild() bool { - return c.CleanBuild +func (c *CmdBuilder) GetKeepSrc() bool { + return c.KeepSrc } diff --git a/pkg/settings/exe/mock.go b/pkg/settings/exe/mock.go index 95c7b8371..31a1f896d 100644 --- a/pkg/settings/exe/mock.go +++ b/pkg/settings/exe/mock.go @@ -25,7 +25,7 @@ type MockBuilder struct { BuildMakepkgCmdCalls []Call BuildMakepkgCmdFn func(ctx context.Context, dir string, extraArgs ...string) *exec.Cmd BuildPacmanCmdFn func(ctx context.Context, args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd - GetCleanBuildFn func() bool + GetKeepSrcFn func() bool } type MockRunner struct { @@ -96,8 +96,8 @@ func (m *MockBuilder) Show(cmd *exec.Cmd) error { return m.Runner.Show(cmd) } -func (m *MockBuilder) GetCleanBuild() bool { - return true +func (m *MockBuilder) GetKeepSrc() bool { + return false } func (m *MockRunner) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) { diff --git a/pkg/settings/parser/parser.go b/pkg/settings/parser/parser.go index cb96a7c7c..885bf9c13 100644 --- a/pkg/settings/parser/parser.go +++ b/pkg/settings/parser/parser.go @@ -378,7 +378,7 @@ func isArg(arg string) bool { case "save": case "afterclean", "cleanafter": case "noafterclean", "nocleanafter": - case "nocleanbuild": + case "keepsrc": case "devel": case "nodevel": case "timeupdate": diff --git a/pkg/sync/build/installer.go b/pkg/sync/build/installer.go index 4169abee9..59b2599d4 100644 --- a/pkg/sync/build/installer.go +++ b/pkg/sync/build/installer.go @@ -279,7 +279,7 @@ func (installer *Installer) buildPkg(ctx context.Context, ) (map[string]string, error) { args := []string{"--nobuild", "-f"} - if installer.exeCmd.GetCleanBuild() { + if !installer.exeCmd.GetKeepSrc() { args = append(args, "-C") } @@ -313,7 +313,7 @@ func (installer *Installer) buildPkg(ctx context.Context, } } - if installer.exeCmd.GetCleanBuild() { + if !installer.exeCmd.GetKeepSrc() { args = append(args, "-c") } diff --git a/pkg/sync/build/installer_test.go b/pkg/sync/build/installer_test.go index 33b819d09..434e48741 100644 --- a/pkg/sync/build/installer_test.go +++ b/pkg/sync/build/installer_test.go @@ -128,7 +128,6 @@ func TestInstaller_InstallNeeded(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -404,7 +403,6 @@ func TestInstaller_InstallMixedSourcesAndLayers(t *testing.T) { PacmanBin: pacmanBin, PacmanConfigPath: "/etc/pacman.conf", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -458,7 +456,6 @@ func TestInstaller_RunPostHooks(t *testing.T) { PacmanBin: "pacman", PacmanConfigPath: "/etc/pacman.conf", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -590,7 +587,6 @@ func TestInstaller_CompileFailed(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -751,7 +747,6 @@ func TestInstaller_InstallSplitPackage(t *testing.T) { PacmanBin: pacmanBin, PacmanConfigPath: "/etc/pacman.conf", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -891,7 +886,6 @@ func TestInstaller_InstallDownloadOnly(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -996,7 +990,6 @@ func TestInstaller_InstallGroup(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -1215,7 +1208,6 @@ func TestInstaller_InstallRebuild(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -1303,7 +1295,6 @@ func TestInstaller_InstallUpgrade(t *testing.T) { SudoBin: "su", PacmanBin: pacmanBin, Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -1347,7 +1338,7 @@ func TestInstaller_InstallUpgrade(t *testing.T) { } } -func TestInstaller_NoCleanBuild(t *testing.T) { +func TestInstaller_KeepSrc(t *testing.T) { t.Parallel() makepkgBin := t.TempDir() + "/makepkg" @@ -1370,7 +1361,7 @@ func TestInstaller_NoCleanBuild(t *testing.T) { testCases := []testCase{ { - desc: "--nocleanbuild", + desc: "--keepsrc", wantShow: []string{ "makepkg --nobuild -f --ignorearch", "makepkg --nobuild --noextract --ignorearch", @@ -1412,8 +1403,8 @@ func TestInstaller_NoCleanBuild(t *testing.T) { MakepkgBin: makepkgBin, SudoBin: "su", PacmanBin: pacmanBin, + KeepSrc: true, Runner: mockRunner, - CleanBuild: false, SudoLoopEnabled: false, } diff --git a/pkg/sync/workdir/aur_source.go b/pkg/sync/workdir/aur_source.go index 821cbc741..6777369b5 100644 --- a/pkg/sync/workdir/aur_source.go +++ b/pkg/sync/workdir/aur_source.go @@ -34,7 +34,7 @@ func downloadPKGBUILDSource(ctx context.Context, ) error { args := []string{"--verifysource", "--skippgpcheck", "-f"} - if cmdBuilder.GetCleanBuild() { + if !cmdBuilder.GetKeepSrc() { args = append(args, "-Cc") } diff --git a/pkg/sync/workdir/aur_source_test.go b/pkg/sync/workdir/aur_source_test.go index 0f20f43da..dd141f971 100644 --- a/pkg/sync/workdir/aur_source_test.go +++ b/pkg/sync/workdir/aur_source_test.go @@ -33,7 +33,7 @@ func (z *TestMakepkgBuilder) BuildMakepkgCmd(ctx context.Context, dir string, ex assert.Contains(z.test, cmd.String(), z.want) } - if !z.GetCleanBuild() { + if z.GetKeepSrc() { assert.NotContains(z.test, cmd.String(), "-Cc") } @@ -50,8 +50,8 @@ func (z *TestMakepkgBuilder) Show(cmd *exec.Cmd) error { return z.showError } -func (z *TestMakepkgBuilder) GetCleanBuild() bool { - return z.parentBuilder.CleanBuild +func (z *TestMakepkgBuilder) GetKeepSrc() bool { + return z.parentBuilder.KeepSrc } // GIVEN 1 package @@ -61,21 +61,21 @@ func Test_downloadPKGBUILDSource(t *testing.T) { t.Parallel() type testCase struct { - desc string - cleanBuild bool - want string + desc string + keepSrc bool + want string } testCases := []testCase{ { - desc: "cleanbuild", - cleanBuild: true, - want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc", + desc: "keepsrc", + keepSrc: true, + want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f", }, { - desc: "nocleanbuild", - cleanBuild: false, - want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f", + desc: "nokeepsrc", + keepSrc: false, + want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc", }, } @@ -87,7 +87,7 @@ func Test_downloadPKGBUILDSource(t *testing.T) { MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", - CleanBuild: tc.cleanBuild, + KeepSrc: tc.keepSrc, }, test: t, want: tc.want, @@ -106,7 +106,7 @@ func Test_downloadPKGBUILDSource(t *testing.T) { func Test_downloadPKGBUILDSourceError(t *testing.T) { t.Parallel() cmdBuilder := &TestMakepkgBuilder{ - parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", CleanBuild: true}, + parentBuilder: &exe.CmdBuilder{MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg"}, test: t, want: "makepkg --nocheck --config /etc/not.conf --verifysource --skippgpcheck -f -Cc", wantDir: "/tmp/yay-bin", @@ -136,7 +136,6 @@ func Test_downloadPKGBUILDSourceFanout(t *testing.T) { parentBuilder: &exe.CmdBuilder{ MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", - CleanBuild: true, }, test: t, } @@ -157,7 +156,6 @@ func Test_downloadPKGBUILDSourceFanoutNoCC(t *testing.T) { parentBuilder: &exe.CmdBuilder{ MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", - CleanBuild: true, }, test: t, } @@ -178,7 +176,6 @@ func Test_downloadPKGBUILDSourceFanoutError(t *testing.T) { parentBuilder: &exe.CmdBuilder{ MakepkgConfPath: "/etc/not.conf", MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg", - CleanBuild: true, }, test: t, showError: &exec.ExitError{}, diff --git a/sync_test.go b/sync_test.go index 977686677..488176c54 100644 --- a/sync_test.go +++ b/sync_test.go @@ -64,7 +64,6 @@ func TestSyncUpgrade(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -177,7 +176,6 @@ func TestSyncUpgrade_IgnoreAll(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -289,7 +287,6 @@ func TestSyncUpgrade_IgnoreOne(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -463,7 +460,6 @@ pkgname = python-vosk PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, } @@ -669,7 +665,6 @@ func TestSyncUpgrade_NoCombinedUpgrade(t *testing.T) { PacmanConfigPath: "/etc/pacman.conf", GitBin: "git", Runner: mockRunner, - CleanBuild: true, SudoLoopEnabled: false, }