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

Contents of /eclass/python-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.75 - (show annotations) (download)
Sun Jul 6 14:41:17 2014 UTC (2 years, 1 month ago) by mgorny
Branch: MAIN
Changes since 1.74: +9 -7 lines
python_gen_cond_dep: delay PYTHON_USEDEP substitution until one of the implementations is actually enabled. Fixes bug #516520.

1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.74 2014/06/19 08:08:10 mgorny Exp $
4
5 # @ECLASS: python-r1
6 # @MAINTAINER:
7 # Python team <python@gentoo.org>
8 # @AUTHOR:
9 # Author: Michał Górny <mgorny@gentoo.org>
10 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @BLURB: A common, simple eclass for Python packages.
12 # @DESCRIPTION:
13 # A common eclass providing helper functions to build and install
14 # packages supporting being installed for multiple Python
15 # implementations.
16 #
17 # This eclass sets correct IUSE and REQUIRED_USE. It exports PYTHON_DEPS
18 # and PYTHON_USEDEP so you can create correct dependencies for your
19 # package easily. It also provides methods to easily run a command for
20 # each enabled Python implementation and duplicate the sources for them.
21 #
22 # Please note that python-r1 will always inherit python-utils-r1 as
23 # well. Thus, all the functions defined there can be used
24 # in the packages using python-r1, and there is no need ever to inherit
25 # both.
26 #
27 # For more information, please see the python-r1 Developer's Guide:
28 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
29
30 case "${EAPI:-0}" in
31 0|1|2|3)
32 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
33 ;;
34 4|5)
35 # EAPI=4 is required for USE default deps on USE_EXPAND flags
36 ;;
37 *)
38 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
39 ;;
40 esac
41
42 if [[ ! ${_PYTHON_R1} ]]; then
43
44 if [[ ${_PYTHON_SINGLE_R1} ]]; then
45 die 'python-r1.eclass can not be used with python-single-r1.eclass.'
46 elif [[ ${_PYTHON_ANY_R1} ]]; then
47 die 'python-r1.eclass can not be used with python-any-r1.eclass.'
48 fi
49
50 inherit multibuild python-utils-r1
51
52 # @ECLASS-VARIABLE: PYTHON_COMPAT
53 # @REQUIRED
54 # @DESCRIPTION:
55 # This variable contains a list of Python implementations the package
56 # supports. It must be set before the `inherit' call. It has to be
57 # an array.
58 #
59 # Example:
60 # @CODE
61 # PYTHON_COMPAT=( python2_5 python2_6 python2_7 )
62 # @CODE
63 #
64 # Please note that you can also use bash brace expansion if you like:
65 # @CODE
66 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
67 # @CODE
68 if ! declare -p PYTHON_COMPAT &>/dev/null; then
69 die 'PYTHON_COMPAT not declared.'
70 fi
71
72 # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
73 # @INTERNAL
74 # @DESCRIPTION:
75 # This variable can be used when working with ebuilds to override
76 # the in-ebuild PYTHON_COMPAT. It is a string listing all
77 # the implementations which package will be built for. It need be
78 # specified in the calling environment, and not in ebuilds.
79 #
80 # It should be noted that in order to preserve metadata immutability,
81 # PYTHON_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
82 # The state of PYTHON_TARGETS is ignored, and all the implementations
83 # in PYTHON_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
84 # manually.
85 #
86 # Example:
87 # @CODE
88 # PYTHON_COMPAT_OVERRIDE='pypy python3_3' emerge -1v dev-python/foo
89 # @CODE
90
91 # @ECLASS-VARIABLE: PYTHON_REQ_USE
92 # @DEFAULT_UNSET
93 # @DESCRIPTION:
94 # The list of USEflags required to be enabled on the chosen Python
95 # implementations, formed as a USE-dependency string. It should be valid
96 # for all implementations in PYTHON_COMPAT, so it may be necessary to
97 # use USE defaults.
98 #
99 # This should be set before calling `inherit'.
100 #
101 # Example:
102 # @CODE
103 # PYTHON_REQ_USE="gdbm,ncurses(-)?"
104 # @CODE
105 #
106 # It will cause the Python dependencies to look like:
107 # @CODE
108 # python_targets_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
109 # @CODE
110
111 # @ECLASS-VARIABLE: PYTHON_DEPS
112 # @DESCRIPTION:
113 # This is an eclass-generated Python dependency string for all
114 # implementations listed in PYTHON_COMPAT.
115 #
116 # Example use:
117 # @CODE
118 # RDEPEND="${PYTHON_DEPS}
119 # dev-foo/mydep"
120 # DEPEND="${RDEPEND}"
121 # @CODE
122 #
123 # Example value:
124 # @CODE
125 # dev-lang/python-exec:=
126 # python_targets_python2_6? ( dev-lang/python:2.6[gdbm] )
127 # python_targets_python2_7? ( dev-lang/python:2.7[gdbm] )
128 # @CODE
129
130 # @ECLASS-VARIABLE: PYTHON_USEDEP
131 # @DESCRIPTION:
132 # This is an eclass-generated USE-dependency string which can be used to
133 # depend on another Python package being built for the same Python
134 # implementations.
135 #
136 # The generate USE-flag list is compatible with packages using python-r1
137 # and python-distutils-ng eclasses. It must not be used on packages
138 # using python.eclass.
139 #
140 # Example use:
141 # @CODE
142 # RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
143 # @CODE
144 #
145 # Example value:
146 # @CODE
147 # python_targets_python2_6(-)?,python_targets_python2_7(-)?
148 # @CODE
149
150 # @ECLASS-VARIABLE: PYTHON_REQUIRED_USE
151 # @DESCRIPTION:
152 # This is an eclass-generated required-use expression which ensures at
153 # least one Python implementation has been enabled.
154 #
155 # This expression should be utilized in an ebuild by including it in
156 # REQUIRED_USE, optionally behind a use flag.
157 #
158 # Example use:
159 # @CODE
160 # REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
161 # @CODE
162 #
163 # Example value:
164 # @CODE
165 # || ( python_targets_python2_6 python_targets_python2_7 )
166 # @CODE
167
168 _python_set_globals() {
169 local impls=()
170
171 PYTHON_DEPS=
172 local i PYTHON_PKG_DEP
173 for i in "${PYTHON_COMPAT[@]}"; do
174 _python_impl_supported "${i}" || continue
175
176 python_export "${i}" PYTHON_PKG_DEP
177 PYTHON_DEPS+="python_targets_${i}? ( ${PYTHON_PKG_DEP} ) "
178
179 impls+=( "${i}" )
180 done
181
182 if [[ ${#impls[@]} -eq 0 ]]; then
183 die "No supported implementation in PYTHON_COMPAT."
184 fi
185
186 local flags=( "${impls[@]/#/python_targets_}" )
187 local optflags=${flags[@]/%/(-)?}
188
189 # A nice QA trick here. Since a python-single-r1 package has to have
190 # at least one PYTHON_SINGLE_TARGET enabled (REQUIRED_USE),
191 # the following check will always fail on those packages. Therefore,
192 # it should prevent developers from mistakenly depending on packages
193 # not supporting multiple Python implementations.
194
195 local flags_st=( "${impls[@]/#/-python_single_target_}" )
196 optflags+=,${flags_st[@]/%/(-)}
197
198 IUSE=${flags[*]}
199 PYTHON_REQUIRED_USE="|| ( ${flags[*]} )"
200 PYTHON_USEDEP=${optflags// /,}
201
202 # 1) well, python-exec would suffice as an RDEP
203 # but no point in making this overcomplex, BDEP doesn't hurt anyone
204 # 2) python-exec should be built with all targets forced anyway
205 # but if new targets were added, we may need to force a rebuild
206 # 3) use whichever python-exec slot installed in EAPI 5. For EAPI 4,
207 # just fix :2 since := deps are not supported.
208 if [[ ${_PYTHON_WANT_PYTHON_EXEC2} == 0 ]]; then
209 PYTHON_DEPS+="dev-lang/python-exec:0[${PYTHON_USEDEP}]"
210 elif [[ ${EAPI} != 4 ]]; then
211 PYTHON_DEPS+="dev-lang/python-exec:=[${PYTHON_USEDEP}]"
212 else
213 PYTHON_DEPS+="dev-lang/python-exec:2[${PYTHON_USEDEP}]"
214 fi
215 }
216 _python_set_globals
217
218 # @ECLASS-VARIABLE: DISTUTILS_JOBS
219 # @DEFAULT_UNSET
220 # @DESCRIPTION:
221 # The number of parallel jobs to run for distutils-r1 parallel builds.
222 # If unset, the job-count in ${MAKEOPTS} will be used.
223 #
224 # This variable is intended to be set in make.conf.
225
226 # @FUNCTION: _python_validate_useflags
227 # @INTERNAL
228 # @DESCRIPTION:
229 # Enforce the proper setting of PYTHON_TARGETS.
230 _python_validate_useflags() {
231 debug-print-function ${FUNCNAME} "${@}"
232
233 local i
234
235 for i in "${PYTHON_COMPAT[@]}"; do
236 _python_impl_supported "${i}" || continue
237
238 use "python_targets_${i}" && return 0
239 done
240
241 eerror "No Python implementation selected for the build. Please add one"
242 eerror "of the following values to your PYTHON_TARGETS (in make.conf):"
243 eerror
244 eerror "${PYTHON_COMPAT[@]}"
245 echo
246 die "No supported Python implementation in PYTHON_TARGETS."
247 }
248
249 # @FUNCTION: python_gen_usedep
250 # @USAGE: <pattern> [...]
251 # @DESCRIPTION:
252 # Output a USE dependency string for Python implementations which
253 # are both in PYTHON_COMPAT and match any of the patterns passed
254 # as parameters to the function.
255 #
256 # Remember to escape or quote the patterns to premature evaluation as a file
257 # name glob.
258 #
259 # When all implementations are requested, please use ${PYTHON_USEDEP}
260 # instead. Please also remember to set an appropriate REQUIRED_USE
261 # to avoid ineffective USE flags.
262 #
263 # Example:
264 # @CODE
265 # PYTHON_COMPAT=( python{2_7,3_2} )
266 # DEPEND="doc? ( dev-python/epydoc[$(python_gen_usedep 'python2*')] )"
267 # @CODE
268 #
269 # It will cause the dependency to look like:
270 # @CODE
271 # DEPEND="doc? ( dev-python/epydoc[python_targets_python2_7?] )"
272 # @CODE
273 python_gen_usedep() {
274 debug-print-function ${FUNCNAME} "${@}"
275
276 local impl pattern
277 local matches=()
278
279 for impl in "${PYTHON_COMPAT[@]}"; do
280 _python_impl_supported "${impl}" || continue
281
282 for pattern; do
283 if [[ ${impl} == ${pattern} ]]; then
284 matches+=(
285 "python_targets_${impl}(-)?"
286 "-python_single_target_${impl}(-)"
287 )
288 break
289 fi
290 done
291 done
292
293 [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}"
294
295 local out=${matches[@]}
296 echo ${out// /,}
297 }
298
299 # @FUNCTION: python_gen_useflags
300 # @USAGE: <pattern> [...]
301 # @DESCRIPTION:
302 # Output a list of USE flags for Python implementations which
303 # are both in PYTHON_COMPAT and match any of the patterns passed
304 # as parameters to the function.
305 #
306 # Example:
307 # @CODE
308 # PYTHON_COMPAT=( python{2_7,3_2} )
309 # REQUIRED_USE="doc? ( || ( $(python_gen_useflags python2*) ) )"
310 # @CODE
311 #
312 # It will cause the variable to look like:
313 # @CODE
314 # REQUIRED_USE="doc? ( || ( python_targets_python2_7 ) )"
315 # @CODE
316 python_gen_useflags() {
317 debug-print-function ${FUNCNAME} "${@}"
318
319 local impl pattern
320 local matches=()
321
322 for impl in "${PYTHON_COMPAT[@]}"; do
323 _python_impl_supported "${impl}" || continue
324
325 for pattern; do
326 if [[ ${impl} == ${pattern} ]]; then
327 matches+=( "python_targets_${impl}" )
328 break
329 fi
330 done
331 done
332
333 echo ${matches[@]}
334 }
335
336 # @FUNCTION: python_gen_cond_dep
337 # @USAGE: <dependency> <pattern> [...]
338 # @DESCRIPTION:
339 # Output a list of <dependency>-ies made conditional to USE flags
340 # of Python implementations which are both in PYTHON_COMPAT and match
341 # any of the patterns passed as the remaining parameters.
342 #
343 # In order to enforce USE constraints on the packages, verbatim
344 # '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency
345 # specification. It will get expanded within the function into a proper
346 # USE dependency string.
347 #
348 # Example:
349 # @CODE
350 # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
351 # RDEPEND="$(python_gen_cond_dep \
352 # 'dev-python/unittest2[${PYTHON_USEDEP}]' python{2_5,2_6})"
353 # @CODE
354 #
355 # It will cause the variable to look like:
356 # @CODE
357 # RDEPEND="python_targets_python2_5? (
358 # dev-python/unittest2[python_targets_python2_5?] )
359 # python_targets_python2_6? (
360 # dev-python/unittest2[python_targets_python2_6?] )"
361 # @CODE
362 python_gen_cond_dep() {
363 debug-print-function ${FUNCNAME} "${@}"
364
365 local impl pattern
366 local matches=()
367
368 local dep=${1}
369 shift
370
371 for impl in "${PYTHON_COMPAT[@]}"; do
372 _python_impl_supported "${impl}" || continue
373
374 for pattern; do
375 if [[ ${impl} == ${pattern} ]]; then
376 # substitute ${PYTHON_USEDEP} if used
377 # (since python_gen_usedep() will not return ${PYTHON_USEDEP}
378 # the code is run at most once)
379 if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then
380 local PYTHON_USEDEP=$(python_gen_usedep "${@}")
381 dep=${dep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
382 fi
383
384 matches+=( "python_targets_${impl}? ( ${dep} )" )
385 break
386 fi
387 done
388 done
389
390 echo ${matches[@]}
391 }
392
393 # @ECLASS-VARIABLE: BUILD_DIR
394 # @DESCRIPTION:
395 # The current build directory. In global scope, it is supposed to
396 # contain an initial build directory; if unset, it defaults to ${S}.
397 #
398 # In functions run by python_foreach_impl(), the BUILD_DIR is locally
399 # set to an implementation-specific build directory. That path is
400 # created through appending a hyphen and the implementation name
401 # to the final component of the initial BUILD_DIR.
402 #
403 # Example value:
404 # @CODE
405 # ${WORKDIR}/foo-1.3-python2_6
406 # @CODE
407
408 # @FUNCTION: python_copy_sources
409 # @DESCRIPTION:
410 # Create a single copy of the package sources for each enabled Python
411 # implementation.
412 #
413 # The sources are always copied from initial BUILD_DIR (or S if unset)
414 # to implementation-specific build directory matching BUILD_DIR used by
415 # python_foreach_abi().
416 python_copy_sources() {
417 debug-print-function ${FUNCNAME} "${@}"
418
419 local MULTIBUILD_VARIANTS
420 _python_obtain_impls
421
422 multibuild_copy_sources
423 }
424
425 # @FUNCTION: _python_check_USE_PYTHON
426 # @INTERNAL
427 # @DESCRIPTION:
428 # Check whether USE_PYTHON and PYTHON_TARGETS are in sync. Output
429 # warnings if they are not.
430 _python_check_USE_PYTHON() {
431 debug-print-function ${FUNCNAME} "${@}"
432
433 if [[ ! ${_PYTHON_USE_PYTHON_CHECKED} ]]; then
434 _PYTHON_USE_PYTHON_CHECKED=1
435
436 # python-exec has profile-forced flags.
437 if [[ ${CATEGORY}/${PN} == dev-lang/python-exec ]]; then
438 return
439 fi
440
441 _try_eselect() {
442 # The eselect solution will work only with one py2 & py3.
443
444 local impl py2 py3 dis_py2 dis_py3
445 for impl in "${PYTHON_COMPAT[@]}"; do
446 _python_impl_supported "${impl}" || continue
447
448 if use "python_targets_${impl}"; then
449 case "${impl}" in
450 python2_*)
451 if [[ ${py2+1} ]]; then
452 debug-print "${FUNCNAME}: -> more than one py2: ${py2} ${impl}"
453 return 1
454 fi
455 py2=${impl/_/.}
456 ;;
457 python3_4)
458 debug-print "${FUNCNAME}: python3.4 found, not using eselect"
459 return 1
460 ;;
461 python3_*)
462 if [[ ${py3+1} ]]; then
463 debug-print "${FUNCNAME}: -> more than one py3: ${py3} ${impl}"
464 return 1
465 fi
466 py3=${impl/_/.}
467 ;;
468 *)
469 return 1
470 ;;
471 esac
472 else
473 case "${impl}" in
474 python2_*)
475 dis_py2=1
476 ;;
477 python3_*)
478 dis_py3=1
479 ;;
480 esac
481 fi
482 done
483
484 # The eselect solution won't work if the disabled Python version
485 # is installed.
486 if [[ ! ${py2+1} && ${dis_py2} ]]; then
487 debug-print "${FUNCNAME}: -> all py2 versions disabled"
488 if ! has python2_7 "${PYTHON_COMPAT[@]}"; then
489 debug-print "${FUNCNAME}: ---> package does not support 2.7"
490 return 0
491 fi
492 if has_version '=dev-lang/python-2*'; then
493 debug-print "${FUNCNAME}: ---> but =python-2* installed!"
494 return 1
495 fi
496 fi
497 if [[ ! ${py3+1} && ${dis_py3} ]]; then
498 debug-print "${FUNCNAME}: -> all py3 versions disabled"
499 if ! has python3_2 "${PYTHON_COMPAT[@]}"; then
500 debug-print "${FUNCNAME}: ---> package does not support 3.2"
501 return 0
502 fi
503 if has_version '=dev-lang/python-3*'; then
504 debug-print "${FUNCNAME}: ---> but =python-3* installed!"
505 return 1
506 fi
507 fi
508
509 local warned
510
511 # Now check whether the correct implementations are active.
512 if [[ ${py2+1} ]]; then
513 local sel_py2=$(eselect python show --python2)
514
515 debug-print "${FUNCNAME}: -> py2 built: ${py2}, active: ${sel_py2}"
516 if [[ ${py2} != ${sel_py2} ]]; then
517 ewarn "Building package for ${py2} only while ${sel_py2} is active."
518 ewarn "Please consider switching the active Python 2 interpreter:"
519 ewarn
520 ewarn " eselect python set --python2 ${py2}"
521 warned=1
522 fi
523 fi
524
525
526 if [[ ${py3+1} ]]; then
527 local sel_py3=$(eselect python show --python3)
528
529 debug-print "${FUNCNAME}: -> py3 built: ${py3}, active: ${sel_py3}"
530 if [[ ${py3} != ${sel_py3} ]]; then
531 [[ ${warned} ]] && ewarn
532 ewarn "Building package for ${py3} only while ${sel_py3} is active."
533 ewarn "Please consider switching the active Python 3 interpreter:"
534 ewarn
535 ewarn " eselect python set --python3 ${py3}"
536 warned=1
537 fi
538 fi
539
540 if [[ ${warned} ]]; then
541 ewarn
542 ewarn "Please note that after switching the active Python interpreter,"
543 ewarn "you may need to run 'python-updater' to rebuild affected packages."
544 ewarn
545 ewarn "For more information on PYTHON_TARGETS and python.eclass"
546 ewarn "compatibility, please see the relevant Wiki article [1]."
547 ewarn
548 ewarn "[1] https://wiki.gentoo.org/wiki/Project:Python/PYTHON_TARGETS"
549 fi
550 }
551
552 # If user has no USE_PYTHON, try to avoid it.
553 if [[ ! ${USE_PYTHON} ]]; then
554 debug-print "${FUNCNAME}: trying eselect solution ..."
555 _try_eselect && return
556 fi
557
558 debug-print "${FUNCNAME}: trying USE_PYTHON solution ..."
559 debug-print "${FUNCNAME}: -> USE_PYTHON=${USE_PYTHON}"
560
561 local impl old=${USE_PYTHON} new=() removed=()
562
563 for impl in "${PYTHON_COMPAT[@]}"; do
564 _python_impl_supported "${impl}" || continue
565
566 local abi
567 case "${impl}" in
568 pypy|python3_4)
569 # unsupported in python.eclass
570 continue
571 ;;
572 python*)
573 abi=${impl#python}
574 ;;
575 jython*)
576 abi=${impl#jython}-jython
577 ;;
578 *)
579 die "Unexpected Python implementation: ${impl}"
580 ;;
581 esac
582 abi=${abi/_/.}
583
584 has "${abi}" ${USE_PYTHON}
585 local has_abi=${?}
586 use "python_targets_${impl}"
587 local has_impl=${?}
588
589 # 0 = has, 1 = does not have
590 if [[ ${has_abi} == 0 && ${has_impl} == 1 ]]; then
591 debug-print "${FUNCNAME}: ---> remove ${abi}"
592 # remove from USE_PYTHON
593 old=${old/${abi}/}
594 removed+=( ${abi} )
595 elif [[ ${has_abi} == 1 && ${has_impl} == 0 ]]; then
596 debug-print "${FUNCNAME}: ---> add ${abi}"
597 # add to USE_PYTHON
598 new+=( ${abi} )
599 fi
600 done
601
602 if [[ ${removed[@]} || ${new[@]} ]]; then
603 old=( ${old} )
604
605 debug-print "${FUNCNAME}: -> old: ${old[@]}"
606 debug-print "${FUNCNAME}: -> new: ${new[@]}"
607 debug-print "${FUNCNAME}: -> removed: ${removed[@]}"
608
609 if [[ ${USE_PYTHON} ]]; then
610 ewarn "It seems that your USE_PYTHON setting lists different Python"
611 ewarn "implementations than your PYTHON_TARGETS variable. Please consider"
612 ewarn "using the following value instead:"
613 ewarn
614 ewarn " USE_PYTHON='\033[35m${old[@]}${new[@]+ \033[1m${new[@]}}\033[0m'"
615
616 if [[ ${removed[@]} ]]; then
617 ewarn
618 ewarn "(removed \033[31m${removed[@]}\033[0m)"
619 fi
620 else
621 ewarn "It seems that you need to set USE_PYTHON to make sure that legacy"
622 ewarn "packages will be built with respect to PYTHON_TARGETS correctly:"
623 ewarn
624 ewarn " USE_PYTHON='\033[35;1m${new[@]}\033[0m'"
625 fi
626
627 ewarn
628 ewarn "Please note that after changing the USE_PYTHON variable, you may need"
629 ewarn "to run 'python-updater' to rebuild affected packages."
630 ewarn
631 ewarn "For more information on PYTHON_TARGETS and python.eclass"
632 ewarn "compatibility, please see the relevant Wiki article [1]."
633 ewarn
634 ewarn "[1] https://wiki.gentoo.org/wiki/Project:Python/PYTHON_TARGETS"
635 fi
636 fi
637 }
638
639 # @FUNCTION: _python_obtain_impls
640 # @INTERNAL
641 # @DESCRIPTION:
642 # Set up the enabled implementation list.
643 _python_obtain_impls() {
644 if [[ ${PYTHON_COMPAT_OVERRIDE} ]]; then
645 if [[ ! ${_PYTHON_COMPAT_OVERRIDE_WARNED} ]]; then
646 ewarn "WARNING: PYTHON_COMPAT_OVERRIDE in effect. The following Python"
647 ewarn "implementations will be enabled:"
648 ewarn
649 ewarn " ${PYTHON_COMPAT_OVERRIDE}"
650 ewarn
651 ewarn "Dependencies won't be satisfied, and PYTHON_TARGETS will be ignored."
652 _PYTHON_COMPAT_OVERRIDE_WARNED=1
653 fi
654
655 MULTIBUILD_VARIANTS=( ${PYTHON_COMPAT_OVERRIDE} )
656 return
657 fi
658
659 _python_validate_useflags
660 _python_check_USE_PYTHON
661
662 MULTIBUILD_VARIANTS=()
663
664 for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
665 if has "${impl}" "${PYTHON_COMPAT[@]}" \
666 && use "python_targets_${impl}"
667 then
668 MULTIBUILD_VARIANTS+=( "${impl}" )
669 fi
670 done
671 }
672
673 # @FUNCTION: _python_multibuild_wrapper
674 # @USAGE: <command> [<args>...]
675 # @INTERNAL
676 # @DESCRIPTION:
677 # Initialize the environment for Python implementation selected
678 # for multibuild.
679 _python_multibuild_wrapper() {
680 debug-print-function ${FUNCNAME} "${@}"
681
682 local -x EPYTHON PYTHON
683 local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
684 python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
685 python_wrapper_setup
686
687 "${@}"
688 }
689
690 # @FUNCTION: python_foreach_impl
691 # @USAGE: <command> [<args>...]
692 # @DESCRIPTION:
693 # Run the given command for each of the enabled Python implementations.
694 # If additional parameters are passed, they will be passed through
695 # to the command.
696 #
697 # The function will return 0 status if all invocations succeed.
698 # Otherwise, the return code from first failing invocation will
699 # be returned.
700 #
701 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
702 # locally, and the former two are exported to the command environment.
703 python_foreach_impl() {
704 debug-print-function ${FUNCNAME} "${@}"
705
706 local MULTIBUILD_VARIANTS
707 _python_obtain_impls
708
709 multibuild_foreach_variant _python_multibuild_wrapper "${@}"
710 }
711
712 # @FUNCTION: python_parallel_foreach_impl
713 # @USAGE: <command> [<args>...]
714 # @DESCRIPTION:
715 # Run the given command for each of the enabled Python implementations.
716 # If additional parameters are passed, they will be passed through
717 # to the command.
718 #
719 # The function will return 0 status if all invocations succeed.
720 # Otherwise, the return code from first failing invocation will
721 # be returned.
722 #
723 # For each command being run, EPYTHON, PYTHON and BUILD_DIR are set
724 # locally, and the former two are exported to the command environment.
725 #
726 # Multiple invocations of the command will be run in parallel, up to
727 # DISTUTILS_JOBS (defaulting to '-j' option argument from MAKEOPTS).
728 python_parallel_foreach_impl() {
729 debug-print-function ${FUNCNAME} "${@}"
730
731 local MULTIBUILD_JOBS=${MULTIBUILD_JOBS:-${DISTUTILS_JOBS}}
732 local MULTIBUILD_VARIANTS
733 _python_obtain_impls
734 multibuild_parallel_foreach_variant _python_multibuild_wrapper "${@}"
735 }
736
737 # @FUNCTION: python_setup
738 # @DESCRIPTION:
739 # Find the best (most preferred) Python implementation enabled
740 # and set the Python build environment up for it.
741 #
742 # This function needs to be used when Python is being called outside
743 # of python_foreach_impl calls (e.g. for shared processes like doc
744 # building). python_foreach_impl sets up the build environment itself.
745 python_setup() {
746 debug-print-function ${FUNCNAME} "${@}"
747
748 python_export_best
749 python_wrapper_setup
750 }
751
752 # @FUNCTION: python_export_best
753 # @USAGE: [<variable>...]
754 # @DESCRIPTION:
755 # Find the best (most preferred) Python implementation enabled
756 # and export given variables for it. If no variables are provided,
757 # EPYTHON & PYTHON will be exported.
758 python_export_best() {
759 debug-print-function ${FUNCNAME} "${@}"
760
761 [[ ${#} -gt 0 ]] || set -- EPYTHON PYTHON
762
763 local best MULTIBUILD_VARIANTS
764 _python_obtain_impls
765
766 _python_set_best() {
767 best=${MULTIBUILD_VARIANT}
768 }
769 multibuild_for_best_variant _python_set_best
770
771 debug-print "${FUNCNAME}: Best implementation is: ${best}"
772 python_export "${best}" "${@}"
773 python_wrapper_setup
774 }
775
776 # @FUNCTION: python_replicate_script
777 # @USAGE: <path>...
778 # @DESCRIPTION:
779 # Copy the given script to variants for all enabled Python
780 # implementations, then replace it with a symlink to the wrapper.
781 #
782 # All specified files must start with a 'python' shebang. A file not
783 # having a matching shebang will be refused.
784 python_replicate_script() {
785 debug-print-function ${FUNCNAME} "${@}"
786
787 _python_replicate_script() {
788 local _PYTHON_FIX_SHEBANG_QUIET=1
789
790 if _python_want_python_exec2; then
791 local PYTHON_SCRIPTDIR
792 python_export PYTHON_SCRIPTDIR
793
794 (
795 exeinto "${PYTHON_SCRIPTDIR#${EPREFIX}}"
796 doexe "${files[@]}"
797 )
798
799 python_fix_shebang -q \
800 "${files[@]/*\//${D%/}/${PYTHON_SCRIPTDIR}/}"
801 else
802 local f
803 for f in "${files[@]}"; do
804 cp -p "${f}" "${f}-${EPYTHON}" || die
805 done
806
807 python_fix_shebang -q \
808 "${files[@]/%/-${EPYTHON}}"
809 fi
810 }
811
812 local files=( "${@}" )
813 python_foreach_impl _python_replicate_script
814
815 # install the wrappers
816 local f
817 for f; do
818 _python_ln_rel "${ED%/}$(_python_get_wrapper_path)" "${f}" || die
819 done
820 }
821
822 _PYTHON_R1=1
823 fi

  ViewVC Help
Powered by ViewVC 1.1.20