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

Scott Horowitz stonecrest at gmail.com
Fri Oct 26 15:12:47 EDT 2007


I personally found it silly to have separate scripts for makepkg and
versionpkg. I've seen countless messages on AUR where people ask for
-svn PKGBUILDS to be updated because their pkgver is out of date, etc.
Many people don't know about versionpkg and, even if you do, it makes
sense to have a single script that handles both.

Please look at the patch carefully because I am by no means a shell
scripting expert. I tested it with mpd-svn and mpd PKGBUILDS; both
worked fine but that hardly means everything is perfect.

Also, this removes the --check-only and --modify-only arguments that
the standalone versionpkg script accepted. I guess there's no reason
these can't be added back in, but they seem a little useless to me
(and their short arguments, -c and -m, are already used by makepkg for
other purposes).

Scott

--- /usr/bin/makepkg    2007-09-16 16:33:23.000000000 -0600
+++ /usr/bin/makepkg2   2007-10-26 13:07:52.000000000 -0600
@@ -34,6 +34,8 @@
 source "/etc/abs/abs.conf"
 SRCROOT="$ABSROOT"

+FORCE_VER=""
+
 # Options
 CLEANUP=0
 CLEANCACHE=0
@@ -106,6 +108,10 @@
        echo "$1" | sed 's|^.*://.*/||g'
 }

+update_pb() {
+       sed -i "1,11 s/pkgver=[^ ]*/pkgver=$1/" ./$BUILDSCRIPT
+}
+
 # checks to see if options are present in makepkg.conf or PKGBUILD;
 #   PKGBUILD options always take precedence
 check_option() {
@@ -457,7 +463,7 @@
                                        exit 1
                                        ;;
                -*)
-               while getopts "bcCdefghiLmop:rRsS-" opt; do
+               while getopts "bcCdefghiLmopz:rRsS-" opt; do
                        case $opt in
                                b) DEP_SRC=1 ;;
                                c) CLEANUP=1 ;;
@@ -479,6 +485,7 @@
                                R) REPKG=1 ;;
                                s) DEP_BIN=1 ;;
                                S) SUDO=1 ;;
+                               z) FORCE_VER=$OPTARG ;;
                                -)
                                                OPTIND=0
                                                break
@@ -592,6 +599,67 @@
        fi
 fi

+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 "determining latest darcs revision... \c"
+               newpkgver=$(date +%Y%m%d)
+               echo $newpkgver
+       elif [ ! -z ${_cvsroot} ] && [ ! -z ${_cvsmod} ] ; then
+               msg "determining latest cvs revision... \c"
+               newpkgver=$(date +%Y%m%d)
+               echo $newpkgver
+       elif [ ! -z ${_gitroot} ] && [ ! -z ${_gitname} ] ; then
+               msg "determining latest git revision... \c"
+               newpkgver=$(date +%Y%m%d)
+               echo $newpkgver
+       elif [ ! -z ${_svntrunk} ] && [ ! -z ${_svnmod} ] ; then
+               msg "retrieving latest revision number from svn... \c"
+               newpkgver=$(svn log $_svntrunk --limit 1 | sed -n
's/^r\([^ ]*\) .*$/\1/p')
+               echo "$newpkgver"
+       elif [ ! -z ${_bzrtrunk} ] && [ ! -z ${_bzrmod} ] ; then
+           msg "retrieving latest revision number from bzr... \c"
+           newpkgver=$(bzr revno ${_bzrtrunk})
+           echo "$newpkgver"
+       elif [ ! -z ${_hgroot} ] && [ ! -z ${_hgrepo} ] ; then
+               if [ -d ./src/$_hgrepo ] ; then
+                       msg "retrieving latest revision number from hg... \c"
+                       cd ./src/$_hgrepo
+                       make clean
+                       hg pull
+                       hg update
+               else
+                       msg "determining latest hg revision... \c"
+                       [[ ! -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')
+               echo "$newpkgver"
+               cd ../../
+       fi
+
+       if [ "$newpkgver" != "$oldpkgver" ]; then
+               msg "newer revision detected: $newpkgver"
+       elif [ "$newpkgver" != "" ]; then
+               warning "PKGBUILD pkgver is $oldpkgver, no newer
revision available"
+               if [ "$FORCE" = "1" ]; then
+                       msg "forcing pkgver to $newpkgver... "
+               else
+                       error "exiting now, use makepkg -f to force update"
+                       exit 1
+               fi
+       fi
+else
+       # Version number retrieved from fakeroot->makepkg argument
+       newpkgver=$FORCE_VER
+fi
+
 # Enter the fakeroot environment if necessary.  This will call the makepkg
 # script again as the fake root user.  We detect this by passing a sentinel
 # option (-F) to makepkg.
@@ -599,7 +667,11 @@
        if [ "$(check_buildenv fakeroot)" = "y" ]; then
                if [ $(type -p fakeroot) ]; then
                        msg "Entering fakeroot environment"
-                       fakeroot -- $0 -F $ARGLIST
+                       if [ "$newpkgver" != "" ]; then
+                               fakeroot -- $0 -F $ARGLIST -z $newpkgver
+                       else
+                               fakeroot -- $0 -F $ARGLIST
+                       fi
                        exit $?
                else
                        warning "Fakeroot is not installed. Building
as an unprivileged user"
@@ -617,6 +689,18 @@
        fi
 fi

+# This is lame, but if we're wanting to use an updated pkgver for
+# retrieving svn/cvs/etc sources, we'll update the PKGBUILD, re-source
+# it, and then revert it
+if [ "$newpkgver" != "" ]; then
+       if [ "newpkgver" != "$pkgver" ]; then
+               oldpkgver=$pkgver
+               update_pb $newpkgver
+               source $BUILDSCRIPT
+               update_pb $oldpkgver
+       fi
+fi
+
 msg "Making package: $pkgname $pkgver-$pkgrel ($(date))"

 # fix flyspray bug #5973




More information about the pacman-dev mailing list