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

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (show annotations) (download)
Tue Jan 15 11:10:17 2013 UTC (19 months, 1 week ago) by jlec
Branch: MAIN
Changes since 1.44: +2 -2 lines
Fix typo

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.44 2013/01/12 23:18:20 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: DISTUTILS_JOBS
71 # @DEFAULT_UNSET
72 # @DESCRIPTION:
73 # The number of parallel jobs to run for distutils-r1 parallel builds.
74 # If unset, the job-count in ${MAKEOPTS} will be used.
75 #
76 # This variable is intended to be set in make.conf.
77
78 # @ECLASS-VARIABLE: PATCHES
79 # @DEFAULT_UNSET
80 # @DESCRIPTION:
81 # An array containing patches to be applied to the sources before
82 # copying them.
83 #
84 # If unset, no custom patches will be applied.
85 #
86 # Please note, however, that at some point the eclass may apply
87 # additional distutils patches/quirks independently of this variable.
88 #
89 # Example:
90 # @CODE
91 # PATCHES=( "${FILESDIR}"/${P}-make-gentoo-happy.patch )
92 # @CODE
93
94 # @ECLASS-VARIABLE: DOCS
95 # @DEFAULT_UNSET
96 # @DESCRIPTION:
97 # An array containing documents installed using dodoc. The files listed
98 # there must exist in the directory from which
99 # distutils-r1_python_install_all() is run (${S} by default).
100 #
101 # If unset, the function will instead look up files matching default
102 # filename pattern list (from the Package Manager Specification),
103 # and install those found.
104 #
105 # Example:
106 # @CODE
107 # DOCS=( NEWS README )
108 # @CODE
109
110 # @ECLASS-VARIABLE: HTML_DOCS
111 # @DEFAULT_UNSET
112 # @DESCRIPTION:
113 # An array containing documents installed using dohtml. The files
114 # and directories listed there must exist in the directory from which
115 # distutils-r1_python_install_all() is run (${S} by default).
116 #
117 # If unset, no HTML docs will be installed.
118 #
119 # Example:
120 # @CODE
121 # HTML_DOCS=( doc/html/ )
122 # @CODE
123
124 # @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
125 # @DEFAULT_UNSET
126 # @DESCRIPTION:
127 # If set to a non-null value, in-source builds will be enabled.
128 # If unset, the default is to use in-source builds when python_prepare()
129 # is declared, and out-of-source builds otherwise.
130 #
131 # If in-source builds are used, the eclass will create a copy of package
132 # sources for each Python implementation in python_prepare_all(),
133 # and work on that copy afterwards.
134 #
135 # If out-of-source builds are used, the eclass will instead work
136 # on the sources directly, prepending setup.py arguments with
137 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
138 # files in the specific root.
139
140 # @ECLASS-VARIABLE: DISTUTILS_NO_PARALLEL_BUILD
141 # @DEFAULT_UNSET
142 # @DESCRIPTION:
143 # If set to a non-null value, the parallel build feature will
144 # be disabled.
145 #
146 # When parallel builds are used, the implementation-specific sub-phases
147 # for selected Python implementation will be run in parallel. This will
148 # increase build efficiency with distutils which does not do parallel
149 # builds.
150 #
151 # This variable can be used to disable the afore-mentioned feature
152 # in case it causes issues with the package.
153
154 # @ECLASS-VARIABLE: mydistutilsargs
155 # @DEFAULT_UNSET
156 # @DESCRIPTION:
157 # An array containing options to be passed to setup.py.
158 #
159 # Example:
160 # @CODE
161 # python_configure_all() {
162 # mydistutilsargs=( --enable-my-hidden-option )
163 # }
164 # @CODE
165
166 # @FUNCTION: esetup.py
167 # @USAGE: [<args>...]
168 # @DESCRIPTION:
169 # Run the setup.py using currently selected Python interpreter
170 # (if ${PYTHON} is set; fallback 'python' otherwise). The setup.py will
171 # be passed default ${mydistutilsargs[@]}, then any parameters passed
172 # to this command and optionally a standard option set (e.g. the build
173 # directory in an ebuild using out-of-source builds).
174 #
175 # This command dies on failure.
176 esetup.py() {
177 debug-print-function ${FUNCNAME} "${@}"
178
179 local add_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 add_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 "${mydistutilsargs[@]}" "${@}" "${add_args[@]}"
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(). A no-op.
233 distutils-r1_python_prepare() {
234 debug-print-function ${FUNCNAME} "${@}"
235
236 :
237 }
238
239 # @FUNCTION: distutils-r1_python_configure
240 # @DESCRIPTION:
241 # The default python_configure(). A no-op.
242 distutils-r1_python_configure() {
243 debug-print-function ${FUNCNAME} "${@}"
244
245 :
246 }
247
248 # @FUNCTION: distutils-r1_python_compile
249 # @USAGE: [additional-args...]
250 # @DESCRIPTION:
251 # The default python_compile(). Runs 'esetup.py build'. Any parameters
252 # passed to this function will be appended to setup.py invocation,
253 # i.e. passed as options to the 'build' command.
254 distutils-r1_python_compile() {
255 debug-print-function ${FUNCNAME} "${@}"
256
257 esetup.py build "${@}"
258 }
259
260 # @FUNCTION: distutils-r1_python_test
261 # @DESCRIPTION:
262 # The default python_test(). A no-op.
263 distutils-r1_python_test() {
264 debug-print-function ${FUNCNAME} "${@}"
265
266 :
267 }
268
269 # @FUNCTION: _distutils-r1_rename_scripts
270 # @USAGE: <path>
271 # @INTERNAL
272 # @DESCRIPTION:
273 # Renames installed Python scripts to be implementation-suffixed.
274 # ${EPYTHON} needs to be set to the implementation name.
275 #
276 # All executable scripts having shebang referencing ${EPYTHON}
277 # in given path will be renamed.
278 _distutils-r1_rename_scripts() {
279 debug-print-function ${FUNCNAME} "${@}"
280
281 local path=${1}
282 [[ ${path} ]] || die "${FUNCNAME}: no path given"
283
284 local f
285 while IFS= read -r -d '' f; do
286 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
287
288 if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
289 then
290 debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
291
292 local newf=${f}-${EPYTHON}
293 debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
294 mv "${f}" "${newf}" || die
295
296 debug-print "${FUNCNAME}: installing wrapper at ${f#${D}/}"
297 _python_ln_rel "${path}${EPREFIX}"/usr/bin/python-exec "${f}" || die
298 fi
299 done < <(find "${path}" -type f -executable -print0)
300 }
301
302 # @FUNCTION: distutils-r1_python_install
303 # @USAGE: [additional-args...]
304 # @DESCRIPTION:
305 # The default python_install(). Runs 'esetup.py install', appending
306 # the optimization flags. Then renames the installed scripts.
307 # Any parameters passed to this function will be appended
308 # to the setup.py invocation (i.e. as options to the 'install' command).
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 _distutils-r1_merge_root "${root}" "${D}"
337 }
338
339 # @FUNCTION: distutils-r1_merge_root
340 # @USAGE: <src-root> <dest-root>
341 # @INTERNAL
342 # @DESCRIPTION:
343 # Merge the directory tree from <src-root> to <dest-root>, removing
344 # the <src-root> in the process.
345 _distutils-r1_merge_root() {
346 local src=${1}
347 local dest=${2}
348
349 local lockfile=${T}/distutils-r1-merge-lock
350
351 if type -P lockf &>/dev/null; then
352 # On BSD, we have 'lockf' wrapper.
353 tar -C "${src}" -f - -c . \
354 | lockf "${lockfile}" tar -x -f - -C "${dest}"
355 else
356 local lock_fd
357 if type -P flock &>/dev/null; then
358 # On Linux, we have 'flock' which can lock fd.
359 redirect_alloc_fd lock_fd "${lockfile}" '>>'
360 flock ${lock_fd}
361 else
362 ewarn "distutils-r1: no locking service found, please report."
363 fi
364
365 cp -a -l -n "${src}"/. "${dest}"/
366
367 if [[ ${lock_fd} ]]; then
368 # Close the lock file when we are done with it.
369 # Prevents deadlock if we aren't in a subshell.
370 eval "exec ${lock_fd}>&-"
371 fi
372 fi
373 [[ ${?} == 0 ]] || die "Merging ${EPYTHON} image failed."
374
375 rm -rf "${src}"
376 }
377
378 # @FUNCTION: distutils-r1_python_install_all
379 # @DESCRIPTION:
380 # The default python_install_all(). It installs the documentation.
381 distutils-r1_python_install_all() {
382 debug-print-function ${FUNCNAME} "${@}"
383
384 if declare -p DOCS &>/dev/null; then
385 dodoc -r "${DOCS[@]}" || die "dodoc failed"
386 else
387 local f
388 # same list as in PMS
389 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
390 THANKS BUGS FAQ CREDITS CHANGELOG; do
391 if [[ -s ${f} ]]; then
392 dodoc "${f}" || die "(default) dodoc ${f} failed"
393 fi
394 done
395 fi
396
397 if declare -p HTML_DOCS &>/dev/null; then
398 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
399 fi
400 }
401
402 # @FUNCTION: distutils-r1_run_phase
403 # @USAGE: [<argv>...]
404 # @INTERNAL
405 # @DESCRIPTION:
406 # Run the given command.
407 #
408 # If out-of-source builds are used, the phase function is run in source
409 # directory, with BUILD_DIR pointing at the build directory
410 # and PYTHONPATH having an entry for the module build directory.
411 #
412 # If in-source builds are used, the command is executed in the BUILD_DIR
413 # (the directory holding per-implementation copy of sources).
414 distutils-r1_run_phase() {
415 debug-print-function ${FUNCNAME} "${@}"
416
417 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
418 pushd "${BUILD_DIR}" &>/dev/null || die
419 else
420 local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
421 export PYTHONPATH
422 fi
423
424 local TMPDIR=${T}/${EPYTHON}
425
426 mkdir -p "${TMPDIR}" || die
427
428 if [[ ${DISTUTILS_NO_PARALLEL_BUILD} ]]; then
429 "${@}" 2>&1 | tee -a "${T}/build-${EPYTHON}.log"
430 else
431 (
432 multijob_child_init
433 "${@}" 2>&1 | tee -a "${T}/build-${EPYTHON}.log"
434 ) &
435 multijob_post_fork
436 fi
437
438 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
439 popd &>/dev/null || die
440 fi
441
442 # Store them for reuse.
443 _DISTUTILS_BEST_IMPL=(
444 "${EPYTHON}" "${PYTHON}" "${BUILD_DIR}" "${PYTHONPATH}"
445 )
446 }
447
448 # @FUNCTION: _distutils-r1_run_common_phase
449 # @USAGE: [<argv>...]
450 # @INTERNAL
451 # @DESCRIPTION:
452 # Run the given command, restoring the best-implementation state.
453 _distutils-r1_run_common_phase() {
454 local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
455
456 local EPYTHON=${_DISTUTILS_BEST_IMPL[0]}
457 local PYTHON=${_DISTUTILS_BEST_IMPL[1]}
458 local BUILD_DIR=${_DISTUTILS_BEST_IMPL[2]}
459 local PYTHONPATH=${_DISTUTILS_BEST_IMPL[3]}
460
461 export EPYTHON PYTHON PYTHONPATH
462
463 einfo "common: running ${1}"
464 "${@}"
465 }
466
467 # @FUNCTION: _distutils-r1_multijob_init
468 # @INTERNAL
469 # @DESCRIPTION:
470 # Init multijob, taking the job-count from ${DISTUTILS_JOBS}.
471 _distutils-r1_multijob_init() {
472 debug-print-function ${FUNCNAME} "${@}"
473
474 local opts
475 if [[ ${DISTUTILS_JOBS} ]]; then
476 opts=-j${DISTUTILS_JOBS}
477 else
478 opts=${MAKEOPTS}
479 fi
480
481 multijob_init "${opts}"
482 }
483
484 distutils-r1_src_prepare() {
485 debug-print-function ${FUNCNAME} "${@}"
486
487 # common preparations
488 if declare -f python_prepare_all >/dev/null; then
489 python_prepare_all
490 else
491 distutils-r1_python_prepare_all
492 fi
493
494 _distutils-r1_multijob_init
495 if declare -f python_prepare >/dev/null; then
496 python_foreach_impl distutils-r1_run_phase python_prepare
497 fi
498 multijob_finish
499 }
500
501 distutils-r1_src_configure() {
502 _distutils-r1_multijob_init
503 if declare -f python_configure >/dev/null; then
504 python_foreach_impl distutils-r1_run_phase python_configure
505 fi
506 multijob_finish
507
508 if declare -f python_configure_all >/dev/null; then
509 _distutils-r1_run_common_phase python_configure_all
510 fi
511 }
512
513 distutils-r1_src_compile() {
514 debug-print-function ${FUNCNAME} "${@}"
515
516 _distutils-r1_multijob_init
517 if declare -f python_compile >/dev/null; then
518 python_foreach_impl distutils-r1_run_phase python_compile
519 else
520 python_foreach_impl distutils-r1_run_phase distutils-r1_python_compile
521 fi
522 multijob_finish
523
524 if declare -f python_compile_all >/dev/null; then
525 _distutils-r1_run_common_phase python_compile_all
526 fi
527 }
528
529 distutils-r1_src_test() {
530 debug-print-function ${FUNCNAME} "${@}"
531
532 _distutils-r1_multijob_init
533 if declare -f python_test >/dev/null; then
534 python_foreach_impl distutils-r1_run_phase python_test
535 fi
536 multijob_finish
537
538 if declare -f python_test_all >/dev/null; then
539 _distutils-r1_run_common_phase python_test_all
540 fi
541 }
542
543 distutils-r1_src_install() {
544 debug-print-function ${FUNCNAME} "${@}"
545
546 _distutils-r1_multijob_init
547 if declare -f python_install >/dev/null; then
548 python_foreach_impl distutils-r1_run_phase python_install
549 else
550 python_foreach_impl distutils-r1_run_phase distutils-r1_python_install
551 fi
552 multijob_finish
553
554 if declare -f python_install_all >/dev/null; then
555 _distutils-r1_run_common_phase python_install_all
556 else
557 _distutils-r1_run_common_phase distutils-r1_python_install_all
558 fi
559 }
560
561 _DISTUTILS_R1=1
562 fi

  ViewVC Help
Powered by ViewVC 1.1.20