[pacman-dev] [PATCH] Integrate versionpkg into makepkg

Dan McGee dpmcgee at gmail.com
Fri Oct 26 19:49:17 EDT 2007


On 10/26/07, Scott Horowitz <stonecrest at gmail.com> wrote:
> > Hate to stomp on good ideas, but can you port this patch to the
> > current GIT version of makepkg? I really like it because it doesn't
> > seem to do too much, but makepkg has changed a lot since pacman 3.0.0.
>
> Ok, attached is a patch against makepkg in git. It uses Aaron's sed
> line and is simplified a bit from my previous patch.
>
> > One thought- usage instructions would be nice to be in the patch too
> > (the stuff from makepkg --help).
>
> I'm not sure what you mean? There aren't any usage instructions, it
> doesn't add any public arguments. If it finds the correct svn/etc
> variables in the PKGBUILD, it'll update to the latest revision.
> (Behind the scenes, I do use a -z argument to prevent the revision
> number from being searched for twice due to fakeroot's makepkg
> call...)

Ahh, one of those hidden options. Comments below on that.

> It also fixes a small typo ;-)
>
> And finally, makepkg -p seems to be documented, but the argument
> doesn't appear to be valid anymore (it's not parsed). I'm not sure if
> your intention was to remove that option or it's simply an
> oversight...

Fixed on my working branch, it looks like it was an oversight in the
getopt conversion.

I've repasted your patch below to give a few comments. Overall looks
pretty good though. I am going to have to ask you for one thing:
http://archlinux.org/pipermail/pacman-dev/2007-October/009681.html

This should help you make a patch:
http://wiki.archlinux.org/index.php/Super_Quick_Git_Guide

For everyone: to make a patch, just start your own branch based off of
master (git checkout -b mybranch master), make your changes, and use
the poor man's way of committing everything (git commit -a -s). Then
type 'git-format-patch master' and you'll produce a stupendous patch.
(Note: you may want to do 'git-config --global user.name "My Name"'
and git-config --global user.email "myemail at domain.com"' to make your
signoff and author lines correct.)

-Dan

--- pacman/scripts/makepkg.sh.in	2007-10-26 16:05:33.000000000 -0600
+++ makepkg.sh.in	2007-10-26 15:59:50.000000000 -0600
@@ -60,6 +60,8 @@
 SOURCEONLY=0
 IGNOREARCH=0

+FORCE_VER=""
***Perhaps a comment here stating what this var is used for?
+
 PACMAN_OPTS=

 ### SUBROUTINES ###
@@ -976,6 +978,72 @@
 	fi
 }

