/[gentoo-x86]/eclass/distutils-r1.eclass
Gentoo

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Mon Nov 5 15:15:32 2012 UTC (22 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.17: +3 -2 lines
Fix enabling byte-compiling.

1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/distutils-r1.eclass,v 1.17 2012/11/01 12:19:22 mgorny Exp $
4
5 # @ECLASS: distutils-r1
6 # @MAINTAINER:
7 # Michał Górny <mgorny@gentoo.org>
8 # Python herd <python@gentoo.org>
9 # @AUTHOR:
10 # Author: Michał Górny <mgorny@gentoo.org>
11 # Based on the work of: Krzysztof Pawlik <nelchael@gentoo.org>
12 # @BLURB: A simple eclass to build Python packages using distutils.
13 # @DESCRIPTION:
14 # A simple eclass providing functions to build Python packages using
15 # the distutils build system. It exports phase functions for all
16 # the src_* phases. Each of the phases runs two pseudo-phases:
17 # python_..._all() (e.g. python_prepare_all()) once in ${S}, then
18 # python_...() (e.g. python_prepare()) for each implementation
19 # (see: python_foreach_impl() in python-r1).
20 #
21 # In distutils-r1_src_prepare(), the 'all' function is run before
22 # per-implementation ones (because it creates the implementations),
23 # per-implementation functions are run in a random order.
24 #
25 # In remaining phase functions, the per-implementation functions are run
26 # before the 'all' one, and they are ordered from the least to the most
27 # preferred implementation (so that 'better' files overwrite 'worse'
28 # ones).
29 #
30 # If the ebuild doesn't specify a particular pseudo-phase function,
31 # the default one will be used (distutils-r1_...). Defaults are provided
32 # for all per-implementation pseudo-phases, python_prepare_all()
33 # and python_install_all(); whenever writing your own pseudo-phase
34 # functions, you should consider calling the defaults (and especially
35 # distutils-r1_python_prepare_all).
36 #
37 # Please note that distutils-r1 sets RDEPEND and DEPEND unconditionally
38 # for you.
39 #
40 # Also, please note that distutils-r1 will always inherit python-r1
41 # as well. Thus, all the variables defined and documented there are
42 # relevant to the packages using distutils-r1.
43
44 case "${EAPI}" in
45 0|1|2|3)
46 die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
47 ;;
48 4|5)
49 ;;
50 *)
51 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
52 ;;
53 esac
54
55 inherit eutils python-r1
56
57 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
58
59 RDEPEND=${PYTHON_DEPS}
60 DEPEND=${PYTHON_DEPS}
61
62 # @ECLASS-VARIABLE: PATCHES
63 # @DEFAULT_UNSET
64 # @DESCRIPTION:
65 # An array containing patches to be applied to the sources before
66 # copying them.
67 #
68 # If unset, no custom patches will be applied.
69 #
70 # Please note, however, that at some point the eclass may apply
71 # additional distutils patches/quirks independently of this variable.
72 #
73 # Example:
74 # @CODE
75 # PATCHES=( "${FILESDIR}"/${P}-make-gentoo-happy.patch )
76 # @CODE
77
78 # @ECLASS-VARIABLE: DOCS
79 # @DEFAULT_UNSET
80 # @DESCRIPTION:
81 # An array containing documents installed using dodoc. The files listed
82 # there must exist in the directory from which
83 # distutils-r1_python_install_all() is run (${S} by default).
84 #
85 # If unset, the function will instead look up files matching default
86 # filename pattern list (from the Package Manager Specification),
87 # and install those found.
88 #
89 # Example:
90 # @CODE
91 # DOCS=( NEWS README )
92 # @CODE
93
94 # @ECLASS-VARIABLE: HTML_DOCS
95 # @DEFAULT_UNSET
96 # @DESCRIPTION:
97 # An array containing documents installed using dohtml. The files
98 # and directories listed there must exist in the directory from which
99 # distutils-r1_python_install_all() is run (${S} by default).
100 #
101 # If unset, no HTML docs will be installed.
102 #
103 # Example:
104 # @CODE
105 # HTML_DOCS=( doc/html/ )
106 # @CODE
107
108 # @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
109 # @DEFAULT_UNSET
110 # @DESCRIPTION:
111 # If set to a non-null value, in-source builds will be enabled.
112 # If unset, the default is to use in-source builds when python_prepare()
113 # is declared, and out-of-source builds otherwise.
114 #
115 # If in-source builds are used, the eclass will create a copy of package
116 # sources for each Python implementation in python_prepare_all(),
117 # and work on that copy afterwards.
118 #
119 # If out-of-source builds are used, the eclass will instead work
120 # on the sources directly, prepending setup.py arguments with
121 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
122 # files in the specific root.
123
124 # @ECLASS-VARIABLE: mydistutilsargs
125 # @DEFAULT_UNSET
126 # @DESCRIPTION:
127 # An array containing options to be passed to setup.py.
128 #
129 # Example:
130 # @CODE
131 # python_configure_all() {
132 # mydistutilsargs=( --enable-my-hidden-option )
133 # }
134 # @CODE
135
136 # @FUNCTION: esetup.py
137 # @USAGE: [<args>...]
138 # @DESCRIPTION:
139 # Run the setup.py using currently selected Python interpreter
140 # (if ${PYTHON} is set; fallback 'python' otherwise). The setup.py will
141 # be passed default command-line arguments, then ${mydistutilsargs[@]},
142 # then any parameters passed to this command.
143 #
144 # This command dies on failure.
145 esetup.py() {
146 debug-print-function ${FUNCNAME} "${@}"
147
148 local args=()
149 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
150 if [[ ! ${BUILD_DIR} ]]; then
151 die 'Out-of-source build requested, yet BUILD_DIR unset.'
152 fi
153
154 args+=(
155 build
156 --build-base "${BUILD_DIR}"
157 # using a single directory for them helps us export ${PYTHONPATH}
158 --build-lib "${BUILD_DIR}/lib"
159 )
160 fi
161
162 set -- "${PYTHON:-python}" setup.py \
163 "${args[@]}" "${mydistutilsargs[@]}" "${@}"
164
165 echo "${@}" >&2
166 "${@}" || die
167 }
168
169 # @FUNCTION: distutils-r1_python_prepare_all
170 # @DESCRIPTION:
171 # The default python_prepare_all(). It applies the patches from PATCHES
172 # array, then user patches and finally calls python_copy_sources to
173 # create copies of resulting sources for each Python implementation.
174 #
175 # At some point in the future, it may also apply eclass-specific
176 # distutils patches and/or quirks.
177 distutils-r1_python_prepare_all() {
178 debug-print-function ${FUNCNAME} "${@}"
179
180 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
181
182 epatch_user
183
184 # by default, use in-source build if python_prepare() is used
185 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD+1} ]]; then
186 if declare -f python_prepare >/dev/null; then
187 DISTUTILS_IN_SOURCE_BUILD=1
188 fi
189 fi
190
191 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
192 # create source copies for each implementation
193 python_copy_sources
194 fi
195 }
196
197 # @FUNCTION: distutils-r1_python_prepare
198 # @DESCRIPTION:
199 # The default python_prepare(). Currently it is a no-op
200 # but in the future it may apply implementation-specific quirks
201 # to the build system.
202 distutils-r1_python_prepare() {
203 debug-print-function ${FUNCNAME} "${@}"
204
205 :
206 }
207
208 # @FUNCTION: distutils-r1_python_configure
209 # @DESCRIPTION:
210 # The default python_configure(). Currently a no-op.
211 distutils-r1_python_configure() {
212 debug-print-function ${FUNCNAME} "${@}"
213
214 :
215 }
216
217 # @FUNCTION: distutils-r1_python_compile
218 # @USAGE: [additional-args...]
219 # @DESCRIPTION:
220 # The default python_compile(). Runs 'esetup.py build'. Any parameters
221 # passed to this function will be passed to setup.py.
222 distutils-r1_python_compile() {
223 debug-print-function ${FUNCNAME} "${@}"
224
225 esetup.py build "${@}"
226 }
227
228 # @FUNCTION: distutils-r1_python_test
229 # @DESCRIPTION:
230 # The default python_test(). Currently a no-op.
231 distutils-r1_python_test() {
232 debug-print-function ${FUNCNAME} "${@}"
233
234 :
235 }
236
237 # @FUNCTION: distutils-r1_rename_scripts
238 # @DESCRIPTION:
239 # Renames installed Python scripts to be implementation-suffixed.
240 # ${PYTHON} has to be set to the expected Python executable (which
241 # hashbang will be grepped for), and ${EPYTHON} to the implementation
242 # name (for new name).
243 distutils-r1_rename_scripts() {
244 debug-print-function ${FUNCNAME} "${@}"
245
246 local f
247 # XXX: change this if we ever allow directories in bin/sbin
248 for f in "${D}"/{bin,sbin,usr/bin,usr/sbin}/*; do
249 if [[ -x ${f} ]]; then
250 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
251
252 if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
253 then
254 debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
255
256 local newf=${f}-${EPYTHON}
257 debug-print "${FUNCNAME}: renamed to ${newf#${D}/}"
258 mv "${f}" "${newf}" || die
259 fi
260 fi
261 done
262 }
263
264 # @FUNCTION: distutils-r1_python_install
265 # @USAGE: [additional-args...]
266 # @DESCRIPTION:
267 # The default python_install(). Runs 'esetup.py install', appending
268 # the optimization flags. Then calls distutils-r1_rename_scripts.
269 # Any parameters passed to this function will be passed to setup.py.
270 distutils-r1_python_install() {
271 debug-print-function ${FUNCNAME} "${@}"
272
273 local flags
274
275 case "${EPYTHON}" in
276 jython*)
277 flags=(--compile);;
278 *)
279 flags=(--compile -O2);;
280 esac
281 debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"
282
283 # enable compilation for the install phase.
284 local PYTHONDONTWRITEBYTECODE
285 export PYTHONDONTWRITEBYTECODE
286
287 esetup.py install "${flags[@]}" --root="${D}" "${@}"
288
289 distutils-r1_rename_scripts
290 }
291
292 # @FUNCTION: distutils-r1_python_install_all
293 # @DESCRIPTION:
294 # The default python_install_all(). It symlinks wrappers
295 # for the implementation-suffixed executables and installs
296 # documentation.
297 distutils-r1_python_install_all() {
298 debug-print-function ${FUNCNAME} "${@}"
299
300 if declare -p DOCS &>/dev/null; then
301 dodoc "${DOCS[@]}" || die "dodoc failed"
302 else
303 local f
304 # same list as in PMS
305 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
306 THANKS BUGS FAQ CREDITS CHANGELOG; do
307 if [[ -s ${f} ]]; then
308 dodoc "${f}" || die "(default) dodoc ${f} failed"
309 fi
310 done
311 fi
312
313 if declare -p HTML_DOCS &>/dev/null; then
314 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
315 fi
316
317 # note: keep in sync with ...rename_scripts()
318 # also, we assume that each script is installed for all impls
319 local EPYTHON
320 python_export_best EPYTHON
321
322 local f
323 while IFS= read -r -d '' f; do
324 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
325
326 local wrapf=${f%-${EPYTHON}}
327
328 _python_ln_rel "${ED}"/usr/bin/python-exec "${wrapf}" || die
329 done < <(find "${D}" -type f -executable -name "*-${EPYTHON}" -print0)
330 }
331
332 # @FUNCTION: distutils-r1_run_phase
333 # @USAGE: [<argv>...]
334 # @INTERNAL
335 # @DESCRIPTION:
336 # Run the given command.
337 #
338 # If out-of-source builds are used, the phase function is run in source
339 # directory, with BUILD_DIR pointing at the build directory
340 # and PYTHONPATH having an entry for the module build directory.
341 #
342 # If in-source builds are used, the command is executed in the BUILD_DIR
343 # (the directory holding per-implementation copy of sources).
344 distutils-r1_run_phase() {
345 debug-print-function ${FUNCNAME} "${@}"
346
347 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
348 pushd "${BUILD_DIR}" &>/dev/null || die
349 else
350 local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
351 export PYTHONPATH
352 fi
353
354 "${@}" || die "${1} failed."
355
356 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
357 popd &>/dev/null || die
358 fi
359 }
360
361 distutils-r1_src_prepare() {
362 debug-print-function ${FUNCNAME} "${@}"
363
364 # common preparations
365 if declare -f python_prepare_all >/dev/null; then
366 python_prepare_all
367 else
368 distutils-r1_python_prepare_all
369 fi
370
371 if declare -f python_prepare >/dev/null; then
372 python_foreach_impl distutils-r1_run_phase python_prepare
373 else
374 python_foreach_impl distutils-r1_run_phase distutils-r1_python_prepare
375 fi
376 }
377
378 distutils-r1_src_configure() {
379 if declare -f python_configure >/dev/null; then
380 python_foreach_impl distutils-r1_run_phase python_configure
381 else
382 python_foreach_impl distutils-r1_run_phase distutils-r1_python_configure
383 fi
384
385 if declare -f python_configure_all >/dev/null; then
386 python_configure_all
387 fi
388 }
389
390 distutils-r1_src_compile() {
391 debug-print-function ${FUNCNAME} "${@}"
392
393 if declare -f python_compile >/dev/null; then
394 python_foreach_impl distutils-r1_run_phase python_compile
395 else
396 python_foreach_impl distutils-r1_run_phase distutils-r1_python_compile
397 fi
398
399 if declare -f python_compile_all >/dev/null; then
400 python_compile_all
401 fi
402 }
403
404 distutils-r1_src_test() {
405 debug-print-function ${FUNCNAME} "${@}"
406
407 if declare -f python_test >/dev/null; then
408 python_foreach_impl distutils-r1_run_phase python_test
409 else
410 python_foreach_impl distutils-r1_run_phase distutils-r1_python_test
411 fi
412
413 if declare -f python_test_all >/dev/null; then
414 python_test_all
415 fi
416 }
417
418 distutils-r1_src_install() {
419 debug-print-function ${FUNCNAME} "${@}"
420
421 if declare -f python_install >/dev/null; then
422 python_foreach_impl distutils-r1_run_phase python_install
423 else
424 python_foreach_impl distutils-r1_run_phase distutils-r1_python_install
425 fi
426
427 if declare -f python_install_all >/dev/null; then
428 python_install_all
429 else
430 distutils-r1_python_install_all
431 fi
432 }

  ViewVC Help
Powered by ViewVC 1.1.20