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