[pacman-dev] [RFC] [PATCH] makepkg: provide mechanism for auto-updating pkgver

Allan McRae allan at archlinux.org
Mon Jun 4 23:49:30 EDT 2012


Now that VCS repos are provided in the source array, it becomes too
complicated to have automatic updating pkgver as was the case with
the old VCS PKGBUILDs (there can be multiple repos of different types
in the source array, the VCS repo may not be the package primary
source, etc).

Instead provide an optional way for a PKGBUILD to update the pkgver
value through the specifing of a pkgver() function that returns the
new version string.  This is run after all source files are downloaded
so can access the VCS repo if needed.

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

Note that this means that now makepkg in no way modifies your PKGBUILD
unless requested.  For example... in a PKGBUILD:


pkgver=1
source=('git+https://projects.archlinux.org/git/pacman.git#branch=maint')

pkgver() {
	cd $srcdir/pacman
	ver=$(git describe | sed 's/-/_/g')
	printf "%s\n" "${ver##v}"
}


will set the pkgver to something like "4.0.3_17_g5de465d".


 scripts/makepkg.sh.in |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 689a2f6..7d4636f 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -462,9 +462,30 @@ download_sources() {
 		esac
 	done
 
+	if declare -f pkgver >/dev/null; then
+		update_pkgver
+	fi
+
 	popd &>/dev/null
 }
 
+# Automatically update pkgver variable if a pkgver() function is provided
+# Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver
+update_pkgver() {
+	newpkgver=$(pkgver)
+
+	if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
+		if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
+			@SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
+			@SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
+			source "$BUILDFILE"
+		else
+			warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \
+					"$BUILDFILE"
+		fi
+	fi
+}
+
 # Print 'source not found' error message and exit makepkg
 missing_source_file() {
 	error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
-- 
1.7.10.3



More information about the pacman-dev mailing list