##// END OF EJS Templates
packaging: rework version detection and declaration (issue4912)...
Augie Fackler -
r26833:6474b640 stable
parent child Browse files
Show More
@@ -1,84 +1,91 b''
1 1 #!/bin/sh -e
2 2 #
3 3 # Build a Mercurial debian package from the current repo
4 4 #
5 5 # Tested on Jessie (stable as of original script authoring.)
6 6
7 7 . $(dirname $0)/packagelib.sh
8 8
9 9 BUILD=1
10 10 CLEANUP=1
11 11 DEBVERSION=jessie
12 12 while [ "$1" ]; do
13 13 case "$1" in
14 14 --release )
15 15 shift
16 16 DEBVERSION="$1"
17 17 shift
18 18 ;;
19 19 --cleanup )
20 20 shift
21 21 BUILD=
22 22 ;;
23 23 --build )
24 24 shift
25 25 CLEANUP=
26 26 ;;
27 27 --debbuilddir )
28 28 shift
29 29 DEBBUILDDIR="$1"
30 30 shift
31 31 ;;
32 32 * )
33 33 echo "Invalid parameter $1!" 1>&2
34 34 exit 1
35 35 ;;
36 36 esac
37 37 done
38 38
39 39 trap "if [ '$CLEANUP' ] ; then rm -r '$PWD/debian' ; fi" EXIT
40 40
41 41 set -u
42 42
43 43 if [ ! -d .hg ]; then
44 44 echo 'You are not inside a Mercurial repository!' 1>&2
45 45 exit 1
46 46 fi
47 47
48 48 gethgversion
49 debver="$version"
50 if [ -n "$type" ] ; then
51 debver="$debver~$type"
52 fi
53 if [ -n "$distance" ] ; then
54 debver="$debver+$distance-$node"
55 fi
49 56
50 57 control=debian/control
51 58 changelog=debian/changelog
52 59
53 60 if [ "$BUILD" ]; then
54 61 if [ -d debian ] ; then
55 62 echo "Error! debian control directory already exists!"
56 63 exit 1
57 64 fi
58 65
59 66 cp -r $PWD/contrib/debian debian
60 67 chmod -R 0755 debian
61 68
62 69 # This looks like sed -i, but sed -i behaves just differently enough
63 70 # between BSD and GNU sed that I gave up and did the dumb thing.
64 sed "s/__VERSION__/$version/" < $changelog > $changelog.tmp
71 sed "s/__VERSION__/$debver/" < $changelog > $changelog.tmp
65 72 date=$(date --rfc-2822)
66 73 sed "s/__DATE__/$date/" < $changelog.tmp > $changelog
67 74 rm $changelog.tmp
68 75
69 76 debuild -us -uc -b
70 77 if [ $? != 0 ]; then
71 78 echo 'debuild failed!'
72 79 exit 1
73 80 fi
74 81
75 82 fi
76 83 if [ "$CLEANUP" ] ; then
77 84 echo
78 85 OUTPUTDIR=${OUTPUTDIR:=packages/debian-$DEBVERSION}
79 86 find ../mercurial*.deb ../mercurial_*.build ../mercurial_*.changes \
80 87 -type f -newer $control -print0 | \
81 88 xargs -Inarf -0 mv narf "$OUTPUTDIR"
82 echo "Built packages for $version-$release:"
89 echo "Built packages for $debver:"
83 90 find "$OUTPUTDIR" -type f -newer $control -name '*.deb'
84 91 fi
@@ -1,149 +1,161 b''
1 1 #!/bin/sh -e
2 2 #
3 3 # Build a Mercurial RPM from the current repo
4 4 #
5 5 # Tested on
6 6 # - Fedora 20
7 7 # - CentOS 5
8 8 # - centOS 6
9 9
10 10 . $(dirname $0)/packagelib.sh
11 11
12 12 BUILD=1
13 13 RPMBUILDDIR="$PWD/rpmbuild"
14 14 while [ "$1" ]; do
15 15 case "$1" in
16 16 --prepare )
17 17 shift
18 18 BUILD=
19 19 ;;
20 20 --withpython | --with-python)
21 21 shift
22 22 PYTHONVER=2.7.10
23 23 PYTHONMD5=d7547558fd673bd9d38e2108c6b42521
24 24 ;;
25 25 --rpmbuilddir )
26 26 shift
27 27 RPMBUILDDIR="$1"
28 28 shift
29 29 ;;
30 30 * )
31 31 echo "Invalid parameter $1!" 1>&2
32 32 exit 1
33 33 ;;
34 34 esac
35 35 done
36 36
37 37 cd "`dirname $0`/.."
38 38
39 39 specfile=$PWD/contrib/mercurial.spec
40 40 if [ ! -f $specfile ]; then
41 41 echo "Cannot find $specfile!" 1>&2
42 42 exit 1
43 43 fi
44 44
45 45 if [ ! -d .hg ]; then
46 46 echo 'You are not inside a Mercurial repository!' 1>&2
47 47 exit 1
48 48 fi
49 49
50 50 gethgversion
51 51
52 # TODO: handle distance/node set, and type set
53
54 if [ -z "$type" ] ; then
55 release=1
56 else
57 release=0.9_$type
58 fi
59
60 if [ -n "$distance" ] ; then
61 release=$release+$distance_$node
62 fi
63
52 64 if [ "$PYTHONVER" ]; then
53 65 release=$release+$PYTHONVER
54 66 RPMPYTHONVER=$PYTHONVER
55 67 else
56 68 RPMPYTHONVER=%{nil}
57 69 fi
58 70
59 71 mkdir -p $RPMBUILDDIR/SOURCES
60 72 $HG archive -t tgz $RPMBUILDDIR/SOURCES/mercurial-$version-$release.tar.gz
61 73 if [ "$PYTHONVER" ]; then
62 74 (
63 75 mkdir -p build
64 76 cd build
65 77 PYTHON_SRCFILE=Python-$PYTHONVER.tgz
66 78 [ -f $PYTHON_SRCFILE ] || curl -Lo $PYTHON_SRCFILE http://www.python.org/ftp/python/$PYTHONVER/$PYTHON_SRCFILE
67 79 if [ "$PYTHONMD5" ]; then
68 80 echo "$PYTHONMD5 $PYTHON_SRCFILE" | md5sum -w -c
69 81 fi
70 82 ln -f $PYTHON_SRCFILE $RPMBUILDDIR/SOURCES/$PYTHON_SRCFILE
71 83
72 84 DOCUTILSVER=`sed -ne "s/^%global docutilsname docutils-//p" $specfile`
73 85 DOCUTILS_SRCFILE=docutils-$DOCUTILSVER.tar.gz
74 86 [ -f $DOCUTILS_SRCFILE ] || curl -Lo $DOCUTILS_SRCFILE http://downloads.sourceforge.net/project/docutils/docutils/$DOCUTILSVER/$DOCUTILS_SRCFILE
75 87 DOCUTILSMD5=`sed -ne "s/^%global docutilsmd5 //p" $specfile`
76 88 if [ "$DOCUTILSMD5" ]; then
77 89 echo "$DOCUTILSMD5 $DOCUTILS_SRCFILE" | md5sum -w -c
78 90 fi
79 91 ln -f $DOCUTILS_SRCFILE $RPMBUILDDIR/SOURCES/$DOCUTILS_SRCFILE
80 92 )
81 93 fi
82 94
83 95 mkdir -p $RPMBUILDDIR/SPECS
84 96 rpmspec=$RPMBUILDDIR/SPECS/mercurial.spec
85 97
86 98 sed -e "s,^Version:.*,Version: $version," \
87 99 -e "s,^Release:.*,Release: $release," \
88 100 $specfile > $rpmspec
89 101
90 102 echo >> $rpmspec
91 103 echo "%changelog" >> $rpmspec
92 104
93 105 if echo $version | grep '+' > /dev/null 2>&1; then
94 106 latesttag="`echo $version | sed -e 's/+.*//'`"
95 107 $HG log -r .:"$latesttag" -fM \
96 108 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
97 109 import sys, time
98 110
99 111 def datestr(date, format):
100 112 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
101 113
102 114 changelog = []
103 115 for l in sys.stdin.readlines():
104 116 tok = l.split("\t")
105 117 hgdate = tuple(int(v) for v in tok[0].split())
106 118 changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
107 119 prevtitle = ""
108 120 for l in sorted(changelog, reverse=True):
109 121 title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
110 122 if prevtitle != title:
111 123 prevtitle = title
112 124 print
113 125 print title
114 126 print "- %s" % l[3].strip()
115 127 ' >> $rpmspec
116 128
117 129 else
118 130
119 131 $HG log \
120 132 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
121 133 .hgtags | python -c '
122 134 import sys, time
123 135
124 136 def datestr(date, format):
125 137 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
126 138
127 139 for l in sys.stdin.readlines():
128 140 tok = l.split("\t")
129 141 hgdate = tuple(int(v) for v in tok[0].split())
130 142 print "* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2])
131 143 ' >> $rpmspec
132 144
133 145 fi
134 146
135 147 sed -i \
136 148 -e "s/^%define withpython.*$/%define withpython $RPMPYTHONVER/" \
137 149 $rpmspec
138 150
139 151 if [ "$BUILD" ]; then
140 152 rpmbuild --define "_topdir $RPMBUILDDIR" -ba $rpmspec --clean
141 153 if [ $? = 0 ]; then
142 154 echo
143 155 echo "Built packages for $version-$release:"
144 156 find $RPMBUILDDIR/*RPMS/ -type f -newer $rpmspec
145 157 fi
146 158 else
147 159 echo "Prepared sources for $version-$release $rpmspec are in $RPMBUILDDIR/SOURCES/ - use like:"
148 160 echo "rpmbuild --define '_topdir $RPMBUILDDIR' -ba $rpmspec --clean"
149 161 fi
@@ -1,19 +1,35 b''
1 # Extract version number into 4 parts, some of which may be empty:
2 #
3 # version: the numeric part of the most recent tag. Will always look like 1.3.
4 #
5 # type: if an rc build, "rc", otherwise empty
6 #
7 # distance: the distance from the nearest tag, or empty if built from a tag
8 #
9 # node: the node|short hg was built from, or empty if built from a tag
1 10 gethgversion() {
2 11 make clean
3 12 make local || make local PURE=--pure
4 13 HG="$PWD/hg"
5 14
6 15 $HG version > /dev/null || { echo 'abort: hg version failed!'; exit 1 ; }
7 16
8 17 hgversion=`$HG version | sed -ne 's/.*(version \(.*\))$/\1/p'`
9 18
19 if echo $hgversion | grep + > /dev/null 2>&1 ; then
20 tmp=`echo $hgversion | cut -d+ -f 2`
21 hgversion=`echo $hgversion | cut -d+ -f 1`
22 distance=`echo $tmp | cut -d- -f 1`
23 node=`echo $tmp | cut -d- -f 2`
24 else
25 distance=''
26 node=''
27 fi
10 28 if echo $hgversion | grep -- '-' > /dev/null 2>&1; then
11 # nightly build case, version is like 1.3.1+250-20b91f91f9ca
12 29 version=`echo $hgversion | cut -d- -f1`
13 release=`echo $hgversion | cut -d- -f2 | sed -e 's/+.*//'`
30 type=`echo $hgversion | cut -d- -f2`
14 31 else
15 # official tag, version is like 1.3.1
16 version=`echo $hgversion | sed -e 's/+.*//'`
17 release='0'
32 version=$hgversion
33 type=''
18 34 fi
19 35 }
General Comments 0
You need to be logged in to leave comments. Login now