dev-perl/Test-MockRandom: Blind stable on arm, critical bug 667774
[gentoo.git] / eclass / twisted-r1.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: twisted-r1.eclass
5 # @MAINTAINER:
6 # Gentoo Python Project <python@gentoo.org>
7 # @AUTHOR:
8 # Author: Michał Górny <mgorny@gentoo.org>
9 # Author: Jan Matejka <yac@gentoo.org>
10 # @SUPPORTED_EAPIS: 4 5
11 # @BLURB: Eclass for Twisted packages
12 # @DESCRIPTION:
13 # The twisted eclass defines phase functions for Twisted packages.
14
15 case "${EAPI:-0}" in
16         0|1|2|3)
17                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
18                 ;;
19         4|5)
20                 ;;
21         *)
22                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
23                 ;;
24 esac
25
26 if [[ ! ${_TWISTED_R1} ]]; then
27
28 inherit distutils-r1 versionator
29
30 fi # ! ${_TWISTED_R1}
31
32 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
33
34 if [[ ! ${_TWISTED_R1} ]]; then
35
36 # @FUNCTION: _twisted-r1_camelcase
37 # @USAGE: <pn>
38 # @DESCRIPTION:
39 # Convert dash-separated <pn> to CamelCase name suitable for Twisted.
40 # In pure bash, therefore safe for global scope execution.
41 _twisted-r1_camelcase() {
42         local IFS=-
43
44         # IFS=- splits words by -.
45         local words=( ${1} )
46
47         # we can't keep '-' as it collides with [a-z] check
48         # and '' is used by bash-4 words[*], so let's just set globally
49         IFS=
50
51         if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then
52                 echo "${words[*]^}"
53                 return
54         fi
55
56         local w LC_COLLATE=C uc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
57
58         local out
59         for w in "${words[@]}"; do
60                 local fl=${w:0:1}
61
62                 # Danger: magic starts here. Please close your eyes.
63                 # In base 36, a..z represents digits 10..35. We substract 10
64                 # and get array subscripts for uc.
65
66                 [[ ${fl} == [a-z] ]] && fl=${uc:36#${fl} - 10:1}
67
68                 out+=${fl}${w:1}
69         done
70
71         echo "${out}"
72 }
73
74 # @ECLASS-VARIABLE: TWISTED_PN
75 # @DESCRIPTION:
76 # The real package name. Default to camel-case conversion of ${PN}.
77 #
78 # Example: TwistedCore
79 : ${TWISTED_PN:=$(_twisted-r1_camelcase ${PN})}
80
81 # @ECLASS-VARIABLE: TWISTED_P
82 # @DESCRIPTION:
83 # The real package name with version appended.
84 #
85 # It is used to build the default SRC_URI and S values.
86 #
87 # Example: TwistedCore-1.2.3
88 : ${TWISTED_P:=${TWISTED_PN}-${PV}}
89
90 # @ECLASS-VARIABLE: TWISTED_RELEASE
91 # @DESCRIPTION:
92 # The 'release' of Twisted. Defaults to the major & minor version
93 # number from ${PV}.
94 #
95 # It is used to build the default SRC_URI. It may be also used
96 # in dependencies against other Twisted packages.
97 #
98 # Example: 1.2
99 : ${TWISTED_RELEASE:=$(get_version_component_range 1-2 ${PV})}
100
101 HOMEPAGE="https://www.twistedmatrix.com/trac/"
102 SRC_URI="https://twistedmatrix.com/Releases/${TWISTED_PN#Twisted}"
103 SRC_URI="${SRC_URI}/${TWISTED_RELEASE}/${TWISTED_P}.tar.bz2"
104
105 LICENSE="MIT"
106 SLOT="0"
107 IUSE=""
108
109 S=${WORKDIR}/${TWISTED_P}
110
111 # @ECLASS-VARIABLE: TWISTED_PLUGINS
112 # @DESCRIPTION:
113 # An array of Twisted plugins, whose cache is regenerated
114 # in pkg_postinst() and pkg_postrm() phases.
115 #
116 # If no plugins are installed, set to empty array.
117 declare -p TWISTED_PLUGINS &>/dev/null || TWISTED_PLUGINS=( twisted.plugins )
118
119 # @FUNCTION: twisted-r1_python_test
120 # @DESCRIPTION:
121 # The common python_test() implementation that suffices for Twisted
122 # packages.
123 twisted-r1_python_test() {
124         local sitedir=$(python_get_sitedir)
125
126         # Copy modules of other Twisted packages from site-packages
127         # directory to the temporary directory.
128         local libdir=${BUILD_DIR}/test/lib
129         mkdir -p "${libdir}" || die
130         cp -r "${ROOT}${sitedir}"/twisted "${libdir}" || die
131         # Drop the installed module in case previous version conflicts with
132         # the new one somehow.
133         rm -fr "${libdir}/${PN/-//}" || die
134
135         distutils_install_for_testing || die
136
137         if [[ ${TEST_DIR} != ${BUILD_DIR}/test ]]; then
138                 eerror "twisted-r1 integrity check failed."
139                 eerror "TEST_DIR: ${TEST_DIR}"
140                 eerror "expected: ${BUILD_DIR}/test"
141                 die "TEST_DIR integrity check failed"
142         fi
143
144         cd "${TEST_DIR}"/lib || die
145         trial ${PN/-/.} || die "Tests fail with ${EPYTHON}"
146 }
147
148 # @FUNCTION: python_test
149 # @DESCRIPTION:
150 # Default python_test() for Twisted packages. If you need to override
151 # it, you can access the original implementation
152 # via twisted-r1_python_test.
153 python_test() {
154         twisted-r1_python_test
155 }
156
157 # @FUNCTION: twisted-r1_src_install
158 # @DESCRIPTION:
159 # Default src_install() for Twisted packages. Automatically handles HTML
160 # docs (unless HTML_DOCS is set explicitly) and manpages in Twisted
161 # packages.
162 twisted-r1_src_install() {
163         [[ -d doc ]] && local HTML_DOCS=( "${HTML_DOCS[@]:-doc/.}" )
164         [[ -d doc/man ]] && doman doc/man/*.[[:digit:]]
165
166         distutils-r1_src_install
167 }
168
169 # @FUNCTION: _twisted-r1_create_caches
170 # @USAGE: <packages>...
171 # @DESCRIPTION:
172 # Create dropin.cache for plugins in specified packages. The packages
173 # are to be listed in standard dotted Python syntax.
174 _twisted-r1_create_caches() {
175         # http://twistedmatrix.com/documents/current/core/howto/plugin.html
176         "${PYTHON}" -c \
177 "import sys
178 sys.path.insert(0, '${ROOT}$(python_get_sitedir)')
179
180 fail = False
181
182 try:
183         from twisted.plugin import getPlugins, IPlugin
184 except ImportError as e:
185         if '${EBUILD_PHASE}' == 'postinst':
186                 raise
187 else:
188         for module in sys.argv[1:]:
189                 try:
190                         __import__(module, globals())
191                 except ImportError as e:
192                         if '${EBUILD_PHASE}' == 'postinst':
193                                 raise
194                 else:
195                         list(getPlugins(IPlugin, sys.modules[module]))
196 " \
197                 "${@}" || die "twisted plugin cache update failed"
198 }
199
200 # @FUNCTION: twisted-r1_update_plugin_cache
201 # @DESCRIPTION:
202 # Update and clean up plugin caches for packages listed
203 # in TWISTED_PLUGINS.
204 twisted-r1_update_plugin_cache() {
205         [[ ${TWISTED_PLUGINS[@]} ]] || return
206
207         local subdirs=( "${TWISTED_PLUGINS[@]//.//}" )
208         local paths=( "${subdirs[@]/#/${ROOT}$(python_get_sitedir)/}" )
209         local caches=( "${paths[@]/%//dropin.cache}" )
210
211         # First, delete existing (possibly stray) caches.
212         rm -f "${caches[@]}" || die
213
214         # Now, let's see which ones we can regenerate.
215         _twisted-r1_create_caches "${TWISTED_PLUGINS[@]}"
216
217         # Finally, drop empty parent directories.
218         rmdir -p "${paths[@]}" 2>/dev/null
219 }
220
221 # @FUNCTION: twisted-r1_pkg_postinst
222 # @DESCRIPTION:
223 # Post-installation hook for twisted-r1. Updates plugin caches.
224 twisted-r1_pkg_postinst() {
225         _distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
226 }
227
228 # @FUNCTION: twisted-r1_pkg_postrm
229 # @DESCRIPTION:
230 # Post-removal hook for twisted-r1. Updates plugin caches.
231 twisted-r1_pkg_postrm() {
232         _distutils-r1_run_foreach_impl twisted-r1_update_plugin_cache
233 }
234
235 _TWISTED_R1=1
236
237 fi # ! ${_TWISTED_R1}