feat(install): add --keepsrc to keep pkg/ and src/ directories (#2272)
* 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) * fix(completion): simplify description for --nocleanbuild in fish This makes the description consistent with the descriptions in the man page, --help, and zsh completion. * refactor(install): Rename --nocleanbuild to --keepsrc This naming scheme is more familiar to users since it is the name of the flag in Paru. --------- Co-authored-by: jguer <me@jguer.space>
This commit is contained in:
1 parent
e60ccdf8b7
commit
04c76a404e
16 files changed
+248
-70
No files matched your search
@@ -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.GetKeepSrc() {
|
||||
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.GetKeepSrc() {
|
||||
args = append(args, "-c")
|
||||
}
|
||||
|
||||
errMake := installer.exeCmd.Show(
|
||||
installer.exeCmd.BuildMakepkgCmd(ctx,
|
||||
dir, args...))
|
||||
|
||||
@@ -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"},
|
||||
@@ -212,8 +212,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 +241,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 +293,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 +323,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 +374,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())
|
||||
@@ -570,7 +570,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
|
||||
@@ -694,13 +694,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",
|
||||
@@ -818,7 +818,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 +828,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 +838,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"},
|
||||
@@ -1075,7 +1075,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 +1099,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 +1123,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 +1147,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",
|
||||
},
|
||||
@@ -1337,3 +1337,107 @@ func TestInstaller_InstallUpgrade(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstaller_KeepSrc(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: "--keepsrc",
|
||||
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,
|
||||
KeepSrc: true,
|
||||
Runner: mockRunner,
|
||||
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")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user