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

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (show annotations) (download)
Sat Nov 24 21:07:14 2012 UTC (21 months ago) by mgorny
Branch: MAIN
Changes since 1.18: +11 -3 lines
Fix EAPI checks, add double- and colliding include guards.

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.18 2012/11/05 15:15:32 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 python-r1
61
62 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
63
64 RDEPEND=${PYTHON_DEPS}
65 DEPEND=${PYTHON_DEPS}
66
67 # @ECLASS-VARIABLE: PATCHES
68 # @DEFAULT_UNSET
69 # @DESCRIPTION:
70 # An array containing patches to be applied to the sources before
71 # copying them.
72 #
73 # If unset, no custom patches will be applied.
74 #
75 # Please note, however, that at some point the eclass may apply
76 # additional distutils patches/quirks independently of this variable.
77 #
78 # Example:
79 # @CODE
80 # PATCHES=( "${FILESDIR}"/${P}-make-gentoo-happy.patch )
81 # @CODE
82
83 # @ECLASS-VARIABLE: DOCS
84 # @DEFAULT_UNSET
85 # @DESCRIPTION:
86 # An array containing documents installed using dodoc. The files listed
87 # there must exist in the directory from which
88 # distutils-r1_python_install_all() is run (${S} by default).
89 #
90 # If unset, the function will instead look up files matching default
91 # filename pattern list (from the Package Manager Specification),
92 # and install those found.
93 #
94 # Example:
95 # @CODE
96 # DOCS=( NEWS README )
97 # @CODE
98
99 # @ECLASS-VARIABLE: HTML_DOCS
100 # @DEFAULT_UNSET
101 # @DESCRIPTION:
102 # An array containing documents installed using dohtml. The files
103 # and directories listed there must exist in the directory from which
104 # distutils-r1_python_install_all() is run (${S} by default).
105 #
106 # If unset, no HTML docs will be installed.
107 #
108 # Example:
109 # @CODE
110 # HTML_DOCS=( doc/html/ )
111 # @CODE
112
113 # @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD
114 # @DEFAULT_UNSET
115 # @DESCRIPTION:
116 # If set to a non-null value, in-source builds will be enabled.
117 # If unset, the default is to use in-source builds when python_prepare()
118 # is declared, and out-of-source builds otherwise.
119 #
120 # If in-source builds are used, the eclass will create a copy of package
121 # sources for each Python implementation in python_prepare_all(),
122 # and work on that copy afterwards.
123 #
124 # If out-of-source builds are used, the eclass will instead work
125 # on the sources directly, prepending setup.py arguments with
126 # 'build --build-base ${BUILD_DIR}' to enforce keeping & using built
127 # files in the specific root.
128
129 # @ECLASS-VARIABLE: mydistutilsargs
130 # @DEFAULT_UNSET
131 # @DESCRIPTION:
132 # An array containing options to be passed to setup.py.
133 #
134 # Example:
135 # @CODE
136 # python_configure_all() {
137 # mydistutilsargs=( --enable-my-hidden-option )
138 # }
139 # @CODE
140
141 # @FUNCTION: esetup.py
142 # @USAGE: [<args>...]
143 # @DESCRIPTION:
144 # Run the setup.py using currently selected Python interpreter
145 # (if ${PYTHON} is set; fallback 'python' otherwise). The setup.py will
146 # be passed default command-line arguments, then ${mydistutilsargs[@]},
147 # then any parameters passed to this command.
148 #
149 # This command dies on failure.
150 esetup.py() {
151 debug-print-function ${FUNCNAME} "${@}"
152
153 local args=()
154 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
155 if [[ ! ${BUILD_DIR} ]]; then
156 die 'Out-of-source build requested, yet BUILD_DIR unset.'
157 fi
158
159 args+=(
160 build
161 --build-base "${BUILD_DIR}"
162 # using a single directory for them helps us export ${PYTHONPATH}
163 --build-lib "${BUILD_DIR}/lib"
164 )
165 fi
166
167 set -- "${PYTHON:-python}" setup.py \
168 "${args[@]}" "${mydistutilsargs[@]}" "${@}"
169
170 echo "${@}" >&2
171 "${@}" || die
172 }
173
174 # @FUNCTION: distutils-r1_python_prepare_all
175 # @DESCRIPTION:
176 # The default python_prepare_all(). It applies the patches from PATCHES
177 # array, then user patches and finally calls python_copy_sources to
178 # create copies of resulting sources for each Python implementation.
179 #
180 # At some point in the future, it may also apply eclass-specific
181 # distutils patches and/or quirks.
182 distutils-r1_python_prepare_all() {
183 debug-print-function ${FUNCNAME} "${@}"
184
185 [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
186
187 epatch_user
188
189 # by default, use in-source build if python_prepare() is used
190 if [[ ! ${DISTUTILS_IN_SOURCE_BUILD+1} ]]; then
191 if declare -f python_prepare >/dev/null; then
192 DISTUTILS_IN_SOURCE_BUILD=1
193 fi
194 fi
195
196 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
197 # create source copies for each implementation
198 python_copy_sources
199 fi
200 }
201
202 # @FUNCTION: distutils-r1_python_prepare
203 # @DESCRIPTION:
204 # The default python_prepare(). Currently it is a no-op
205 # but in the future it may apply implementation-specific quirks
206 # to the build system.
207 distutils-r1_python_prepare() {
208 debug-print-function ${FUNCNAME} "${@}"
209
210 :
211 }
212
213 # @FUNCTION: distutils-r1_python_configure
214 # @DESCRIPTION:
215 # The default python_configure(). Currently a no-op.
216 distutils-r1_python_configure() {
217 debug-print-function ${FUNCNAME} "${@}"
218
219 :
220 }
221
222 # @FUNCTION: distutils-r1_python_compile
223 # @USAGE: [additional-args...]
224 # @DESCRIPTION:
225 # The default python_compile(). Runs 'esetup.py build'. Any parameters
226 # passed to this function will be passed to setup.py.
227 distutils-r1_python_compile() {
228 debug-print-function ${FUNCNAME} "${@}"
229
230 esetup.py build "${@}"
231 }
232
233 # @FUNCTION: distutils-r1_python_test
234 # @DESCRIPTION:
235 # The default python_test(). Currently a no-op.
236 distutils-r1_python_test() {
237 debug-print-function ${FUNCNAME} "${@}"
238
239 :
240 }
241
242 # @FUNCTION: distutils-r1_rename_scripts
243 # @DESCRIPTION:
244 # Renames installed Python scripts to be implementation-suffixed.
245 # ${PYTHON} has to be set to the expected Python executable (which
246 # hashbang will be grepped for), and ${EPYTHON} to the implementation
247 # name (for new name).
248 distutils-r1_rename_scripts() {
249 debug-print-function ${FUNCNAME} "${@}"
250
251 local f
252 # XXX: change this if we ever allow directories in bin/sbin
253 for f in "${D}"/{bin,sbin,usr/bin,usr/sbin}/*; do
254 if [[ -x ${f} ]]; then
255 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
256
257 if [[ "$(head -n 1 "${f}")" == '#!'*${EPYTHON}* ]]
258 then
259 debug-print "${FUNCNAME}: matching shebang: $(head -n 1 "${f}")"
260
261 local newf=${f}-${EPYTHON}
262 debug-print "${FUNCNAME}: renamed to ${newf#${D}/}"
263 mv "${f}" "${newf}" || die
264 fi
265 fi
266 done
267 }
268
269 # @FUNCTION: distutils-r1_python_install
270 # @USAGE: [additional-args...]
271 # @DESCRIPTION:
272 # The default python_install(). Runs 'esetup.py install', appending
273 # the optimization flags. Then calls distutils-r1_rename_scripts.
274 # Any parameters passed to this function will be passed to setup.py.
275 distutils-r1_python_install() {
276 debug-print-function ${FUNCNAME} "${@}"
277
278 local flags
279
280 case "${EPYTHON}" in
281 jython*)
282 flags=(--compile);;
283 *)
284 flags=(--compile -O2);;
285 esac
286 debug-print "${FUNCNAME}: [${EPYTHON}] flags: ${flags}"
287
288 # enable compilation for the install phase.
289 local PYTHONDONTWRITEBYTECODE
290 export PYTHONDONTWRITEBYTECODE
291
292 esetup.py install "${flags[@]}" --root="${D}" "${@}"
293
294 distutils-r1_rename_scripts
295 }
296
297 # @FUNCTION: distutils-r1_python_install_all
298 # @DESCRIPTION:
299 # The default python_install_all(). It symlinks wrappers
300 # for the implementation-suffixed executables and installs
301 # documentation.
302 distutils-r1_python_install_all() {
303 debug-print-function ${FUNCNAME} "${@}"
304
305 if declare -p DOCS &>/dev/null; then
306 dodoc "${DOCS[@]}" || die "dodoc failed"
307 else
308 local f
309 # same list as in PMS
310 for f in README* ChangeLog AUTHORS NEWS TODO CHANGES \
311 THANKS BUGS FAQ CREDITS CHANGELOG; do
312 if [[ -s ${f} ]]; then
313 dodoc "${f}" || die "(default) dodoc ${f} failed"
314 fi
315 done
316 fi
317
318 if declare -p HTML_DOCS &>/dev/null; then
319 dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed"
320 fi
321
322 # note: keep in sync with ...rename_scripts()
323 # also, we assume that each script is installed for all impls
324 local EPYTHON
325 python_export_best EPYTHON
326
327 local f
328 while IFS= read -r -d '' f; do
329 debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
330
331 local wrapf=${f%-${EPYTHON}}
332
333 _python_ln_rel "${ED}"/usr/bin/python-exec "${wrapf}" || die
334 done < <(find "${D}" -type f -executable -name "*-${EPYTHON}" -print0)
335 }
336
337 # @FUNCTION: distutils-r1_run_phase
338 # @USAGE: [<argv>...]
339 # @INTERNAL
340 # @DESCRIPTION:
341 # Run the given command.
342 #
343 # If out-of-source builds are used, the phase function is run in source
344 # directory, with BUILD_DIR pointing at the build directory
345 # and PYTHONPATH having an entry for the module build directory.
346 #
347 # If in-source builds are used, the command is executed in the BUILD_DIR
348 # (the directory holding per-implementation copy of sources).
349 distutils-r1_run_phase() {
350 debug-print-function ${FUNCNAME} "${@}"
351
352 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
353 pushd "${BUILD_DIR}" &>/dev/null || die
354 else
355 local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
356 export PYTHONPATH
357 fi
358
359 "${@}" || die "${1} failed."
360
361 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
362 popd &>/dev/null || die
363 fi
364 }
365
366 distutils-r1_src_prepare() {
367 debug-print-function ${FUNCNAME} "${@}"
368
369 # common preparations
370 if declare -f python_prepare_all >/dev/null; then
371 python_prepare_all
372 else
373 distutils-r1_python_prepare_all
374 fi
375
376 if declare -f python_prepare >/dev/null; then
377 python_foreach_impl distutils-r1_run_phase python_prepare
378 else
379 python_foreach_impl distutils-r1_run_phase distutils-r1_python_prepare
380 fi
381 }
382
383 distutils-r1_src_configure() {
384 if declare -f python_configure >/dev/null; then
385 python_foreach_impl distutils-r1_run_phase python_configure
386 else
387 python_foreach_impl distutils-r1_run_phase distutils-r1_python_configure
388 fi
389
390 if declare -f python_configure_all >/dev/null; then
391 python_configure_all
392 fi
393 }
394
395 distutils-r1_src_compile() {
396 debug-print-function ${FUNCNAME} "${@}"
397
398 if declare -f python_compile >/dev/null; then
399 python_foreach_impl distutils-r1_run_phase python_compile
400 else
401 python_foreach_impl distutils-r1_run_phase distutils-r1_python_compile
402 fi
403
404 if declare -f python_compile_all >/dev/null; then
405 python_compile_all
406 fi
407 }
408
409 distutils-r1_src_test() {
410 debug-print-function ${FUNCNAME} "${@}"
411
412 if declare -f python_test >/dev/null; then
413 python_foreach_impl distutils-r1_run_phase python_test
414 else
415 python_foreach_impl distutils-r1_run_phase distutils-r1_python_test
416 fi
417
418 if declare -f python_test_all >/dev/null; then
419 python_test_all
420 fi
421 }
422
423 distutils-r1_src_install() {
424 debug-print-function ${FUNCNAME} "${@}"
425
426 if declare -f python_install >/dev/null; then
427 python_foreach_impl distutils-r1_run_phase python_install
428 else
429 python_foreach_impl distutils-r1_run_phase distutils-r1_python_install
430 fi
431
432 if declare -f python_install_all >/dev/null; then
433 python_install_all
434 else
435 distutils-r1_python_install_all
436 fi
437 }
438
439 _DISTUTILS_R1=1
440 fi

  ViewVC Help
Powered by ViewVC 1.1.20