775814d2f42b804934168af47698efa9bb086f65
[gentoo.git] / www-servers / uwsgi / uwsgi-2.0.17.1-r1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python2_7 python3_{5,6,7} pypy )
7 PYTHON_REQ_USE="threads(+)"
8
9 RUBY_OPTIONAL="yes"
10 USE_RUBY="ruby23 ruby24 ruby25"
11
12 PHP_EXT_INI="no"
13 PHP_EXT_NAME="dummy"
14 PHP_EXT_OPTIONAL_USE="php"
15 USE_PHP="php5-6 php7-1 php7-2 php7-3" # deps must be registered separately below
16
17 MY_P="${P/_/-}"
18
19 inherit eapi7-ver eutils flag-o-matic multilib pax-utils php-ext-source-r3 python-r1 ruby-ng
20
21 DESCRIPTION="uWSGI server for Python web applications"
22 HOMEPAGE="http://projects.unbit.it/uwsgi/"
23 SRC_URI="https://github.com/unbit/uwsgi/archive/${PV}.tar.gz -> ${P}.tar.gz"
24
25 LICENSE="GPL-2"
26 SLOT="0"
27 KEYWORDS="~amd64 ~arm ~x86 ~amd64-linux"
28
29 UWSGI_PLUGINS_STD=( ping cache carbon nagios rpc rrdtool
30         http ugreen signal syslog rsyslog
31         router_{uwsgi,redirect,basicauth,rewrite,http,cache,static,memcached,redis,hash,expires,metrics}
32         {core,fast,raw,ssl}router
33         redislog mongodblog log{file,socket}
34         spooler cheaper_busyness symcall
35         transformation_{chunked,gzip,offload,tofile}
36         zergpool )
37 UWSGI_PLUGINS_OPT=( alarm_{curl,xmpp} clock_{monotonic,realtime} curl_cron
38         dumbloop echo emperor_{amqp,pg,zeromq} forkptyrouter
39         geoip graylog2 legion_cache_fetch ldap log{crypto,pipe} notfound pam
40         rados router_{access,radius,spnego,xmldir}
41         sqlite ssi stats_pusher_statsd
42         systemd_logger transformation_toupper tuntap webdav xattr xslt zabbix )
43
44 LANG_SUPPORT_SIMPLE=( cgi mono perl ) # plugins which can be built in the main build process
45 LANG_SUPPORT_EXTENDED=( go lua php pypy python python_asyncio python_gevent ruby )
46
47 # plugins to be ignored (for now):
48 # cheaper_backlog2: example plugin
49 # coroae: TODO
50 # cplusplus: partially example code, needs explicit class
51 # dummy: no idea
52 # example: example plugin
53 # exception_log: example plugin
54 # *java*: TODO
55 # v8: TODO
56 # matheval: TODO
57 IUSE="apache2 +caps debug +embedded expat jemalloc json libressl +pcre +routing selinux +ssl +xml yajl yaml zeromq"
58
59 for plugin in ${UWSGI_PLUGINS_STD[@]}; do IUSE="${IUSE} +uwsgi_plugins_${plugin}"; done
60 for plugin in ${UWSGI_PLUGINS_OPT[@]}; do IUSE="${IUSE} uwsgi_plugins_${plugin}"; done
61 IUSE="${IUSE} ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]}"
62
63 REQUIRED_USE="|| ( ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]} )
64         uwsgi_plugins_logcrypto? ( ssl )
65         uwsgi_plugins_sslrouter? ( ssl )
66         routing? ( pcre )
67         uwsgi_plugins_emperor_zeromq? ( zeromq )
68         uwsgi_plugins_forkptyrouter? ( uwsgi_plugins_corerouter )
69         uwsgi_plugins_router_xmldir? ( xml !expat )
70         pypy? ( python_targets_python2_7 )
71         python? ( ${PYTHON_REQUIRED_USE} )
72         python_asyncio? ( || ( $(python_gen_useflags -3) ) )
73         python_gevent? ( python )
74         expat? ( xml )"
75
76 # util-linux is required for libuuid when requesting zeromq support
77 # Order:
78 # 1. Unconditional
79 # 2. General features
80 # 3. Plugins
81 # 4. Language/app support
82 CDEPEND="
83         sys-libs/zlib
84         caps? ( sys-libs/libcap )
85         json? (
86                 !yajl? ( dev-libs/jansson )
87                 yajl? ( dev-libs/yajl )
88         )
89         pcre? ( dev-libs/libpcre:3 )
90         ssl? (
91                 !libressl? ( dev-libs/openssl:0= )
92                 libressl? ( dev-libs/libressl )
93         )
94         xml? (
95                 !expat? ( dev-libs/libxml2 )
96                 expat? ( dev-libs/expat )
97         )
98         yaml? ( dev-libs/libyaml )
99         zeromq? ( net-libs/zeromq sys-apps/util-linux )
100         uwsgi_plugins_alarm_curl? ( net-misc/curl )
101         uwsgi_plugins_alarm_xmpp? ( net-libs/gloox )
102         uwsgi_plugins_curl_cron? ( net-misc/curl )
103         uwsgi_plugins_emperor_pg? ( dev-db/postgresql:= )
104         uwsgi_plugins_geoip? ( dev-libs/geoip )
105         uwsgi_plugins_ldap? ( net-nds/openldap )
106         uwsgi_plugins_pam? ( sys-libs/pam )
107         uwsgi_plugins_sqlite? ( dev-db/sqlite:3 )
108         uwsgi_plugins_rados? ( sys-cluster/ceph )
109         uwsgi_plugins_router_access? ( sys-apps/tcp-wrappers )
110         uwsgi_plugins_router_spnego? ( virtual/krb5 )
111         uwsgi_plugins_systemd_logger? ( sys-apps/systemd )
112         uwsgi_plugins_webdav? ( dev-libs/libxml2 )
113         uwsgi_plugins_xslt? ( dev-libs/libxslt )
114         go? ( sys-devel/gcc:=[go] )
115         lua? ( dev-lang/lua:= )
116         mono? ( dev-lang/mono:= )
117         perl? ( dev-lang/perl:= )
118         php? (
119                 php_targets_php5-6? ( dev-lang/php:5.6[embed] )
120                 php_targets_php7-1? ( dev-lang/php:7.1[embed] )
121                 php_targets_php7-2? ( dev-lang/php:7.2[embed] )
122                 php_targets_php7-3? ( dev-lang/php:7.3[embed] )
123         )
124         pypy? ( dev-python/pypy )
125         python? ( ${PYTHON_DEPS} )
126         python_asyncio? ( virtual/python-greenlet[${PYTHON_USEDEP}] )
127         python_gevent? ( >=dev-python/gevent-1.3.5[${PYTHON_USEDEP}] )
128         ruby? ( $(ruby_implementations_depend) )"
129 DEPEND="${CDEPEND}
130         virtual/pkgconfig"
131 RDEPEND="${CDEPEND}
132         selinux? ( sec-policy/selinux-uwsgi )
133         uwsgi_plugins_rrdtool? ( net-analyzer/rrdtool )"
134
135 S="${WORKDIR}/${MY_P}"
136
137 src_unpack() {
138         echo ${PYTHON_USEDEP}
139         default
140 }
141
142 pkg_setup() {
143         python_setup
144         use ruby && ruby-ng_pkg_setup
145 }
146
147 src_prepare() {
148         default
149
150         sed -i \
151                 -e "s|'-O2', ||" \
152                 -e "s|'-Werror', ||" \
153                 -e "s|uc.get('plugin_dir')|uc.get('plugin_build_dir')|" \
154                 uwsgiconfig.py || die "sed failed"
155
156         sed -i \
157                 -e "s|/lib|/$(get_libdir)|" \
158                 plugins/php/uwsgiplugin.py || die "sed failed"
159 }
160
161 src_configure() {
162         local embedded_plugins=()
163         local plugins=()
164         local malloc_impl="libc"
165         local json="false"
166         local xml="false"
167
168         for p in ${UWSGI_PLUGINS_STD[@]} ${UWSGI_PLUGINS_OPT[@]} ; do
169                 use uwsgi_plugins_${p} && embedded_plugins+=("${p}")
170         done
171         for p in ${LANG_SUPPORT_SIMPLE[@]} ; do
172                 use ${p} && plugins+=("${p}")
173         done
174
175         # do not embed any plugins
176         if ! use embedded; then
177                 plugins=( ${plugins[@]} ${embedded_plugins[@]} )
178                 embedded_plugins=()
179         fi
180
181         # flatten the arrays
182         plugins=${plugins[@]}
183         embedded_plugins=${embedded_plugins[@]}
184
185         # rename some of the use flags, language plugins are always real plugins
186         plugins="${plugins/perl/psgi}"
187         plugins="${plugins/sqlite/sqlite3}"
188         embedded_plugins="${embedded_plugins/sqlite/sqlite3}"
189
190         # override defaults as requested by the user
191         if use xml; then
192                 use expat && xml="expat" || xml="libxml2"
193         fi
194         if use json; then
195                 use yajl && json="yajl" || json="jansson"
196         fi
197         use jemalloc && malloc_impl="jemalloc"
198
199         # prepare the buildconf for gentoo
200         cp "${FILESDIR}"/gentoo.buildconf buildconf/gentoo.ini || die
201         sed -i \
202                 -e "s|VAR_XML|${xml}|" \
203                 -e "s|VAR_YAML|$(usex yaml libyaml true)|" \
204                 -e "s|VAR_JSON|${json}|" \
205                 -e "s|VAR_SSL|$(usex ssl true false)|" \
206                 -e "s|VAR_PCRE|$(usex pcre true false)|" \
207                 -e "s|VAR_ZMQ|$(usex zeromq true false)|" \
208                 -e "s|VAR_ROUTING|$(usex routing true false)|" \
209                 -e "s|VAR_DEBUG|$(usex debug true false)|" \
210                 -e "s|VAR_MALLOC|${malloc_impl}|" \
211                 -e "s|VAR_PLUGINS|${plugins// /, }|" \
212                 -e "s|VAR_PLUGIN_DIR|${EPREFIX}/usr/$(get_libdir)/uwsgi|" \
213                 -e "s|VAR_BUILD_DIR|${T}/plugins|" \
214                 -e "s|VAR_EMBEDDED|${embedded_plugins// /, }|" \
215                 buildconf/gentoo.ini || die "sed failed"
216
217         if ! use caps; then
218                 sed -i -e 's|sys/capability.h|DISABLED|' uwsgiconfig.py || die "sed failed"
219         fi
220
221         if ! use zeromq; then
222                 sed -i -e 's|uuid/uuid.h|DISABLED|' uwsgiconfig.py || die "sed failed"
223         fi
224
225         if use uwsgi_plugins_emperor_pg ; then
226                 PGPV="$(best_version dev-db/postgresql)"
227                 PGSLOT="$(ver_cut 1-2 ${PGPV##dev-db/postgresql-})"
228                 sed -i \
229                         -e "s|pg_config|pg_config${PGSLOT/.}|" \
230                         plugins/emperor_pg/uwsgiplugin.py || die "sed failed"
231         fi
232 }
233
234 each_ruby_compile() {
235         cd "${WORKDIR}/${MY_P}" || die "sed failed"
236
237         UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rack gentoo rack_${RUBY##*/} || die "building plugin for ${RUBY} failed"
238         UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/fiber gentoo fiber_${RUBY##*/}|| die "building fiber plugin for ${RUBY} failed"
239         UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rbthreads gentoo rbthreads_${RUBY##*/}|| die "building rbthreads plugin for ${RUBY} failed"
240 }
241
242 python_compile_plugins() {
243         local EPYV
244         local PYV
245         EPYV=${EPYTHON/.}
246         PYV=${EPYV/python}
247
248         if [[ ${EPYTHON} == pypy* ]]; then
249                 einfo "skipping because pypy is not meant to build plugins on its own"
250                 return
251         fi
252
253         ${PYTHON} uwsgiconfig.py --plugin plugins/python gentoo ${EPYV} || die "building plugin for ${EPYTHON} failed"
254
255         if use python_asyncio ; then
256                 if [[ "${PYV}" != "27" ]] ; then
257                         ${PYTHON} uwsgiconfig.py --plugin plugins/asyncio gentoo asyncio${PYV} || die "building plugin for asyncio-support in ${EPYTHON} failed"
258                 fi
259         fi
260
261         if use python_gevent ; then
262                 ${PYTHON} uwsgiconfig.py --plugin plugins/gevent gentoo gevent${PYV} || die "building plugin for gevent-support in ${EPYTHON} failed"
263         fi
264
265         if use python_gevent || use python_asyncio; then
266                         ${PYTHON} uwsgiconfig.py --plugin plugins/greenlet gentoo greenlet${PYV} || die "building plugin for greenlet-support in ${EPYTHON} failed"
267         fi
268
269         if use pypy ; then
270                 if [[ "${PYV}" == "27" ]] ; then
271                         # TODO: do some proper patching ? The wiki didn't help... I gave up for now.
272                         # QA: RWX --- --- usr/lib64/uwsgi/pypy_plugin.so
273                         append-ldflags -Wl,-z,noexecstack
274                         ${PYTHON} uwsgiconfig.py --plugin plugins/pypy gentoo pypy || die "building plugin for pypy-support in ${EPYTHON} failed"
275                 fi
276         fi
277 }
278
279 python_install_symlinks() {
280         dosym uwsgi /usr/bin/uwsgi_${EPYTHON/.}
281 }
282
283 src_compile() {
284         mkdir -p "${T}/plugins" || die
285
286         python uwsgiconfig.py --build gentoo || die "building uwsgi failed"
287
288         if use go ; then
289                 python uwsgiconfig.py --plugin plugins/gccgo gentoo || die "building plugin for go failed"
290         fi
291
292         if use lua ; then
293                 # setting the name for the pkg-config file to lua, since we don't have
294                 # slotted lua
295                 UWSGICONFIG_LUAPC="lua" python uwsgiconfig.py --plugin plugins/lua gentoo || die "building plugin for lua failed"
296         fi
297
298         if use php ; then
299                 for s in $(php_get_slots); do
300                         UWSGICONFIG_PHPDIR="/usr/$(get_libdir)/${s}" python uwsgiconfig.py --plugin plugins/php gentoo ${s/.} || die "building plugin for ${s} failed"
301                 done
302         fi
303
304         if use python ; then
305                 python_foreach_impl python_compile_plugins
306         fi
307
308         if use ruby ; then
309                 ruby-ng_src_compile
310         fi
311 }
312
313 src_install() {
314         dobin uwsgi
315         pax-mark m "${D}"/usr/bin/uwsgi
316
317         insinto /usr/$(get_libdir)/uwsgi
318         doins "${T}/plugins"/*.so
319
320         use cgi && dosym uwsgi /usr/bin/uwsgi_cgi
321         use go && dosym uwsgi /usr/bin/uwsgi_go
322         use lua && dosym uwsgi /usr/bin/uwsgi_lua
323         use mono && dosym uwsgi /usr/bin/uwsgi_mono
324         use perl && dosym uwsgi /usr/bin/uwsgi_psgi
325
326         if use php ; then
327                 for s in $(php_get_slots); do
328                         dosym uwsgi /usr/bin/uwsgi_${s/.}
329                 done
330         fi
331
332         if use python ; then
333                 python_foreach_impl python_install_symlinks
334                 python_foreach_impl python_domodule uwsgidecorators.py
335         fi
336
337         newinitd "${FILESDIR}"/uwsgi.initd-r7 uwsgi
338         newconfd "${FILESDIR}"/uwsgi.confd-r4 uwsgi
339         keepdir /etc/"${PN}".d
340         use uwsgi_plugins_spooler && keepdir /var/spool/"${PN}"
341 }
342
343 pkg_postinst() {
344         if use apache2 ; then
345                 ewarn "As reported on bug #650776 [1], Apache module mod_proxy_uwsgi"
346                 ewarn "is being transferred to upstream Apache since 2.4.30, see [2]."
347                 ewarn "We therefore do not build them any more."
348                 ewarn "    [1] https://bugs.gentoo.org/650776"
349                 ewarn "    [2] https://github.com/unbit/uwsgi/issues/1636"
350         fi
351
352         elog "Append the following options to the uwsgi call to load the respective language plugin:"
353         use cgi    && elog "  '--plugins cgi' for cgi"
354         use lua    && elog "  '--plugins lua' for lua"
355         use mono   && elog "  '--plugins mono' for mono"
356         use perl   && elog "  '--plugins psgi' for perl"
357
358         if use php ; then
359                 for s in $(php_get_slots); do
360                         elog "  '--plugins ${s/.}' for ${s}"
361                 done
362         fi
363
364         python_pkg_postinst() {
365                 local EPYV
366                 local PYV
367                 EPYV=${EPYTHON/.}
368                 PYV=${EPYV/python}
369
370                 if [[ ${EPYTHON} == pypy* ]] ; then
371                         elog "  '--plugins pypy' for pypy"
372                         return
373                 fi
374
375                 elog " "
376                 elog "  '--plugins ${EPYV}' for ${EPYTHON}"
377                 if use python_asyncio ; then
378                         if [[ ${EPYV} == python34 ]] ; then
379                                 elog "  '--plugins ${EPYV},asyncio${PYV}' for asyncio support in ${EPYTHON}"
380                         else
381                                 elog "  (asyncio is only supported in python3.4)"
382                         fi
383                 fi
384                 if use python_gevent ; then
385                         elog "  '--plugins ${EPYV},gevent${PYV}' for gevent support in ${EPYTHON}"
386                 fi
387         }
388
389         use python && python_foreach_impl python_pkg_postinst
390
391         if use ruby ; then
392                 for ruby in $(ruby_get_use_implementations) ; do
393                         elog "  '--plugins rack_${ruby/.}' for ${ruby}"
394                         elog "  '--plugins fiber_${ruby/.}' for ${ruby} fibers"
395                         elog "  '--plugins rbthreads_${ruby/.}' for ${ruby} rbthreads"
396                 done
397         fi
398 }