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

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (show annotations) (download)
Sun Dec 9 20:56:25 2012 UTC (2 years ago) by mgorny
Branch: MAIN
Changes since 1.30: +2 -2 lines
Fix python-exec symlink generation for Prefix. Thanks to Fabian Groffen for help.

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.30 2012/12/07 22:23:04 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 # For more information, please see the python-r1 Developer's Guide:
45 # http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
46
47 case "${EAPI:-0}" in
48 0|1|2|3)
49 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
50 ;;
51 4|5)
52 ;;
53 *)
54 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
55 ;;
56 esac
57
58 if [[ ! ${_DISTUTILS_R1} ]]; then
59
60 inherit eutils multiprocessing python-r1
61
62 fi
63
64 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
65
66 if [[ ! ${_DISTUTILS_R1} ]]; then
67
68 RDEPEND=${PYTHON_DEPS}
69 DEPEND=${PYTHON_DEPS}
70
71 # @ECLASS-VARIABLE: PATCHES
72 # @DEFAULT_UNSET
73 # @DESCRIPTION:
74 # An array containing patches to be applied to the sources before
75 # copying them.
76 #
77 # If unset, no custom patches will be applied.
78 #
79 # Please note, however, that at some point the eclass may apply
80 # additional distutils patches/quirks independently of this variable.
81 #
82 # Example:
83 # @CODE
84 # PATCHES=( "${FILESDIR}"/${P}-make-gentoo-happy.patch )
85 # @CODE
86
87 # @ECLASS-VARIABLE: DOCS
88 # @DEFAULT_UNSET
89 # @DESCRIPTION:
90 # An array containing documents installed using dodoc. The files listed
91 # there must exist in the directory from which
92 # distutils-r1_python_install_all() is run (${S} by default).
93 #
94 # If unset, the function will instead look up files matching default
95 # filename pattern list (from the Package Manager Specification),
96 # and install those found.
97 #
98 # Example:
99 # @CODE
100 # DOCS=( NEWS README )
101 # @CODE
102
103 # @ECLASS-VARIABLE: HTML_DOCS
104 # @DEFAULT_UNSET
105 # @DESCRIPTION:
106 # An array containing documents installed using dohtml. The files
107 # and directories listed there must exist in the directory from which
108 # distutils-r1_python_install_all() is run (${S} by default).
109 #
110 # If unset, no HTML docs will be installed.
111 #
112 # Example:
113 # @CODE
114 # HTML_DOCS=( doc/html/ )
115 # @CODE
116
117 # @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
118 # @DEFAULT_UNSET
119 # @DESCRIPTION:
120 # If set to a non-null value, in-source builds will be enabled.
121 # If unset, the default is to use in-source builds when python_prepare()
122 # is declared, and out-of-source builds otherwise.
123 #
124 # If in-source builds are used, the eclass will create a copy of package
125 # sources for each Python implementation in python_prepare_all(),
126 # and work on that copy afterwards.
127 #
128 # If out-of-source builds are used, the eclass will instead work
129 # on the sources directly, prepending setup.py arguments with
130 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
131 # files in the specific root.
132
133 # @ECLASS-VARIABLE: DISTUTILS_NO_PARALLEL_BUILD
134 # @DEFAULT_UNSET
135 # @DESCRIPTION:
136 # If set to a non-null value, the parallel build feature will
137 # be disabled.
138 #
139 # When parallel builds are used, the implementation-specific sub-phases
140 # for selected Python implementation will be run in parallel. This will
141 # increase build efficiency with distutils which does not do parallel
142 # builds.
143 #
144 # This variable can be used to disable the afore-mentioned feature
145 # in case it causes issues with the package.
146
147 #
148 # If in-source builds are used, the eclass will create a copy of package
149 # sources for each Python implementation in python_prepare_all(),
150 # and work on that copy afterwards.
151 #
152 # If out-of-source builds are used, the eclass will instead work
153 # on the sources directly, prepending setup.py arguments with
154 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
155 # files in the specific root.
156 # @ECLASS-VARIABLE: mydistutilsargs
157 # @DEFAULT_UNSET
158 # @DESCRIPTION:
159 # An array containing options to be passed to setup.py.
160 #
161 # Example:
162 # @CODE
163 # python_configure_all() {
164 # mydistutilsargs=( --enable-my-hidden-option )
165 # }
166 # @CODE
167
168 # @FUNCTION: esetup.py
169 # @USAGE: [<args>...]
170 # @DESCRIPTION:
171 # Run the setup.py using currently selected Python interpreter
172 # (if ${PYTHON} is set; fallback 'python' otherwise). The setup.py will
173 # be passed default command-line arguments, then ${mydistutilsargs[@]},
174 # then any parameters passed to this command.
175 #
176 # This command dies on failure.
177 esetup.py() {
178 debug-print-function ${FUNCNAME} "${@}"
179
180 local args=()
181 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
182 if [[ ! ${BUILD_DIR} ]]; then
183 die 'Out-of-source build requested, yet BUILD_DIR unset.'
184 fi
185
186 args+=(
187 build
188 --build-base "${BUILD_DIR}"
189 # using a single directory for them helps us export ${PYTHONPATH}
190 --build-lib "${BUILD_DIR}/lib"
191 )
192 fi
193
194 set -- "${PYTHON:-python}" setup.py \
195 "${args[@]}" "${mydistutilsargs[@]}" "${@}"
196
197 echo "${@}" >&2
198 "${@}" || die
199 }
200
201 # @FUNCTION: distutils-r1_python_prepare_all
202 # @DESCRIPTION:
203 # The default python_prepare_all(). It applies the patches from PATCHES
204 # array, then user patches and finally calls python_copy_sources to
205 # create copies of resulting sources for each Python implementation.
206 #
207 # At some point in the future, it may also apply eclass-specific
208 # distutils patches and/or quirks.
209 distutils-r1_python_prepare_all() {
210 debug-print-function ${FUNCNAME} "${@}"
211
212 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
213
214 epatch_user
215
216 # by default, use in-source build if python_prepare() is used
217 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD+1} ]]; then
218 if declare -f python_prepare >/dev/null; then
219 DISTUTILS_IN_SOURCE_BUILD=1
220 fi
221 fi
222
223 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
224 # create source copies for each implementation
225 python_copy_sources
226 fi
227 }
228
229 # @FUNCTION: distutils-r1_python_prepare
230 # @DESCRIPTION:
231 # The default python_prepare(). Currently it is a no-op
232 # but in the future it may apply implementation-specific quirks
233 # to the build system.
234 distutils-r1_python_prepare() {
235 debug-print-function ${FUNCNAME} "${@}"
236
237 :
238 }
239
240 # @FUNCTION: distutils-r1_python_configure
241 # @DESCRIPTION:
242 # The default python_configure(). Currently a no-op.
243 distutils-r1_python_configure() {
244 debug-print-function ${FUNCNAME} "${@}"
245
246 :
247 }
248
249 # @FUNCTION: distutils-r1_python_compile
250 # @USAGE: [additional-args...]
251 # @DESCRIPTION:
252 # The default python_compile(). Runs 'esetup.py build'. Any parameters
253 # passed to this function will be passed to setup.py.
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(). Currently 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 # XXX: change this if we ever allow directories in bin/sbin
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 local root=${D}/_${EPYTHON}
327
328 esetup.py install "${flags[@]}" --root="${root}" "${@}"
329 _distutils-r1_rename_scripts "${root}"
330
331 # merge
332 cp -a -l -n "${root}"/* "${D}"/ || die "Merging ${EPYTHON} image failed."
333 rm -rf "${root}"
334 }
335
336 # @FUNCTION: distutils-r1_python_install_all
337 # @DESCRIPTION:
338 # The default python_install_all(). It installs the documentation.
339 distutils-r1_python_install_all() {
340 debug-print-function ${FUNCNAME} "${@}"
341
342 if declare -p DOCS &>/dev/null; then
343 dodoc "${DOCS[@]}" || die "dodoc failed"
344 else
345 local f
346 # same list as in PMS
347 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
348 THANKS BUGS FAQ CREDITS CHANGELOG; do
349 if [[ -s ${f} ]]; then
350 dodoc "${f}" || die "(default) dodoc ${f} failed"
351 fi
352 done
353 fi
354
355 if declare -p HTML_DOCS &>/dev/null; then
356 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
357 fi
358 }
359
360 # @FUNCTION: distutils-r1_run_phase
361 # @USAGE: [<argv>...]
362 # @INTERNAL
363 # @DESCRIPTION:
364 # Run the given command.
365 #
366 # If out-of-source builds are used, the phase function is run in source
367 # directory, with BUILD_DIR pointing at the build directory
368 # and PYTHONPATH having an entry for the module build directory.
369 #
370 # If in-source builds are used, the command is executed in the BUILD_DIR
371 # (the directory holding per-implementation copy of sources).
372 distutils-r1_run_phase() {
373 debug-print-function ${FUNCNAME} "${@}"
374
375 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
376 pushd "${BUILD_DIR}" &>/dev/null || die
377 else
378 local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
379 export PYTHONPATH
380 fi
381
382 local TMPDIR=${T}/${EPYTHON}
383
384 mkdir -p "${TMPDIR}" || die
385
386 if [[ ${DISTUTILS_NO_PARALLEL_BUILD} ]]; then
387 "${@}"
388 else
389 (
390 multijob_child_init
391 "${@}" 2>&1 | tee -a "${T}/build-${EPYTHON}.log"
392 ) &
393 multijob_post_fork
394 fi
395
396 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
397 popd &>/dev/null || die
398 fi
399
400 # Store them for reuse.
401 _DISTUTILS_BEST_IMPL=(
402 "${EPYTHON}" "${PYTHON}" "${BUILD_DIR}" "${PYTHONPATH}"
403 )
404 }
405
406 # @FUNCTION: _distutils-r1_run_common_phase
407 # @USAGE: [<argv>...]
408 # @INTERNAL
409 # @DESCRIPTION:
410 # Run the given command, restoring the best-implementation state.
411 _distutils-r1_run_common_phase() {
412 local EPYTHON=${_DISTUTILS_BEST_IMPL[0]}
413 local PYTHON=${_DISTUTILS_BEST_IMPL[1]}
414 local BEST_BUILD_DIR=${_DISTUTILS_BEST_IMPL[2]}
415 local PYTHONPATH=${_DISTUTILS_BEST_IMPL[3]}
416
417 export EPYTHON PYTHON PYTHONPATH
418
419 einfo "common: running ${1}"
420 "${@}"
421 }
422
423 distutils-r1_src_prepare() {
424 debug-print-function ${FUNCNAME} "${@}"
425
426 # common preparations
427 if declare -f python_prepare_all >/dev/null; then
428 python_prepare_all
429 else
430 distutils-r1_python_prepare_all
431 fi
432
433 multijob_init
434 if declare -f python_prepare >/dev/null; then
435 python_foreach_impl distutils-r1_run_phase python_prepare
436 else
437 python_foreach_impl distutils-r1_run_phase distutils-r1_python_prepare
438 fi
439 multijob_finish
440 }
441
442 distutils-r1_src_configure() {
443 multijob_init
444 if declare -f python_configure >/dev/null; then
445 python_foreach_impl distutils-r1_run_phase python_configure
446 else
447 python_foreach_impl distutils-r1_run_phase distutils-r1_python_configure
448 fi
449 multijob_finish
450
451 if declare -f python_configure_all >/dev/null; then
452 _distutils-r1_run_common_phase python_configure_all
453 fi
454 }
455
456 distutils-r1_src_compile() {
457 debug-print-function ${FUNCNAME} "${@}"
458
459 multijob_init
460 if declare -f python_compile >/dev/null; then
461 python_foreach_impl distutils-r1_run_phase python_compile
462 else
463 python_foreach_impl distutils-r1_run_phase distutils-r1_python_compile
464 fi
465 multijob_finish
466
467 if declare -f python_compile_all >/dev/null; then
468 _distutils-r1_run_common_phase python_compile_all
469 fi
470 }
471
472 distutils-r1_src_test() {
473 debug-print-function ${FUNCNAME} "${@}"
474
475 multijob_init
476 if declare -f python_test >/dev/null; then
477 python_foreach_impl distutils-r1_run_phase python_test
478 else
479 python_foreach_impl distutils-r1_run_phase distutils-r1_python_test
480 fi
481 multijob_finish
482
483 if declare -f python_test_all >/dev/null; then
484 _distutils-r1_run_common_phase python_test_all
485 fi
486 }
487
488 distutils-r1_src_install() {
489 debug-print-function ${FUNCNAME} "${@}"
490
491 multijob_init
492 if declare -f python_install >/dev/null; then
493 python_foreach_impl distutils-r1_run_phase python_install
494 else
495 python_foreach_impl distutils-r1_run_phase distutils-r1_python_install
496 fi
497 multijob_finish
498
499 if declare -f python_install_all >/dev/null; then
500 _distutils-r1_run_common_phase python_install_all
501 else
502 _distutils-r1_run_common_phase distutils-r1_python_install_all
503 fi
504 }
505
506 _DISTUTILS_R1=1
507 fi

  ViewVC Help
Powered by ViewVC 1.1.20