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

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.66 - (show annotations) (download)
Mon Apr 1 09:17:53 2013 UTC (17 months ago) by mgorny
Branch: MAIN
Changes since 1.65: +2 -41 lines
Introduce multibuild_merge_root, as an universal interim-install merging function.

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.65 2013/03/19 06:13:41 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 # @ECLASS-VARIABLE: DISTUTILS_OPTIONAL
58 # @DEFAULT_UNSET
59 # @DESCRIPTION:
60 # If set to a non-null value, distutils part in the ebuild will
61 # be considered optional. No dependencies will be added and no phase
62 # functions will be exported.
63 #
64 # If you enable DISTUTILS_OPTIONAL, you have to set proper dependencies
65 # for your package (using ${PYTHON_DEPS}) and to either call
66 # distutils-r1 default phase functions or call the build system
67 # manually.
68
69 # @ECLASS-VARIABLE: DISTUTILS_SINGLE_IMPL
70 # @DEFAULT_UNSET
71 # @DESCRIPTION:
72 # If set to a non-null value, the ebuild will support setting a single
73 # Python implementation only. It will effectively replace the python-r1
74 # eclass inherit with python-single-r1.
75 #
76 # Note that inheriting python-single-r1 will cause pkg_setup()
77 # to be exported. It must be run in order for the eclass functions
78 # to function properly.
79
80 if [[ ! ${_DISTUTILS_R1} ]]; then
81
82 inherit eutils
83
84 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
85 inherit multiprocessing python-r1
86 else
87 inherit python-single-r1
88 fi
89
90 fi
91
92 if [[ ! ${DISTUTILS_OPTIONAL} ]]; then
93 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
94 fi
95
96 if [[ ! ${_DISTUTILS_R1} ]]; then
97
98 if [[ ! ${DISTUTILS_OPTIONAL} ]]; then
99 RDEPEND=${PYTHON_DEPS}
100 DEPEND=${PYTHON_DEPS}
101 fi
102
103 # @ECLASS-VARIABLE: PATCHES
104 # @DEFAULT_UNSET
105 # @DESCRIPTION:
106 # An array containing patches to be applied to the sources before
107 # copying them.
108 #
109 # If unset, no custom patches will be applied.
110 #
111 # Please note, however, that at some point the eclass may apply
112 # additional distutils patches/quirks independently of this variable.
113 #
114 # Example:
115 # @CODE
116 # PATCHES=( "${FILESDIR}"/${P}-make-gentoo-happy.patch )
117 # @CODE
118
119 # @ECLASS-VARIABLE: DOCS
120 # @DEFAULT_UNSET
121 # @DESCRIPTION:
122 # An array containing documents installed using dodoc. The files listed
123 # there must exist in the directory from which
124 # distutils-r1_python_install_all() is run (${S} by default).
125 #
126 # If unset, the function will instead look up files matching default
127 # filename pattern list (from the Package Manager Specification),
128 # and install those found.
129 #
130 # Example:
131 # @CODE
132 # DOCS=( NEWS README )
133 # @CODE
134
135 # @ECLASS-VARIABLE: HTML_DOCS
136 # @DEFAULT_UNSET
137 # @DESCRIPTION:
138 # An array containing documents installed using dohtml. The files
139 # and directories listed there must exist in the directory from which
140 # distutils-r1_python_install_all() is run (${S} by default).
141 #
142 # If unset, no HTML docs will be installed.
143 #
144 # Example:
145 # @CODE
146 # HTML_DOCS=( doc/html/. )
147 # @CODE
148
149 # @ECLASS-VARIABLE: EXAMPLES
150 # @DEFAULT_UNSET
151 # @DESCRIPTION:
152 # An array containing examples installed into 'examples' doc
153 # subdirectory. The files and directories listed there must exist
154 # in the directory from which distutils-r1_python_install_all() is run
155 # (${S} by default).
156 #
157 # The 'examples' subdirectory will be marked not to be compressed
158 # automatically.
159 #
160 # If unset, no examples will be installed.
161 #
162 # Example:
163 # @CODE
164 # EXAMPLES=( examples/. demos/. )
165 # @CODE
166
167 # @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
168 # @DEFAULT_UNSET
169 # @DESCRIPTION:
170 # If set to a non-null value, in-source builds will be enabled.
171 # If unset, the default is to use in-source builds when python_prepare()
172 # is declared, and out-of-source builds otherwise.
173 #
174 # If in-source builds are used, the eclass will create a copy of package
175 # sources for each Python implementation in python_prepare_all(),
176 # and work on that copy afterwards.
177 #
178 # If out-of-source builds are used, the eclass will instead work
179 # on the sources directly, prepending setup.py arguments with
180 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
181 # files in the specific root.
182
183 # @ECLASS-VARIABLE: DISTUTILS_NO_PARALLEL_BUILD
184 # @DEFAULT_UNSET
185 # @DESCRIPTION:
186 # If set to a non-null value, the parallel build feature will
187 # be disabled.
188 #
189 # When parallel builds are used, the implementation-specific sub-phases
190 # for selected Python implementation will be run in parallel. This will
191 # increase build efficiency with distutils which does not do parallel
192 # builds.
193 #
194 # This variable can be used to disable the afore-mentioned feature
195 # in case it causes issues with the package.
196
197 # @ECLASS-VARIABLE: mydistutilsargs
198 # @DEFAULT_UNSET
199 # @DESCRIPTION:
200 # An array containing options to be passed to setup.py.
201 #
202 # Example:
203 # @CODE
204 # python_configure_all() {
205 # mydistutilsargs=( --enable-my-hidden-option )
206 # }
207 # @CODE
208
209 # @FUNCTION: esetup.py
210 # @USAGE: [<args>...]
211 # @DESCRIPTION:
212 # Run setup.py using currently selected Python interpreter
213 # (if ${PYTHON} is set; fallback 'python' otherwise).
214 #
215 # setup.py will be passed the following, in order:
216 # 1. ${mydistutilsargs[@]}
217 # 2. The 'build' command and standard build options including ${BUILD_DIR}
218 # 3. Any additional arguments passed to the esetup.py function.
219 #
220 # This command dies on failure.
221 esetup.py() {
222 debug-print-function ${FUNCNAME} "${@}"
223
224 local add_args=()
225 if [[ ${BUILD_DIR} ]]; then
226 # if setuptools is used, adjust egg_info path as well
227 # (disabled since it causes build not to install scripts)
228 # if "${PYTHON:-python}" setup.py --help egg_info &>/dev/null; then
229 # add_args+=(
230 # egg_info --egg-base "${BUILD_DIR}"
231 # )
232 # fi
233
234 add_args+=(
235 build
236 --build-base "${BUILD_DIR}"
237
238 # using a single directory for them helps us export
239 # ${PYTHONPATH} and ebuilds find the sources independently
240 # of whether the package installs extensions or not
241 #
242 # note: due to some packages (wxpython) relying on separate
243 # platlib & purelib dirs, we do not set --build-lib (which
244 # can not be overriden with --build-*lib)
245 --build-platlib "${BUILD_DIR}/lib"
246 --build-purelib "${BUILD_DIR}/lib"
247
248 # make the ebuild writer lives easier
249 --build-scripts "${BUILD_DIR}/scripts"
250 )
251 elif [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
252 die 'Out-of-source build requested, yet BUILD_DIR unset.'
253 fi
254
255 set -- "${PYTHON:-python}" setup.py \
256 "${mydistutilsargs[@]}" "${add_args[@]}" "${@}"
257
258 echo "${@}" >&2
259 "${@}" || die
260 }
261
262 # @FUNCTION: distutils_install_for_testing
263 # @USAGE: [<args>...]
264 # @DESCRIPTION:
265 # Install the package into a temporary location for running tests.
266 # Update PYTHONPATH appropriately and set TEST_DIR to the test
267 # installation root. The Python packages will be installed in 'lib'
268 # subdir, and scripts in 'scripts' subdir (like in BUILD_DIR).
269 #
270 # Please note that this function should be only used if package uses
271 # namespaces (and therefore proper install needs to be done to enforce
272 # PYTHONPATH) or tests rely on the results of install command.
273 # For most of the packages, tests built in BUILD_DIR are good enough.
274 distutils_install_for_testing() {
275 debug-print-function ${FUNCNAME} "${@}"
276
277 # A few notes:
278 # 1) because of namespaces, we can't use 'install --root',
279 # 2) 'install --home' is terribly broken on pypy, so we need
280 # to override --install-lib and --install-scripts,
281 # 3) non-root 'install' complains about PYTHONPATH and missing dirs,
282 # so we need to set it properly and mkdir them,
283 # 4) it runs a bunch of commands which write random files to cwd,
284 # in order to avoid that, we need to run them ourselves to pass
285 # alternate build paths,
286 # 5) 'install' needs to go before 'bdist_egg' or the latter would
287 # re-set install paths.
288
289 TEST_DIR=${BUILD_DIR}/test
290 local bindir=${TEST_DIR}/scripts
291 local libdir=${TEST_DIR}/lib
292 PYTHONPATH=${libdir}:${PYTHONPATH}
293
294 local add_args=(
295 install
296 --home="${TEST_DIR}"
297 --install-lib="${libdir}"
298 --install-scripts="${bindir}"
299 )
300
301 if "${PYTHON:-python}" setup.py --help bdist_egg &>/dev/null; then
302 add_args+=(
303 bdist_egg --dist-dir="${TEST_DIR}"
304 )
305 fi
306
307 mkdir -p "${libdir}" || die
308 esetup.py "${add_args[@]}"
309 }
310
311 # @FUNCTION: distutils-r1_python_prepare_all
312 # @DESCRIPTION:
313 # The default python_prepare_all(). It applies the patches from PATCHES
314 # array, then user patches and finally calls python_copy_sources to
315 # create copies of resulting sources for each Python implementation.
316 #
317 # At some point in the future, it may also apply eclass-specific
318 # distutils patches and/or quirks.
319 distutils-r1_python_prepare_all() {
320 debug-print-function ${FUNCNAME} "${@}"
321
322 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
323
324 epatch_user
325
326 # by default, use in-source build if python_prepare() is used
327 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD+1} ]]; then
328 if declare -f python_prepare >/dev/null; then
329 DISTUTILS_IN_SOURCE_BUILD=1
330 fi
331 fi
332
333 if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
334 then
335 # create source copies for each implementation
336 python_copy_sources
337 fi
338 }
339
340 # @FUNCTION: distutils-r1_python_prepare
341 # @DESCRIPTION:
342 # The default python_prepare(). A no-op.
343 distutils-r1_python_prepare() {
344 debug-print-function ${FUNCNAME} "${@}"
345
346 :
347 }
348
349 # @FUNCTION: distutils-r1_python_configure
350 # @DESCRIPTION:
351 # The default python_configure(). A no-op.
352 distutils-r1_python_configure() {
353 debug-print-function ${FUNCNAME} "${@}"
354
355 :
356 }
357
358 # @FUNCTION: distutils-r1_python_compile
359 # @USAGE: [additional-args...]
360 # @DESCRIPTION:
361 # The default python_compile(). Runs 'esetup.py build'. Any parameters
362 # passed to this function will be appended to setup.py invocation,
363 # i.e. passed as options to the 'build' command.
364 distutils-r1_python_compile() {
365 debug-print-function ${FUNCNAME} "${@}"
366
367 esetup.py "${@}"
368 }
369
370 # @FUNCTION: distutils-r1_python_test
371 # @DESCRIPTION:
372 # The default python_test(). A no-op.
373 distutils-r1_python_test() {
374 debug-print-function ${FUNCNAME} "${@}"
375
376 :
377 }
378
379 # @FUNCTION: _distutils-r1_rename_scripts
380 # @USAGE: <path>
381 # @INTERNAL
382 # @DESCRIPTION:
383 # Renames installed Python scripts to be implementation-suffixed.
384 # ${EPYTHON} needs to be set to the implementation name.
385 #
386 # All executable scripts having shebang referencing ${EPYTHON}
387 # in given path will be renamed.
388 _distutils-r1_rename_scripts() {
389 debug-print-function ${FUNCNAME} "${@}"
390
391 local path=${1}
392 [[ ${path} ]] || die "${FUNCNAME}: no path given"
393
394 local f
395 while IFS= read -r -d '' f; do
396 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
397
398 if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
399 then
400 debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
401
402 local newf=${f}-${EPYTHON}
403 debug-print "${FUNCNAME}: renaming to ${newf#${D}/}"
404 mv "${f}" "${newf}" || die
405
406 debug-print "${FUNCNAME}: installing wrapper at ${f#${D}/}"
407 _python_ln_rel "${path}${EPREFIX}"/usr/bin/python-exec "${f}" || die
408 fi
409 done < <(find "${path}" -type f -executable -print0)
410 }
411
412 # @FUNCTION: distutils-r1_python_install
413 # @USAGE: [additional-args...]
414 # @DESCRIPTION:
415 # The default python_install(). Runs 'esetup.py install', appending
416 # the optimization flags. Then renames the installed scripts.
417 # Any parameters passed to this function will be appended
418 # to the setup.py invocation (i.e. as options to the 'install' command).
419 distutils-r1_python_install() {
420 debug-print-function ${FUNCNAME} "${@}"
421
422 local flags
423
424 case "${EPYTHON}" in
425 jython*)
426 flags=(--compile);;
427 *)
428 flags=(--compile -O2);;
429 esac
430 debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"
431
432 # enable compilation for the install phase.
433 local PYTHONDONTWRITEBYTECODE
434 export PYTHONDONTWRITEBYTECODE
435
436 # python likes to compile any module it sees, which triggers sandbox
437 # failures if some packages haven't compiled their modules yet.
438 addpredict "$(python_get_sitedir)"
439 addpredict /usr/lib/portage/pym
440
441 local root=${D}/_${EPYTHON}
442 [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D}
443
444 esetup.py install "${flags[@]}" --root="${root}" "${@}"
445
446 if [[ -d ${root}$(python_get_sitedir)/tests ]]; then
447 die "Package installs 'tests' package, file collisions likely."
448 fi
449
450 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
451 _distutils-r1_rename_scripts "${root}"
452 multibuild_merge_root "${root}" "${D}"
453 fi
454 }
455
456 # @FUNCTION: distutils-r1_python_install_all
457 # @DESCRIPTION:
458 # The default python_install_all(). It installs the documentation.
459 distutils-r1_python_install_all() {
460 debug-print-function ${FUNCNAME} "${@}"
461
462 if declare -p DOCS &>/dev/null; then
463 # an empty list == don't install anything
464 if [[ ${DOCS[@]} ]]; then
465 dodoc -r "${DOCS[@]}"
466 fi
467 else
468 local f
469 # same list as in PMS
470 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
471 THANKS BUGS FAQ CREDITS CHANGELOG; do
472 if [[ -s ${f} ]]; then
473 dodoc "${f}"
474 fi
475 done
476 fi
477
478 if declare -p HTML_DOCS &>/dev/null; then
479 dohtml -r "${HTML_DOCS[@]}"
480 fi
481
482 if declare -p EXAMPLES &>/dev/null; then
483 local INSDESTTREE=/usr/share/doc/${PF}/examples
484 doins -r "${EXAMPLES[@]}"
485 docompress -x "${INSDESTTREE}"
486 fi
487 }
488
489 # @FUNCTION: distutils-r1_run_phase
490 # @USAGE: [<argv>...]
491 # @INTERNAL
492 # @DESCRIPTION:
493 # Run the given command.
494 #
495 # If out-of-source builds are used, the phase function is run in source
496 # directory, with BUILD_DIR pointing at the build directory
497 # and PYTHONPATH having an entry for the module build directory.
498 #
499 # If in-source builds are used, the command is executed in the directory
500 # holding the per-implementation copy of sources. BUILD_DIR points
501 # to the 'build' subdirectory.
502 distutils-r1_run_phase() {
503 debug-print-function ${FUNCNAME} "${@}"
504
505 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
506 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
507 pushd "${BUILD_DIR}" >/dev/null || die
508 fi
509 local BUILD_DIR=${BUILD_DIR}/build
510 fi
511 local -x PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
512
513 local TMPDIR=${T}/${EPYTHON}
514
515 mkdir -p "${TMPDIR}" || die
516
517 "${@}"
518
519 if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
520 then
521 popd >/dev/null || die
522 fi
523 }
524
525 # @FUNCTION: _distutils-r1_run_common_phase
526 # @USAGE: [<argv>...]
527 # @INTERNAL
528 # @DESCRIPTION:
529 # Run the given command, restoring the best-implementation state.
530 #
531 # If in-source build is used, the command will be run in the copy
532 # of sources made for the best Python interpreter.
533 _distutils-r1_run_common_phase() {
534 local DISTUTILS_ORIG_BUILD_DIR=${BUILD_DIR}
535
536 local MULTIBUILD_VARIANTS
537 _python_obtain_impls
538
539 multibuild_for_best_variant _python_multibuild_wrapper \
540 distutils-r1_run_phase "${@}"
541 }
542
543 # @FUNCTION: _distutils-r1_run_foreach_impl
544 # @INTERNAL
545 # @DESCRIPTION:
546 # Run the given phase for each implementation if multiple implementations
547 # are enabled, once otherwise.
548 _distutils-r1_run_foreach_impl() {
549 debug-print-function ${FUNCNAME} "${@}"
550
551 set -- distutils-r1_run_phase "${@}"
552
553 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
554 if [[ ${DISTUTILS_NO_PARALLEL_BUILD} || ${DISTUTILS_SINGLE_IMPL} ]]
555 then
556 python_foreach_impl "${@}"
557 else
558 python_parallel_foreach_impl "${@}"
559 fi
560 else
561 if [[ ! ${EPYTHON} ]]; then
562 die "EPYTHON unset, python-single-r1_pkg_setup not called?!"
563 fi
564 local BUILD_DIR=${BUILD_DIR:-${S}}
565 BUILD_DIR=${BUILD_DIR%%/}_${EPYTHON}
566
567 "${@}"
568 fi
569 }
570
571 distutils-r1_src_prepare() {
572 debug-print-function ${FUNCNAME} "${@}"
573
574 # common preparations
575 if declare -f python_prepare_all >/dev/null; then
576 python_prepare_all
577 else
578 distutils-r1_python_prepare_all
579 fi
580
581 if declare -f python_prepare >/dev/null; then
582 _distutils-r1_run_foreach_impl python_prepare
583 fi
584 }
585
586 distutils-r1_src_configure() {
587 if declare -f python_configure >/dev/null; then
588 _distutils-r1_run_foreach_impl python_configure
589 fi
590
591 if declare -f python_configure_all >/dev/null; then
592 _distutils-r1_run_common_phase python_configure_all
593 fi
594 }
595
596 distutils-r1_src_compile() {
597 debug-print-function ${FUNCNAME} "${@}"
598
599 if declare -f python_compile >/dev/null; then
600 _distutils-r1_run_foreach_impl python_compile
601 else
602 _distutils-r1_run_foreach_impl distutils-r1_python_compile
603 fi
604
605 if declare -f python_compile_all >/dev/null; then
606 _distutils-r1_run_common_phase python_compile_all
607 fi
608 }
609
610 distutils-r1_src_test() {
611 debug-print-function ${FUNCNAME} "${@}"
612
613 if declare -f python_test >/dev/null; then
614 _distutils-r1_run_foreach_impl python_test
615 fi
616
617 if declare -f python_test_all >/dev/null; then
618 _distutils-r1_run_common_phase python_test_all
619 fi
620 }
621
622 distutils-r1_src_install() {
623 debug-print-function ${FUNCNAME} "${@}"
624
625 if declare -f python_install >/dev/null; then
626 _distutils-r1_run_foreach_impl python_install
627 else
628 _distutils-r1_run_foreach_impl distutils-r1_python_install
629 fi
630
631 if declare -f python_install_all >/dev/null; then
632 _distutils-r1_run_common_phase python_install_all
633 else
634 _distutils-r1_run_common_phase distutils-r1_python_install_all
635 fi
636 }
637
638 _DISTUTILS_R1=1
639 fi

  ViewVC Help
Powered by ViewVC 1.1.20