contrib/buildrpm
author Yuya Nishihara <yuya@tcha.org>
Thu, 22 May 2014 22:05:26 +0900
branchstable
changeset 21543 21b3513d43e4
parent 9814 5070e4d57276
child 21638 5337cb17fa1f
permissions -rwxr-xr-x
proxy: remove unneeded _set_hostport for compatibility with Python 2.7.7rc1 With Python 2.7.7rc1, "hg pull" through HTTP CONNECT tunnel fails due to the removal of _set_hostport [1]. ... File "mercurial/url.py", line 372, in https_open return self.do_open(self._makeconnection, req) ... File "mercurial/url.py", line 342, in connect _generic_proxytunnel(self) File "mercurial/url.py", line 228, in _generic_proxytunnel self._set_hostport(self.host, self.port) AttributeError: httpsconnection instance has no attribute '_set_hostport' self._set_hostport(self.host, self.port) should be noop and can be removed because: - _set_hostport() [2] was the function to parse "host:port" string and set them to self.host and self.port, - and (self.host, self.port) pair should be valid since connect() is called prior to _generic_proxytunnel(). [1]: http://hg.python.org/cpython/rev/568041fd8090 [2]: http://hg.python.org/cpython/file/3a1db0d2747e/Lib/httplib.py#l721

#!/bin/sh
#
# Build a Mercurial RPM in place.
#
# Tested on
# - Fedora 8 (with docutils 0.5)
# - Fedora 11
# - OpenSuse 11.2

cd "`dirname $0`/.."
HG="$PWD/hg"
PYTHONPATH="$PWD/mercurial/pure"
export PYTHONPATH

specfile=contrib/mercurial.spec
if [ ! -f $specfile ]; then
    echo "Cannot find $specfile!" 1>&2
    exit 1
fi

if [ ! -d .hg ]; then
    echo 'You are not inside a Mercurial repository!' 1>&2
    exit 1
fi

if $HG id -i | grep '+$' > /dev/null 2>&1; then
    echo -n "Your local changes will NOT be in the RPM. Continue [y/n] ? "
    read answer
    if echo $answer | grep -iv '^y'; then
        exit
    fi
fi

rpmdir="$PWD/rpmbuild"

rm -rf $rpmdir
mkdir -p $rpmdir/SOURCES $rpmdir/SPECS $rpmdir/RPMS $rpmdir/SRPMS $rpmdir/BUILD

# 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

$HG archive -t tgz $rpmdir/SOURCES/mercurial-$version.tar.gz
rpmspec=$rpmdir/SPECS/mercurial-$version.spec

sed -e "s,^Version:.*,Version: $version," \
    -e "s,^Release:.*,Release: $release," \
    $specfile > $rpmspec

echo >> $rpmspec
echo "%changelog" >> $rpmspec

if echo $version | grep '+' > /dev/null 2>&1; then
    latesttag="`echo $version | sed -e 's/+.*//'`"
    $HG log -r .:"$latesttag" -fM \
        --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
import sys, time

def datestr(date, format):
    return time.strftime(format, time.gmtime(float(date[0]) - date[1]))

changelog = []
for l in sys.stdin.readlines():
    tok = l.split("\t")
    hgdate = tuple(int(v) for v in tok[0].split())
    changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
prevtitle = ""
for l in sorted(changelog, reverse=True):
    title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
    if prevtitle != title:
        prevtitle = title
        print
        print title
    print "- %s" % l[3].strip()
' >> $rpmspec

else

    $HG log \
         --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
         .hgtags | python -c '
import sys, time

def datestr(date, format):
    return time.strftime(format, time.gmtime(float(date[0]) - date[1]))

for l in sys.stdin.readlines():
    tok = l.split("\t")
    hgdate = tuple(int(v) for v in tok[0].split())
    print "* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2])
' >> $rpmspec

fi

rpmbuild --define "_topdir $rpmdir" -ba $rpmspec --clean
if [ $? = 0 ]; then
    echo
    echo "Packages are in $rpmdir:"
    ls -l $rpmdir/*RPMS/*
fi