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

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.36 - (show annotations) (download)
Fri Jan 4 03:12:44 2013 UTC (20 months, 2 weeks ago) by floppym
Branch: MAIN
Changes since 1.35: +2 -1 lines
addpredict /usr/lib/portage/pym in distutils-r1_src_install.

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

  ViewVC Help
Powered by ViewVC 1.1.20