+devel_check() {
+	newpkgver=""
+	if [ "$FORCE_VER" = "" ]; then
+		# Check if this is a svn/cvs/etc PKGBUILD; set $newpkgver if so.
+		# This will only be used on the first call to makepkg; subsequent
+		# calls to makepkg via fakeroot will explicitly pass the version
+		# number to avoid having to determine the version number twice.
+		oldpkgver=$pkgver
+		if [ ! -z ${_darcstrunk} ] && [ ! -z ${_darcsmod} ] ; then
+			msg "$(gettext "Determining latest darcs revision...")"
+			newpkgver=$(date +%Y%m%d)
+		elif [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then
+			msg "$(gettext "Determining latest cvs revision...")"
+			newpkgver=$(date +%Y%m%d)
+		elif [ ! -z ${_gitroot} ] && [ ! -z ${_gitname} ] ; then
+			msg "$(gettext "Determining latest git revision...")"
+			newpkgver=$(date +%Y%m%d)
+		elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then
+			msg "$(gettext "Determining latest svn revision...")"
+			newpkgver=$(svn log $_svntrunk --limit 1 | sed -n 's/^r\([^ ]*\) .*$/\1/p')
+		elif [ ! -z ${_bzrtrunk} ] && [ ! -z ${_bzrmod} ] ; then
+			msg "$(gettext "Determining latest bzr revision...")"
+			newpkgver=$(bzr revno ${_bzrtrunk})
+		elif [ ! -z ${_hgroot} ] && [ ! -z ${_hgrepo} ] ; then
+			msg "$(gettext "Determining latest hg revision...")"
+			if [ -d ./src/$_hgrepo ] ; then
+				cd ./src/$_hgrepo
+				make clean
+				hg pull
+				hg update
+			else
+				[[ ! -d ./src/$_hgrepo ]] && mkdir -p ./src/$_hgrepo
+				hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
+				cd ./src/$_hgrepo
+			fi
+			newpkgver=$(hg tip | sed -n '1s/[^0-9]*\([^:]*\):.*$/\1/p')
+			cd ../../
+		fi
+
+		if [ "$newpkgver" != "" ]; then
+			msg2 "$(gettext "Version found: %s")" "$newpkgver"
+			pkgver=$newpkgver
+		fi
+
+	else
+		# Version number retrieved from fakeroot->makepkg argument
+		newpkgver=$FORCE_VER
+	fi
+}
***Trusting that this code is good, it looks sane to me.
+
+devel_update() {
+	# This is lame, but if we're wanting to use an updated pkgver for
+	# retrieving svn/cvs/etc sources, we'll update the PKGBUILD with
+	# the new pkgver and then re-source it. This is the most robust
+	# method for dealing with PKGBUILDs that use, e.g.:
+	#     pkgver=23
+	#     ...
+	#     _foo=pkgver
+	if [ "$newpkgver" != "" ]; then
+		if [ "newpkgver" != "$pkgver" ]; then
+			sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" ./$BUILDSCRIPT
+			source $BUILDSCRIPT
+		fi
+	fi
+}
+
 usage() {
 	printf "makepkg (pacman) %s\n" "$myver"
 	echo
@@ -1058,7 +1126,7 @@
 fi

 # Parse Command Line Options.
-OPT_SHORT="AbcCdefFghiLmop:rRsSV"
+OPT_SHORT="AbcCdefFghiLmopz:rRsSV"
 OPT_LONG="ignorearch,asroot,builddeps,clean,cleancache,nodeps,noextract,force,geninteg,help,install,log"
 OPT_LONG="$OPT_LONG,nocolor,nobuild,rmdeps,repackage,source,syncdeps,usesudo,version"
 # Pacman Options
@@ -1096,6 +1164,7 @@
 		-R|--repackage)   REPKG=1 ;;
 		--source)         SOURCEONLY=1 ;;
 		-s|--syncdeps)    DEP_BIN=1 ;;
+		-z)               shift; FORCE_VER=$1;;
****Can you stick a comment above this parameter saying it is a hidden
argument and what it is for? It might even be better to use a long
option since we don't really care who has to type it- it is better to
be descriptive and this way we aren't using up one of our few
remaining short options.

 		# BEGIN DEPRECATED
 		-S|--usesudo)
@@ -1255,12 +1324,15 @@
 	fi
 fi

-# Run the bear minimum in fakeroot
+devel_check
+
+# Run the bare minimum in fakeroot
 # fix flyspray bug 6208 -- using makepkg with fakeroot gives an error
 if [ "$INFAKEROOT" = "1" ]; then
 	if [ "$REPKG" = "1" ]; then
 		warning "$(gettext "Skipping build.")"
 	else
+		devel_update
 		run_build
 		tidy_install
 	fi
@@ -1359,6 +1431,7 @@
 		if [ "$REPKG" = "1" ]; then
 			warning "$(gettext "Skipping build.")"
 		else
+			devel_update
 			run_build
 			tidy_install
 		fi
@@ -1368,7 +1441,11 @@
 		msg "$(gettext "Entering fakeroot environment...")"
 		cd "$startdir"

-		fakeroot -- $0 -F $ARGLIST || exit $?
+		if [ "$newpkgver" != "" ]; then
+			fakeroot -- $0 -z $newpkgver -F $ARGLIST || exit $?
+		else
+			fakeroot -- $0 -F $ARGLIST || exit $?
+		fi
 	fi

 	create_xdelta "$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"




More information about the pacman-dev mailing list