buildrpm: build from working dir parent and use hg version for RPM versioning
authorGilles Moris <gilles.moris@free.fr>
Fri, 06 Nov 2009 09:26:29 +0100
changeset 9809 ce145bf2ca5e
parent 9808 0d65e191ac4c
child 9810 326a0a6453a3
buildrpm: build from working dir parent and use hg version for RPM versioning Previous, RPMs was always built from tip, and the release number did not match the 'hg version' put in place for 1.4. This will enable also to this script to be able to build official tag and not only nightly build.
contrib/buildrpm
--- a/contrib/buildrpm	Mon Nov 09 23:47:24 2009 +0100
+++ b/contrib/buildrpm	Fri Nov 06 09:26:29 2009 +0100
@@ -26,7 +26,7 @@
 cd "$root"
 rm -rf $rpmdir
 mkdir -p $rpmdir/RPMS
-$HG clone "$root" $rpmdir/BUILD
+$HG clone -u . "$root" $rpmdir/BUILD
 
 if [ ! -f $specfile ]; then
     echo "Cannot find $specfile!" 1>&2
@@ -34,11 +34,19 @@
 fi
 
 tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
-# Use the most recent tag as the version.
-version=`$HG tags | python -c 'import sys; print [l for l in sys.stdin.readlines() if l[0].isdigit()][0].split()[0]'`
-# Compute the release number as the difference in revision numbers
-# between the tip and the most recent tag.
-release=`$HG tags | python -c 'import sys; l = sys.stdin.readlines(); print int(l[0].split()[1].split(":")[0]) - int([x for x in l if x[0].isdigit()][0].split()[1].split(":")[0])'`
+# make setup.py build the version string
+python setup.py build_py -c -d .
+hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`
+
+if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
+    # nightly build case, version is like 1.3.1+250-20b91f91f9ca
+    version=`echo $hgversion | cut -d- -f1`
+    release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
+else
+    # official tag, version is like 1.3.1
+    version=`echo $hgversion | sed -e 's/+.*//'`
+    release='0'
+fi
 tip=`$HG -q tip`
 
 # Beat up the spec file