[PATCH 1 of 6] buildrpm: build from working dir parent and use hg version for RPM versioning

Gilles Moris gilles.moris at free.fr
Mon Nov 9 03:21:42 CST 2009


 contrib/buildrpm |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)


# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1257495989 -3600
# Node ID 244a4475d7800c164d86c68056848185792f0dfc
# Parent  fd4be646d28f31ea0e0bcf5333db728bcc91c2f8
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.

diff --git a/contrib/buildrpm b/contrib/buildrpm
--- a/contrib/buildrpm
+++ b/contrib/buildrpm
@@ -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


More information about the Mercurial-devel mailing list