contrib/buildrpm
author Gilles Moris <gilles.moris@free.fr>
Fri, 06 Nov 2009 09:26:29 +0100
changeset 9809 ce145bf2ca5e
parent 8906 bb255fe7c27e
child 9810 326a0a6453a3
permissions -rwxr-xr-x
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.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     1
#!/bin/sh
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     2
#
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     3
# Build a Mercurial RPM in place.
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     4
#
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
     5
# Bryan O'Sullivan <bos@serpentine.com>
8867
ff817723280a contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents: 7431
diff changeset
     6
#
ff817723280a contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents: 7431
diff changeset
     7
# Tested on
ff817723280a contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents: 7431
diff changeset
     8
# - Fedora 10
ff817723280a contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents: 7431
diff changeset
     9
# - Fedora 11
ff817723280a contrib/buildrpm: Support python 2.4 and 2.6
Mads Kiilerich <mads@kiilerich.com>
parents: 7431
diff changeset
    10
# - Centos 5.3 (with Fedora EPEL repo for asciidoc)
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    11
8869
d244ee52ac30 contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents: 8868
diff changeset
    12
HG="`dirname $0`/../hg"
d244ee52ac30 contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents: 8868
diff changeset
    13
PYTHONPATH="`dirname $0`/../mercurial/pure"
d244ee52ac30 contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents: 8868
diff changeset
    14
export PYTHONPATH
7431
3d827cc616b6 buildrpm: complain when hg command isn't available
Mads Kiilerich <mads@kiilerich.com>
parents: 7277
diff changeset
    15
8869
d244ee52ac30 contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents: 8868
diff changeset
    16
root="`$HG root 2>/dev/null`"
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    17
specfile=contrib/mercurial.spec
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    18
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    19
if [ -z "$root" ]; then
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    20
    echo 'You are not inside a Mercurial repository!' 1>&2
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    21
    exit 1
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    22
fi
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    23
7277
3e000e2bf5f6 Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents: 4755
diff changeset
    24
rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    25
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    26
cd "$root"
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    27
rm -rf $rpmdir
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    28
mkdir -p $rpmdir/RPMS
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
    29
$HG clone -u . "$root" $rpmdir/BUILD
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    30
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    31
if [ ! -f $specfile ]; then
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    32
    echo "Cannot find $specfile!" 1>&2
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    33
    exit 1
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    34
fi
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    35
7277
3e000e2bf5f6 Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents: 4755
diff changeset
    36
tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
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
    37
# make setup.py build the version string
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    38
python setup.py build_py -c -d .
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    39
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
    40
ce145bf2ca5e buildrpm: build from working dir parent and use hg version for RPM versioning
Gilles Moris <gilles.moris@free.fr>
parents: 8906
diff changeset
    41
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
    42
    # 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
    43
    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
    44
    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
    45
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
    46
    # 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
    47
    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
    48
    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
    49
fi
8869
d244ee52ac30 contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents: 8868
diff changeset
    50
tip=`$HG -q tip`
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    51
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    52
# Beat up the spec file
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    53
sed -e 's,^Source:.*,Source: /dev/null,' \
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    54
    -e "s,^Version:.*,Version: $version," \
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    55
    -e "s,^Release:.*,Release: $release," \
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    56
    -e "s,^%prep.*,Changeset: $tip\n\0," \
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    57
    -e 's,^%setup.*,,' \
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    58
    $specfile > $tmpspec
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    59
4754
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    60
cat <<EOF >> $tmpspec
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    61
%changelog
8906
bb255fe7c27e contrib/buildrpm: force en_US locale during changelog's creation
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents: 8869
diff changeset
    62
* `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release
4754
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    63
- Automatically built via $0
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    64
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    65
EOF
8869
d244ee52ac30 contrib/buildrpm: Don't require installed hg, use local hg with pure extensions
Mads Kiilerich <mads@kiilerich.com>
parents: 8868
diff changeset
    66
$HG log \
4754
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    67
     --template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    68
     .hgtags \
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    69
  | sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    70
        -e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    71
   >> $tmpspec
e5e6dd8ba6bb buildrpm: auto-generate %changelog in .spec file
Adam Spiers <hg@adamspiers.org>
parents: 564
diff changeset
    72
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    73
rpmbuild --define "_topdir $rpmdir" -bb $tmpspec
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    74
if [ $? = 0 ]; then
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    75
    rm -rf $tmpspec $rpmdir/BUILD
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    76
    mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    77
    echo
7277
3e000e2bf5f6 Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents: 4755
diff changeset
    78
    echo "Packages are in $rpmdir:"
3e000e2bf5f6 Make contrib/buildrpm work on Fedora 9.
Mads Kiilerich <mads@kiilerich.com>
parents: 4755
diff changeset
    79
    ls -l $rpmdir/*.rpm
564
ced5f5ceb172 [PATCH] Add contrib/buildrpm script
mpm@selenic.com
parents:
diff changeset
    80
fi