contrib/buildrpm
author Mads Kiilerich <madski@unity3d.com>
Thu, 15 May 2014 01:48:37 +0200
changeset 21639 57e0f053e529
parent 21638 5337cb17fa1f
child 21640 4bfb721de6dd
permissions -rwxr-xr-x
buildrpm: collect code for building local hg and using it in one place
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21638
5337cb17fa1f buildrpm: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 9814
diff changeset
     1
#!/bin/sh -e
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     2
#
21638
5337cb17fa1f buildrpm: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 9814
diff changeset
     3
# Build a Mercurial RPM from the current repo
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     4
#
8867
ff817723280a contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents: 7431
diff changeset
     5
# Tested on
21638
5337cb17fa1f buildrpm: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 9814
diff changeset
     6
# - Fedora 20
5337cb17fa1f buildrpm: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 9814
diff changeset
     7
# - CentOS 5
5337cb17fa1f buildrpm: various minor cleanup
Mads Kiilerich <madski@unity3d.com>
parents: 9814
diff changeset
     8
# - centOS 6
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     9
9811
c92ac5a56f69 buildrpm: enable to start the script from anywhere
Gilles Moris <gilles.moris@free.fr>
parents: 9810
diff changeset
    10
cd "`dirname $0`/.."
7431
3d827cc616b6 buildrpm: complain when hg command isn't available
Mads Kiilerich <mads@kiilerich.com>
parents: 7277
diff changeset
    11
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    12
specfile=contrib/mercurial.spec
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    13
if [ ! -f $specfile ]; then
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    14
    echo "Cannot find $specfile!" 1>&2
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    15
    exit 1
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    16
fi
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    17
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    18
if [ ! -d .hg ]; then
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    19
    echo 'You are not inside a Mercurial repository!' 1>&2
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    20
    exit 1
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    21
fi
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    22
9810
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    23
if $HG id -i | grep '+$' > /dev/null 2>&1; then
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    24
    echo -n "Your local changes will NOT be in the RPM. Continue [y/n] ? "
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    25
    read answer
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    26
    if echo $answer | grep -iv '^y'; then
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    27
        exit
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    28
    fi
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    29
fi
326a0a6453a3 buildrpm: warn if there is outstanding uncommitted changes
Gilles Moris <gilles.moris@free.fr>
parents: 9809
diff changeset
    30
21639
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    31
# build local hg and use it
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    32
python setup.py build_py -c -d .
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    33
HG="$PWD/hg"
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    34
PYTHONPATH="$PWD/mercurial/pure"
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    35
export PYTHONPATH
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    36
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    37
rpmdir="$PWD/rpmbuild"
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    38
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    39
rm -rf $rpmdir
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    40
mkdir -p $rpmdir/SOURCES $rpmdir/SPECS $rpmdir/RPMS $rpmdir/SRPMS $rpmdir/BUILD
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    41
9809
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    42
hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    43
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    44
if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    45
    # nightly build case, version is like 1.3.1+250-20b91f91f9ca
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    46
    version=`echo $hgversion | cut -d- -f1`
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    47
    release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    48
else
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    49
    # official tag, version is like 1.3.1
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    50
    version=`echo $hgversion | sed -e 's/+.*//'`
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    51
    release='0'
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    52
fi
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    53
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    54
$HG archive -t tgz $rpmdir/SOURCES/mercurial-$version.tar.gz
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    55
rpmspec=$rpmdir/SPECS/mercurial-$version.spec
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    56
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    57
sed -e "s,^Version:.*,Version: $version," \
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    58
    -e "s,^Release:.*,Release: $release," \
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    59
    $specfile > $rpmspec
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    60
9814
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    61
echo >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    62
echo "%changelog" >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    63
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    64
if echo $version | grep '+' > /dev/null 2>&1; then
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    65
    latesttag="`echo $version | sed -e 's/+.*//'`"
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    66
    $HG log -r .:"$latesttag" -fM \
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    67
        --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    68
import sys, time
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    69
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    70
def datestr(date, format):
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    71
    return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
4754
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    72
9814
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    73
changelog = []
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    74
for l in sys.stdin.readlines():
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    75
    tok = l.split("\t")
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    76
    hgdate = tuple(int(v) for v in tok[0].split())
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    77
    changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    78
prevtitle = ""
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    79
for l in sorted(changelog, reverse=True):
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    80
    title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    81
    if prevtitle != title:
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    82
        prevtitle = title
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    83
        print
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    84
        print title
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    85
    print "- %s" % l[3].strip()
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    86
' >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    87
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    88
else
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    89
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    90
    $HG log \
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    91
         --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    92
         .hgtags | python -c '
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    93
import sys, time
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    94
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    95
def datestr(date, format):
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    96
    return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    97
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    98
for l in sys.stdin.readlines():
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    99
    tok = l.split("\t")
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   100
    hgdate = tuple(int(v) for v in tok[0].split())
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   101
    print "* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2])
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   102
' >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   103
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   104
fi
4754
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
   105
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
   106
rpmbuild --define "_topdir $rpmdir" -ba $rpmspec --clean
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
   107
if [ $? = 0 ]; then
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
   108
    echo
7277
3e000e2bf5f6 Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents: 4755
diff changeset
   109
    echo "Packages are in $rpmdir:"
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
   110
    ls -l $rpmdir/*RPMS/*
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
   111
fi