Skip to content

Commit

Permalink
feat(install): add --keepsrc to keep pkg/ and src/ directories (#2272)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jdholtz and Jguer authored Sep 18, 2023
1 parent e60ccdf commit 04c76a4
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 70 deletions.
1 change: 1 addition & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Permanent configuration options:
--cleanafter Remove package sources after successful install
--nocleanafter Do not remove package sources after successful build
--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
Expand Down
2 changes: 1 addition & 1 deletion completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 keepsrc
nocleanmenu nodiffmenu provides noprovides pgpfetch nopgpfetch
useask nouseask combinedupgrade nocombinedupgrade aur repo makepkgconf
nomakepkgconf askremovemake askyesremovemake removemake noremovemake completioninterval aururl aurrpcurl
Expand Down
1 change: 1 addition & 0 deletions completions/fish
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down
1 change: 1 addition & 0 deletions completions/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
'--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]'
Expand Down
4 changes: 4 additions & 0 deletions doc/yay.8
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ instead of having to reclone the entire repo.
.B \-\-nocleanafter
Do not remove package sources after successful Install.

.TP
.B \-\-keepsrc
Keep pkg/ and src/ after building packages

.TP
.B \-\-timeupdate
During sysupgrade also compare the build time of installed packages against
Expand Down
38 changes: 19 additions & 19 deletions local_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -324,14 +324,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",
}

Expand Down Expand Up @@ -492,16 +492,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",
Expand Down Expand Up @@ -783,12 +783,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",
Expand Down Expand Up @@ -910,13 +910,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",
Expand Down
2 changes: 2 additions & 0 deletions pkg/settings/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (c *Configuration) handleOption(option, value string) bool {
c.CleanAfter = true
case "noafterclean", "nocleanafter":
c.CleanAfter = false
case "keepsrc":
c.KeepSrc = true
case "debug":
c.Debug = true
return false
Expand Down
2 changes: 2 additions & 0 deletions pkg/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Configuration struct {
TimeUpdate bool `json:"timeupdate"`
Devel bool `json:"devel"`
CleanAfter bool `json:"cleanAfter"`
KeepSrc bool `json:"keepSrc"`
Provides bool `json:"provides"`
PGPFetch bool `json:"pgpfetch"`
CleanMenu bool `json:"cleanmenu"`
Expand Down Expand Up @@ -193,6 +194,7 @@ func DefaultConfig(version string) *Configuration {
AURURL: "https://aur.archlinux.org",
BuildDir: os.ExpandEnv("$HOME/.cache/yay"),
CleanAfter: false,
KeepSrc: false,
Editor: "",
EditorFlags: "",
Devel: false,
Expand Down
7 changes: 7 additions & 0 deletions pkg/settings/exe/cmd_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ 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)
GetKeepSrc() bool
SudoLoop()
}

Expand All @@ -56,6 +57,7 @@ type CmdBuilder struct {
PacmanBin string
PacmanConfigPath string
PacmanDBPath string
KeepSrc bool
Runner Runner
Log *text.Logger
}
Expand All @@ -75,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,
}
Expand Down Expand Up @@ -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) GetKeepSrc() bool {
return c.KeepSrc
}
5 changes: 5 additions & 0 deletions pkg/settings/exe/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
GetKeepSrcFn func() bool
}

type MockRunner struct {
Expand Down Expand Up @@ -95,6 +96,10 @@ func (m *MockBuilder) Show(cmd *exec.Cmd) error {
return m.Runner.Show(cmd)
}

func (m *MockBuilder) GetKeepSrc() bool {
return false
}

func (m *MockRunner) Capture(cmd *exec.Cmd) (stdout, stderr string, err error) {
m.CaptureCallsMu.Lock()
m.CaptureCalls = append(m.CaptureCalls, Call{
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func isArg(arg string) bool {
case "save":
case "afterclean", "cleanafter":
case "noafterclean", "nocleanafter":
case "keepsrc":
case "devel":
case "nodevel":
case "timeupdate":
Expand Down
16 changes: 12 additions & 4 deletions pkg/sync/build/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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...))
Expand Down
Loading

0 comments on commit 04c76a4

Please sign in to comment.