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

Contents of /eclass/distutils-r1.eclass

Parent Directory Parent Directory | Revision Log Revision Log


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

1 mgorny 1.1 # Copyright 1999-2012 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.19 # $Header: /var/cvsroot/gentoo-x86/eclass/distutils-r1.eclass,v 1.18 2012/11/05 15:15:32 mgorny Exp $
4 mgorny 1.1
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 mgorny 1.5 # 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 mgorny 1.19 #
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 mgorny 1.1
47 mgorny 1.19 case "${EAPI:-0}" in
48 mgorny 1.1 0|1|2|3)
49 mgorny 1.19 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
50 mgorny 1.1 ;;
51 mgorny 1.3 4|5)
52 mgorny 1.1 ;;
53     *)
54     die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
55     ;;
56     esac
57    
58 mgorny 1.19 if [[ ! ${_DISTUTILS_R1} ]]; then
59    
60 mgorny 1.1 inherit eutils python-r1
61    
62     EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
63    
64 mgorny 1.11 RDEPEND=${PYTHON_DEPS}
65 mgorny 1.1 DEPEND=${PYTHON_DEPS}
66    
67 mgorny 1.5 # @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 mgorny 1.1 # @ECLASS-VARIABLE: DOCS
84     # @DEFAULT_UNSET
85     # @DESCRIPTION:
86 mgorny 1.5 # 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 mgorny 1.1 #
90 mgorny 1.5 # 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 mgorny 1.1 #
94     # Example:
95     # @CODE
96     # DOCS=( NEWS README )
97     # @CODE
98    
99     # @ECLASS-VARIABLE: HTML_DOCS
100     # @DEFAULT_UNSET
101     # @DESCRIPTION:
102 mgorny 1.5 # 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 mgorny 1.1 #
108     # Example:
109     # @CODE
110     # HTML_DOCS=( doc/html/ )
111     # @CODE
112    
113 mgorny 1.14 # @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 mgorny 1.13 # @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 mgorny 1.14 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 mgorny 1.16 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 mgorny 1.14 fi
166    
167 mgorny 1.13 set -- "${PYTHON:-python}" setup.py \
168 mgorny 1.14 "${args[@]}" "${mydistutilsargs[@]}" "${@}"
169 mgorny 1.13
170     echo "${@}" >&2
171     "${@}" || die
172     }
173    
174 mgorny 1.1 # @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 mgorny 1.5 #
180     # At some point in the future, it may also apply eclass-specific
181     # distutils patches and/or quirks.
182 mgorny 1.1 distutils-r1_python_prepare_all() {
183     debug-print-function ${FUNCNAME} "${@}"
184    
185     [[ ${PATCHES} ]] && epatch "${PATCHES[@]}"
186    
187     epatch_user
188    
189 mgorny 1.14 # 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 mgorny 1.1 }
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 mgorny 1.13 # The default python_compile(). Runs 'esetup.py build'. Any parameters
226     # passed to this function will be passed to setup.py.
227 mgorny 1.1 distutils-r1_python_compile() {
228     debug-print-function ${FUNCNAME} "${@}"
229    
230 mgorny 1.13 esetup.py build "${@}"
231 mgorny 1.1 }
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 mgorny 1.13 # 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 mgorny 1.1 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 mgorny 1.15 # enable compilation for the install phase.
289 mgorny 1.18 local PYTHONDONTWRITEBYTECODE
290     export PYTHONDONTWRITEBYTECODE
291 mgorny 1.1
292 mgorny 1.13 esetup.py install "${flags[@]}" --root="${D}" "${@}"
293 mgorny 1.1
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 mgorny 1.9 local EPYTHON
325     python_export_best EPYTHON
326 mgorny 1.2
327 mgorny 1.10 local f
328     while IFS= read -r -d '' f; do
329     debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
330 mgorny 1.1
331 mgorny 1.10 local wrapf=${f%-${EPYTHON}}
332 mgorny 1.1
333 mgorny 1.10 _python_ln_rel "${ED}"/usr/bin/python-exec "${wrapf}" || die
334     done < <(find "${D}" -type f -executable -name "*-${EPYTHON}" -print0)
335 mgorny 1.1 }
336    
337 mgorny 1.8 # @FUNCTION: distutils-r1_run_phase
338     # @USAGE: [<argv>...]
339     # @INTERNAL
340     # @DESCRIPTION:
341 mgorny 1.17 # 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 mgorny 1.8 distutils-r1_run_phase() {
350     debug-print-function ${FUNCNAME} "${@}"
351    
352 mgorny 1.14 if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
353     pushd "${BUILD_DIR}" &>/dev/null || die
354 mgorny 1.17 else
355     local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
356     export PYTHONPATH
357 mgorny 1.14 fi
358    
359 mgorny 1.8 "${@}" || die "${1} failed."
360 mgorny 1.14
361     if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
362     popd &>/dev/null || die
363     fi
364 mgorny 1.8 }
365    
366 mgorny 1.1 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 mgorny 1.8 python_foreach_impl distutils-r1_run_phase python_prepare
378 mgorny 1.1 else
379 mgorny 1.8 python_foreach_impl distutils-r1_run_phase distutils-r1_python_prepare
380 mgorny 1.1 fi
381     }
382    
383     distutils-r1_src_configure() {
384     if declare -f python_configure >/dev/null; then
385 mgorny 1.8 python_foreach_impl distutils-r1_run_phase python_configure
386 mgorny 1.1 else
387 mgorny 1.8 python_foreach_impl distutils-r1_run_phase distutils-r1_python_configure
388 mgorny 1.1 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 mgorny 1.8 python_foreach_impl distutils-r1_run_phase python_compile
400 mgorny 1.1 else
401 mgorny 1.8 python_foreach_impl distutils-r1_run_phase distutils-r1_python_compile
402 mgorny 1.1 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 mgorny 1.8 python_foreach_impl distutils-r1_run_phase python_test
414 mgorny 1.1 else
415 mgorny 1.8 python_foreach_impl distutils-r1_run_phase distutils-r1_python_test
416 mgorny 1.1 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 mgorny 1.8 python_foreach_impl distutils-r1_run_phase python_install
428 mgorny 1.1 else
429 mgorny 1.8 python_foreach_impl distutils-r1_run_phase distutils-r1_python_install
430 mgorny 1.1 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 mgorny 1.19
439     _DISTUTILS_R1=1
440     fi

  ViewVC Help
Powered by ViewVC 1.1.20