contrib/buildrpm
author Mads Kiilerich <madski@unity3d.com>
Sun, 31 Aug 2014 12:51:06 +0200
changeset 22435 4c4385eb26bc
parent 21641 977e5bd6eb76
child 22436 96d95b75a63b
permissions -rwxr-xr-x
buildrpm: introduce --prepare for preparing without actually building rpms
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
22435
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    10
BUILD=1
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    11
while [ "$1" ]; do
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    12
    case "$1" in
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    13
    --prepare )
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    14
        shift
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    15
        BUILD=
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    16
        ;;
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    17
    * )
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    18
        echo "Invalid parameter $1!" 1>&2
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    19
        exit 1
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    20
        ;;
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    21
    esac
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    22
done
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
    23
9811
c92ac5a56f69 buildrpm: enable to start the script from anywhere
Gilles Moris <gilles.moris@free.fr>
parents: 9810
diff changeset
    24
cd "`dirname $0`/.."
7431
3d827cc616b6 buildrpm: complain when hg command isn't available
Mads Kiilerich <mads@kiilerich.com>
parents: 7277
diff changeset
    25
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    26
specfile=contrib/mercurial.spec
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    27
if [ ! -f $specfile ]; then
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    28
    echo "Cannot find $specfile!" 1>&2
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    29
    exit 1
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    30
fi
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    31
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    32
if [ ! -d .hg ]; then
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    33
    echo 'You are not inside a Mercurial repository!' 1>&2
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    34
    exit 1
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    35
fi
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    36
21639
57e0f053e529 buildrpm: collect code for building local hg and using it in one place
Mads Kiilerich <madski@unity3d.com>
parents: 21638
diff changeset
    37
# 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
    38
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
    39
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
    40
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
    41
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
    42
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    43
rpmdir="$PWD/rpmbuild"
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    44
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    45
rm -rf $rpmdir
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    46
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
    47
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
    48
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
    49
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
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
    51
    # 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
    52
    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
    53
    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
    54
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
    55
    # 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
    56
    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
    57
    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
    58
fi
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    59
21641
977e5bd6eb76 buildrpm: include release version in .tar.gz name
Mads Kiilerich <madski@unity3d.com>
parents: 21640
diff changeset
    60
$HG archive -t tgz $rpmdir/SOURCES/mercurial-$version-$release.tar.gz
977e5bd6eb76 buildrpm: include release version in .tar.gz name
Mads Kiilerich <madski@unity3d.com>
parents: 21640
diff changeset
    61
rpmspec=$rpmdir/SPECS/mercurial.spec
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    62
9812
dd2c95fc4fe5 buildrpm: cleanup script
Gilles Moris <gilles.moris@free.fr>
parents: 9811
diff changeset
    63
sed -e "s,^Version:.*,Version: $version," \
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    64
    -e "s,^Release:.*,Release: $release," \
9813
2059795bb5d0 buildrpm: build full RPM package including sources
Gilles Moris <gilles.moris@free.fr>
parents: 9812
diff changeset
    65
    $specfile > $rpmspec
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    66
9814
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    67
echo >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    68
echo "%changelog" >> $rpmspec
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
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
    71
    latesttag="`echo $version | sed -e 's/+.*//'`"
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    72
    $HG log -r .:"$latesttag" -fM \
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    73
        --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
    74
import sys, time
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    75
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    76
def datestr(date, format):
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    77
    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
    78
9814
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    79
changelog = []
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    80
for l in sys.stdin.readlines():
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    81
    tok = l.split("\t")
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    82
    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
    83
    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
    84
prevtitle = ""
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    85
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
    86
    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
    87
    if prevtitle != title:
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    88
        prevtitle = title
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    89
        print
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    90
        print title
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    91
    print "- %s" % l[3].strip()
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    92
' >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    93
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    94
else
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    95
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    96
    $HG log \
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    97
         --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
    98
         .hgtags | python -c '
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
    99
import sys, time
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   100
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   101
def datestr(date, format):
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   102
    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
   103
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   104
for l in sys.stdin.readlines():
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   105
    tok = l.split("\t")
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   106
    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
   107
    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
   108
' >> $rpmspec
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   109
5070e4d57276 buildrpm: enhance changelog of the RPM file
Gilles Moris <gilles.moris@free.fr>
parents: 9813
diff changeset
   110
fi
4754
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
   111
22435
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   112
if [ "$BUILD" ]; then
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   113
    rpmbuild --define "_topdir $rpmdir" -ba $rpmspec --clean
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   114
    if [ $? = 0 ]; then
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   115
        echo
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   116
        echo "Built packages for $version-$release:"
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   117
        find $rpmdir/*RPMS/ -type f -newer $rpmspec
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   118
    fi
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   119
else
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   120
    echo "Prepared sources for $version-$release $rpmspec are in $rpmdir/SOURCES/ - use like:"
4c4385eb26bc buildrpm: introduce --prepare for preparing without actually building rpms
Mads Kiilerich <madski@unity3d.com>
parents: 21641
diff changeset
   121
    echo "rpmbuild --define '_topdir $rpmdir' -ba $rpmspec --clean"
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
   122
fi