##// END OF EJS Templates
packaging: introduce Python3 support as buildrpm --python3...
Mads Kiilerich -
r43650:a6dcac64 stable
parent child Browse files
Show More
@@ -1,160 +1,166 b''
1 1 #!/bin/bash -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 PYTHONEXE=python2
14 15
15 16 while [ "$1" ]; do
16 17 case "$1" in
17 18 --prepare )
18 19 shift
19 20 BUILD=
20 21 ;;
22 --python3)
23 shift
24 PYTHONEXE=python3
25 ;;
21 26 --withpython | --with-python)
22 27 shift
23 28 PYTHONVER=2.7.16
24 29 PYTHONMD5=f1a2ace631068444831d01485466ece0
25 30 ;;
26 31 --rpmbuilddir )
27 32 shift
28 33 RPMBUILDDIR="$1"
29 34 shift
30 35 ;;
31 36 * )
32 37 echo "Invalid parameter $1!" 1>&2
33 38 exit 1
34 39 ;;
35 40 esac
36 41 done
37 42
38 43 cd "`dirname $0`/../.."
39 44
40 45 specfile=$PWD/contrib/packaging/mercurial.spec
41 46 if [ ! -f $specfile ]; then
42 47 echo "Cannot find $specfile!" 1>&2
43 48 exit 1
44 49 fi
45 50
46 51 if [ ! -d .hg ]; then
47 52 echo 'You are not inside a Mercurial repository!' 1>&2
48 53 exit 1
49 54 fi
50 55
51 56 gethgversion
52 57
53 58 if [ -z "$type" ] ; then
54 59 release=1
55 60 else
56 61 release=0.9_$type
57 62 fi
58 63
59 64 if [ -n "$distance" ] ; then
60 65 release=$release+${distance}_${node}
61 66 fi
62 67
63 68 if [ "$PYTHONVER" ]; then
64 69 release=$release+$PYTHONVER
65 70 RPMPYTHONVER=$PYTHONVER
66 71 else
67 72 RPMPYTHONVER=%{nil}
68 73 fi
69 74
70 75 mkdir -p $RPMBUILDDIR/{SOURCES,BUILD,SRPMS,RPMS}
71 76 $HG archive -t tgz $RPMBUILDDIR/SOURCES/mercurial-$version-$release.tar.gz
72 77 if [ "$PYTHONVER" ]; then
73 78 (
74 79 mkdir -p build
75 80 cd build
76 81 PYTHON_SRCFILE=Python-$PYTHONVER.tgz
77 82 [ -f $PYTHON_SRCFILE ] || curl -Lo $PYTHON_SRCFILE http://www.python.org/ftp/python/$PYTHONVER/$PYTHON_SRCFILE
78 83 if [ "$PYTHONMD5" ]; then
79 84 echo "$PYTHONMD5 $PYTHON_SRCFILE" | md5sum -w -c
80 85 fi
81 86 ln -f $PYTHON_SRCFILE $RPMBUILDDIR/SOURCES/$PYTHON_SRCFILE
82 87
83 88 DOCUTILSVER=`sed -ne "s/^%global docutilsname docutils-//p" $specfile`
84 89 DOCUTILS_SRCFILE=docutils-$DOCUTILSVER.tar.gz
85 90 [ -f $DOCUTILS_SRCFILE ] || curl -Lo $DOCUTILS_SRCFILE http://downloads.sourceforge.net/project/docutils/docutils/$DOCUTILSVER/$DOCUTILS_SRCFILE
86 91 DOCUTILSMD5=`sed -ne "s/^%global docutilsmd5 //p" $specfile`
87 92 if [ "$DOCUTILSMD5" ]; then
88 93 echo "$DOCUTILSMD5 $DOCUTILS_SRCFILE" | md5sum -w -c
89 94 fi
90 95 ln -f $DOCUTILS_SRCFILE $RPMBUILDDIR/SOURCES/$DOCUTILS_SRCFILE
91 96 )
92 97 fi
93 98
94 99 mkdir -p $RPMBUILDDIR/SPECS
95 100 rpmspec=$RPMBUILDDIR/SPECS/mercurial.spec
96 101
97 102 sed -e "s,^Version:.*,Version: $version," \
98 103 -e "s,^Release:.*,Release: $release," \
104 -e "s/^%global pythonexe .*/%global pythonexe $PYTHONEXE/" \
99 105 $specfile > $rpmspec
100 106
101 107 echo >> $rpmspec
102 108 echo "%changelog" >> $rpmspec
103 109
104 110 if echo $version | grep '+' > /dev/null 2>&1; then
105 111 latesttag="`echo $version | sed -e 's/+.*//'`"
106 112 $HG log -r .:"$latesttag" -fM \
107 113 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
108 114 import sys, time
109 115
110 116 def datestr(date, format):
111 117 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
112 118
113 119 changelog = []
114 120 for l in sys.stdin.readlines():
115 121 tok = l.split("\t")
116 122 hgdate = tuple(int(v) for v in tok[0].split())
117 123 changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
118 124 prevtitle = ""
119 125 for l in sorted(changelog, reverse=True):
120 126 title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
121 127 if prevtitle != title:
122 128 prevtitle = title
123 129 print
124 130 print(title)
125 131 print("- %s" % l[3].strip())
126 132 ' >> $rpmspec
127 133
128 134 else
129 135
130 136 $HG log \
131 137 --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
132 138 .hgtags | python -c '
133 139 import sys, time
134 140
135 141 def datestr(date, format):
136 142 return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
137 143
138 144 for l in sys.stdin.readlines():
139 145 tok = l.split("\t")
140 146 hgdate = tuple(int(v) for v in tok[0].split())
141 147 print("* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2]))
142 148 ' >> $rpmspec
143 149
144 150 fi
145 151
146 152 sed -i \
147 153 -e "s/^%define withpython.*$/%define withpython $RPMPYTHONVER/" \
148 154 $rpmspec
149 155
150 156 if [ "$BUILD" ]; then
151 157 rpmbuild --define "_topdir $RPMBUILDDIR" -ba $rpmspec --clean
152 158 if [ $? = 0 ]; then
153 159 echo
154 160 echo "Built packages for $version-$release:"
155 161 find $RPMBUILDDIR/*RPMS/ -type f -newer $rpmspec
156 162 fi
157 163 else
158 164 echo "Prepared sources for $version-$release $rpmspec are in $RPMBUILDDIR/SOURCES/ - use like:"
159 165 echo "rpmbuild --define '_topdir $RPMBUILDDIR' -ba $rpmspec --clean"
160 166 fi
@@ -1,167 +1,171 b''
1 1 %global emacs_lispdir %{_datadir}/emacs/site-lisp
2 2
3 3 %define withpython %{nil}
4 4
5 5 %if "%{?withpython}"
6 6
7 7 %global pythonver %{withpython}
8 8 %global pythonname Python-%{withpython}
9 9 %global docutilsname docutils-0.14
10 10 %global docutilsmd5 c53768d63db3873b7d452833553469de
11 11 %global pythonhg python-hg
12 12 %global hgpyprefix /opt/%{pythonhg}
13 13 # byte compilation will fail on some some Python /test/ files
14 14 %global _python_bytecompile_errors_terminate_build 0
15 15
16 16 %else
17 17
18 18 %global pythonexe python2
19 19 %global pythonver %(%{pythonexe} -c 'import sys;print(".".join(map(str, sys.version_info[:2])))')
20 20
21 21 %endif
22 22
23 23 Summary: A fast, lightweight Source Control Management system
24 24 Name: mercurial
25 25 Version: snapshot
26 26 Release: 0
27 27 License: GPLv2+
28 28 Group: Development/Tools
29 29 URL: https://mercurial-scm.org/
30 30 Source0: %{name}-%{version}-%{release}.tar.gz
31 31 %if "%{?withpython}"
32 32 Source1: %{pythonname}.tgz
33 33 Source2: %{docutilsname}.tar.gz
34 34 %endif
35 35 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
36 36
37 37 BuildRequires: make, gcc, gettext
38 38 %if "%{?withpython}"
39 39 BuildRequires: readline-devel, openssl-devel, ncurses-devel, zlib-devel, bzip2-devel
40 40 %else
41 BuildRequires: python >= 2.7, python-devel, python-docutils >= 0.5
42 Requires: python >= 2.7
41 BuildRequires: python >= %{pythonver}, python-devel, python-docutils >= 0.5
42 Requires: python >= %{pythonver}
43 43 %endif
44 44 # The hgk extension uses the wish tcl interpreter, but we don't enforce it
45 45 #Requires: tk
46 46
47 47 %description
48 48 Mercurial is a fast, lightweight source control management system designed
49 49 for efficient handling of very large distributed projects.
50 50
51 51 %prep
52 52
53 53 %if "%{?withpython}"
54 54 %setup -q -n mercurial-%{version}-%{release} -a1 -a2
55 55 # despite the comments in cgi.py, we do this to prevent rpmdeps from picking /usr/local/bin/python up
56 56 sed -i '1c#! /usr/bin/env %{pythonexe}' %{pythonname}/Lib/cgi.py
57 57 %else
58 58 %setup -q -n mercurial-%{version}-%{release}
59 59 %endif
60 60
61 61 %build
62 62
63 export HGPYTHON3=1
64
63 65 %if "%{?withpython}"
64 66
65 67 PYPATH=$PWD/%{pythonname}
66 68 cd $PYPATH
67 69 ./configure --prefix=%{hgpyprefix}
68 70 make all %{?_smp_mflags}
69 71 cd -
70 72
71 73 cd %{docutilsname}
72 74 LD_LIBRARY_PATH=$PYPATH $PYPATH/python setup.py build
73 75 cd -
74 76
75 77 # verify Python environment
76 78 LD_LIBRARY_PATH=$PYPATH PYTHONPATH=$PWD/%{docutilsname} $PYPATH/python -c 'import sys, zlib, bz2, ssl, curses, readline'
77 79
78 80 # set environment for make
79 81 export PATH=$PYPATH:$PATH
80 82 export LD_LIBRARY_PATH=$PYPATH
81 83 export CFLAGS="-L $PYPATH"
82 84 export PYTHONPATH=$PWD/%{docutilsname}
83 85
84 86 %endif
85 87
86 88 make all PYTHON=%{pythonexe}
87 89 make -C contrib/chg
88 90
89 91 sed -i -e '1s|#!/usr/bin/env python$|#!/usr/bin/env %{pythonexe}|' contrib/hg-ssh
90 92
91 93 %install
92 94 rm -rf $RPM_BUILD_ROOT
93 95
96 export HGPYTHON3=1
97
94 98 %if "%{?withpython}"
95 99
96 100 PYPATH=$PWD/%{pythonname}
97 101 cd $PYPATH
98 102 make install DESTDIR=$RPM_BUILD_ROOT
99 103 # these .a are not necessary and they are readonly and strip fails - kill them!
100 104 rm -f %{buildroot}%{hgpyprefix}/lib/{,python2.*/config}/libpython2.*.a
101 105 cd -
102 106
103 107 cd %{docutilsname}
104 108 LD_LIBRARY_PATH=$PYPATH $PYPATH/python setup.py install --root="$RPM_BUILD_ROOT"
105 109 cd -
106 110
107 111 PATH=$PYPATH:$PATH LD_LIBRARY_PATH=$PYPATH make install PYTHON=%{pythonexe} DESTDIR=$RPM_BUILD_ROOT PREFIX=%{hgpyprefix} MANDIR=%{_mandir}
108 112 mkdir -p $RPM_BUILD_ROOT%{_bindir}
109 113 ( cd $RPM_BUILD_ROOT%{_bindir}/ && ln -s ../..%{hgpyprefix}/bin/hg . )
110 114 ( cd $RPM_BUILD_ROOT%{_bindir}/ && ln -s ../..%{hgpyprefix}/bin/python2.? %{pythonhg} )
111 115
112 116 %else
113 117
114 118 make install PYTHON=%{pythonexe} DESTDIR=$RPM_BUILD_ROOT PREFIX=%{_prefix} MANDIR=%{_mandir}
115 119
116 120 %endif
117 121
118 122 install -m 755 contrib/chg/chg $RPM_BUILD_ROOT%{_bindir}/
119 123 install -m 755 contrib/hgk $RPM_BUILD_ROOT%{_bindir}/
120 124 install -m 755 contrib/hg-ssh $RPM_BUILD_ROOT%{_bindir}/
121 125
122 126 bash_completion_dir=$RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d
123 127 mkdir -p $bash_completion_dir
124 128 install -m 644 contrib/bash_completion $bash_completion_dir/mercurial.sh
125 129
126 130 zsh_completion_dir=$RPM_BUILD_ROOT%{_datadir}/zsh/site-functions
127 131 mkdir -p $zsh_completion_dir
128 132 install -m 644 contrib/zsh_completion $zsh_completion_dir/_mercurial
129 133
130 134 mkdir -p $RPM_BUILD_ROOT%{emacs_lispdir}
131 135 install -m 644 contrib/mercurial.el $RPM_BUILD_ROOT%{emacs_lispdir}/
132 136 install -m 644 contrib/mq.el $RPM_BUILD_ROOT%{emacs_lispdir}/
133 137
134 138 mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/mercurial/hgrc.d
135 139
136 140 %clean
137 141 rm -rf $RPM_BUILD_ROOT
138 142
139 143 %files
140 144 %defattr(-,root,root,-)
141 145 %doc CONTRIBUTORS COPYING doc/README doc/hg*.txt doc/hg*.html *.cgi contrib/*.fcgi
142 146 %doc %attr(644,root,root) %{_mandir}/man?/hg*
143 147 %doc %attr(644,root,root) contrib/*.svg
144 148 %dir %{_datadir}/zsh/
145 149 %dir %{_datadir}/zsh/site-functions/
146 150 %{_datadir}/zsh/site-functions/_mercurial
147 151 %dir %{_datadir}/emacs/site-lisp/
148 152 %{_datadir}/emacs/site-lisp/mercurial.el
149 153 %{_datadir}/emacs/site-lisp/mq.el
150 154 %{_bindir}/hg
151 155 %{_bindir}/chg
152 156 %{_bindir}/hgk
153 157 %{_bindir}/hg-ssh
154 158 %dir %{_sysconfdir}/bash_completion.d/
155 159 %config(noreplace) %{_sysconfdir}/bash_completion.d/mercurial.sh
156 160 %dir %{_sysconfdir}/mercurial
157 161 %dir %{_sysconfdir}/mercurial/hgrc.d
158 162 %if "%{?withpython}"
159 163 %{_bindir}/%{pythonhg}
160 164 %{hgpyprefix}
161 165 %else
162 166 %{_libdir}/python%{pythonver}/site-packages/%{name}-*-py%{pythonver}.egg-info
163 167 %{_libdir}/python%{pythonver}/site-packages/%{name}
164 168 %{_libdir}/python%{pythonver}/site-packages/hgext
165 169 %{_libdir}/python%{pythonver}/site-packages/hgext3rd
166 170 %{_libdir}/python%{pythonver}/site-packages/hgdemandimport
167 171 %endif
General Comments 0
You need to be logged in to leave comments. Login now