[pacman-dev] [PATCH] makepkg: use --unneeded for pacman call in remove_deps()

Allan McRae allan at archlinux.org
Wed Jan 30 00:51:13 UTC 2019

This patch was inspired by FS#32723 which asks makepkg to install makedepends
before depends.  The use case is build package depending on a virtual package
that is only provided by other packages (e.g. java-runtime in Arch Linux), but
wanting to build against a specific version.  Installing makedepends first
(but not at the same time as depends) would allow specifying the version to
build against, instead of pacman resolving to the default version when
installing depends.

It turns out, we can already achieve installing makedepends first by specifying
dependencies only in the package function (and making sure makedepends includes
everything needed). The only issue is that if we use makepkg to install the
built package with the --install flag and along with the --rmdeps flag, we will
try to remove any installed dependencies that are specified in the depends
array in the package function.  To counter this, we need to use the --unneeded
flag for the pacman call.

Signed-off-by: Allan McRae <allan at archlinux.org>

I think I need a prize for the size of the commit message for a one character

 scripts/makepkg.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index c81dc801..749d074a 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -336,7 +336,7 @@ remove_deps() {
 	msg "Removing installed dependencies..."
 	# exit cleanly on failure to remove deps as package has been built successfully
-	if ! run_pacman -Rn ${deplist[@]}; then
+	if ! run_pacman -Rnu ${deplist[@]}; then
 		warning "$(gettext "Failed to remove installed dependencies.")"

More information about the pacman-dev mailing list