/[gentoo-x86]/eclass/perl-module.eclass
Gentoo

Contents of /eclass/perl-module.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.166 - (show annotations) (download)
Sat Jun 13 19:01:10 2015 UTC (13 months, 1 week ago) by dilfridge
Branch: MAIN
CVS Tags: HEAD
Changes since 1.165: +3 -3 lines
Allow dev-perl/Module-Build in QA check for Module::Build

1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/perl-module.eclass,v 1.165 2015/05/25 18:18:00 dilfridge Exp $
4
5 # @ECLASS: perl-module.eclass
6 # @MAINTAINER:
7 # perl@gentoo.org
8 # @AUTHOR:
9 # Seemant Kulleen <seemant@gentoo.org>
10 # @BLURB: eclass for perl modules
11 # @DESCRIPTION:
12 # The perl-module eclass is designed to allow easier installation of perl
13 # modules, and their incorporation into the Gentoo Linux system.
14
15 inherit eutils multiprocessing unpacker
16 [[ ${CATEGORY} == "perl-core" ]] && inherit alternatives
17
18 PERL_EXPF="src_unpack src_prepare src_configure src_compile src_test src_install"
19
20 case "${EAPI:-0}" in
21 5)
22 [[ ${CATEGORY} == "perl-core" ]] && \
23 PERL_EXPF+=" pkg_postinst pkg_postrm"
24
25 case "${GENTOO_DEPEND_ON_PERL:-yes}" in
26 yes)
27 case "${GENTOO_DEPEND_ON_PERL_SUBSLOT:-yes}" in
28 yes)
29 DEPEND="dev-lang/perl:=[-build(-)]"
30 ;;
31 *)
32 DEPEND="dev-lang/perl[-build(-)]"
33 ;;
34 esac
35 RDEPEND="${DEPEND}"
36 ;;
37 esac
38 ;;
39 *)
40 die "EAPI=${EAPI} is not supported by perl-module.eclass"
41 ;;
42 esac
43
44 case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
45 yes)
46 EXPORT_FUNCTIONS ${PERL_EXPF}
47 ;;
48 no)
49 debug-print "PERL_EXPORT_PHASE_FUNCTIONS=no"
50 ;;
51 *)
52 die "PERL_EXPORT_PHASE_FUNCTIONS=${PERL_EXPORT_PHASE_FUNCTIONS} is not supported by perl-module.eclass"
53 ;;
54 esac
55
56 LICENSE="${LICENSE:-|| ( Artistic GPL-1+ )}"
57
58 if [[ -n ${MY_PN} || -n ${MY_PV} || -n ${MODULE_VERSION} ]] ; then
59 : ${MY_P:=${MY_PN:-${PN}}-${MY_PV:-${MODULE_VERSION:-${PV}}}}
60 S=${MY_S:-${WORKDIR}/${MY_P}}
61 fi
62
63 [[ -z "${SRC_URI}" && -z "${MODULE_A}" ]] && \
64 MODULE_A="${MY_P:-${P}}.${MODULE_A_EXT:-tar.gz}"
65 [[ -z "${SRC_URI}" && -n "${MODULE_AUTHOR}" ]] && \
66 SRC_URI="mirror://cpan/authors/id/${MODULE_AUTHOR:0:1}/${MODULE_AUTHOR:0:2}/${MODULE_AUTHOR}/${MODULE_SECTION:+${MODULE_SECTION}/}${MODULE_A}"
67 [[ -z "${HOMEPAGE}" ]] && \
68 HOMEPAGE="http://search.cpan.org/dist/${MY_PN:-${PN}}/"
69
70 SRC_PREP="no"
71 SRC_TEST="skip"
72 PREFER_BUILDPL="yes"
73
74 pm_echovar=""
75 perlinfo_done=false
76
77 # @FUNCTION: perl-module_src_unpack
78 # @USAGE: perl-module_src_unpack
79 # @DESCRIPTION:
80 # Unpack the ebuild tarball(s).
81 # This function is to be called during the ebuild src_unpack() phase.
82 perl-module_src_unpack() {
83 debug-print-function $FUNCNAME "$@"
84
85 unpacker_src_unpack
86 }
87
88 # @FUNCTION: perl-module_src_prepare
89 # @USAGE: perl-module_src_prepare
90 # @DESCRIPTION:
91 # Get the ebuild sources ready.
92 # This function is to be called during the ebuild src_prepare() phase.
93 perl-module_src_prepare() {
94 debug-print-function $FUNCNAME "$@"
95 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
96 debug-print "$FUNCNAME: applying user patches"
97 epatch_user
98 if [[ ${PERL_RM_FILES[@]} ]]; then
99 debug-print "$FUNCNAME: stripping unneeded files"
100 perl_rm_files "${PERL_RM_FILES[@]}"
101 fi
102 perl_fix_osx_extra
103 esvn_clean
104 }
105
106 # @FUNCTION: perl-module_src_configure
107 # @USAGE: perl-module_src_configure
108 # @DESCRIPTION:
109 # Configure the ebuild sources.
110 # This function is to be called during the ebuild src_configure() phase.
111 perl-module_src_configure() {
112 debug-print-function $FUNCNAME "$@"
113
114 [[ ${SRC_PREP} = yes ]] && return 0
115 SRC_PREP="yes"
116
117 perl_check_env
118
119 perl_set_version
120
121 [[ -z ${pm_echovar} ]] && export PERL_MM_USE_DEFAULT=1
122 # Disable ExtUtils::AutoInstall from prompting
123 export PERL_EXTUTILS_AUTOINSTALL="--skipdeps"
124
125 if [[ $(declare -p myconf 2>&-) != "declare -a myconf="* ]]; then
126 local myconf_local=(${myconf})
127 else
128 local myconf_local=("${myconf[@]}")
129 fi
130
131 if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
132 if grep -q '\(use\|require\)\s*Module::Build::Tiny' Build.PL ; then
133 einfo "Using Module::Build::Tiny"
134 if [[ ${DEPEND} != *dev-perl/Module-Build-Tiny* && ${PN} != Module-Build-Tiny ]]; then
135 eqawarn "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
136 eqawarn " Add dev-perl/Module-Build-Tiny to DEPEND!"
137 if [[ -n ${PERLQAFATAL} ]]; then
138 eerror "Bailing out due to PERLQAFATAL=1";
139 die
140 fi
141 fi
142 else
143 einfo "Using Module::Build"
144 if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${DEPEND} != *dev-perl/Module-Build* && ${PN} != Module-Build ]] ; then
145 eqawarn "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
146 eqawarn " Add dev-perl/Module-Build to DEPEND!"
147 if [[ -n ${PERLQAFATAL} ]]; then
148 eerror "Bailing out due to PERLQAFATAL=1";
149 die
150 fi
151 fi
152 fi
153 set -- \
154 --installdirs=vendor \
155 --libdoc= \
156 --destdir="${D}" \
157 --create_packlist=0 \
158 "${myconf_local[@]}"
159 einfo "perl Build.PL" "$@"
160 perl Build.PL "$@" <<< "${pm_echovar}" \
161 || die "Unable to build!"
162 elif [[ -f Makefile.PL ]] ; then
163 einfo "Using ExtUtils::MakeMaker"
164 set -- \
165 PREFIX=${EPREFIX}/usr \
166 INSTALLDIRS=vendor \
167 INSTALLMAN3DIR='none' \
168 DESTDIR="${D}" \
169 "${myconf_local[@]}"
170 einfo "perl Makefile.PL" "$@"
171 perl Makefile.PL "$@" <<< "${pm_echovar}" \
172 || die "Unable to build!"
173 fi
174 if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
175 einfo "No Make or Build file detected..."
176 return
177 fi
178 }
179
180 # @FUNCTION: perl-module_src_compile
181 # @USAGE: perl-module_src_compile
182 # @DESCRIPTION:
183 # Compile the ebuild sources.
184 # This function is to be called during the ebuild src_compile() phase.
185 perl-module_src_compile() {
186 debug-print-function $FUNCNAME "$@"
187 perl_set_version
188
189 if [[ $(declare -p mymake 2>&-) != "declare -a mymake="* ]]; then
190 local mymake_local=(${mymake})
191 else
192 local mymake_local=("${mymake[@]}")
193 fi
194
195 if [[ -f Build ]] ; then
196 ./Build build \
197 || die "Compilation failed"
198 elif [[ -f Makefile ]] ; then
199 set -- \
200 OTHERLDFLAGS="${LDFLAGS}" \
201 "${mymake_local[@]}"
202 einfo "emake" "$@"
203 emake "$@" \
204 || die "Compilation failed"
205 # OPTIMIZE="${CFLAGS}" \
206 fi
207 }
208
209 # @FUNCTION: perl-module_src-test
210 # @USAGE: perl-module_src_test()
211 # @DESCRIPTION:
212 # This code attempts to work out your threadingness from MAKEOPTS
213 # and apply them to Test::Harness.
214 #
215 # If you want more verbose testing, set TEST_VERBOSE=1
216 # in your bashrc | /etc/portage/make.conf | ENV
217 #
218 # or ebuild writers:
219 # If you wish to enable default tests w/ 'make test' ,
220 #
221 # SRC_TEST="do"
222 #
223 # If you wish to have threads run in parallel ( using the users makeopts )
224 # all of the following have been tested to work.
225 #
226 # SRC_TEST="do parallel"
227 # SRC_TEST="parallel"
228 # SRC_TEST="parallel do"
229 # SRC_TEST=parallel
230 #
231 perl-module_src_test() {
232 debug-print-function $FUNCNAME "$@"
233 if has 'do' ${SRC_TEST} || has 'parallel' ${SRC_TEST} ; then
234 if has "${TEST_VERBOSE:-0}" 0 && has 'parallel' ${SRC_TEST} ; then
235 export HARNESS_OPTIONS=j$(makeopts_jobs)
236 einfo "Test::Harness Jobs=$(makeopts_jobs)"
237 fi
238 ${perlinfo_done} || perl_set_version
239 if [[ -f Build ]] ; then
240 ./Build test verbose=${TEST_VERBOSE:-0} || die "test failed"
241 elif [[ -f Makefile ]] ; then
242 emake test TEST_VERBOSE=${TEST_VERBOSE:-0} || die "test failed"
243 fi
244 fi
245 }
246
247 # @FUNCTION: perl-module_src_install
248 # @USAGE: perl-module_src_install
249 # @DESCRIPTION:
250 # Install a Perl ebuild.
251 # This function is to be called during the ebuild src_install() phase.
252 perl-module_src_install() {
253 debug-print-function $FUNCNAME "$@"
254
255 perl_set_version
256
257 local f
258
259 if [[ -f Build ]]; then
260 mytargets="${mytargets:-install}"
261 mbparams="${mbparams:---pure}"
262 einfo "./Build ${mytargets} ${mbparams}"
263 ./Build ${mytargets} ${mbparams} \
264 || die "./Build ${mytargets} ${mbparams} failed"
265 elif [[ -f Makefile ]]; then
266 case "${CATEGORY}" in
267 dev-perl|perl-core) mytargets="pure_install" ;;
268 *) mytargets="install" ;;
269 esac
270 if [[ $(declare -p myinst 2>&-) != "declare -a myinst="* ]]; then
271 local myinst_local=(${myinst})
272 else
273 local myinst_local=("${myinst[@]}")
274 fi
275 emake "${myinst_local[@]}" ${mytargets} \
276 || die "emake ${myinst_local[@]} ${mytargets} failed"
277 fi
278
279 perl_delete_module_manpages
280 perl_delete_localpod
281 perl_delete_packlist
282 perl_remove_temppath
283
284 for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
285 [[ -s ${f} ]] && dodoc ${f}
286 done
287
288 perl_link_duallife_scripts
289 }
290
291 # @FUNCTION: perl-module_pkg_postinst
292 # @USAGE: perl-module_pkg_postinst
293 # @DESCRIPTION:
294 # This function is to be called during the pkg_postinst() phase. It only does
295 # useful things for the perl-core category, where it handles the file renaming and symbolic
296 # links that prevent file collisions for dual-life packages installing scripts.
297 # In any other category it immediately exits.
298 perl-module_pkg_postinst() {
299 debug-print-function $FUNCNAME "$@"
300 if [[ ${CATEGORY} != perl-core ]] ; then
301 eqawarn "perl-module.eclass: You are calling perl-module_pkg_postinst outside the perl-core category."
302 eqawarn " This does not do anything; the call can be safely removed."
303 return 0
304 fi
305 perl_link_duallife_scripts
306 }
307
308 # @FUNCTION: perl-module_pkg_postrm
309 # @USAGE: perl-module_pkg_postrm
310 # @DESCRIPTION:
311 # This function is to be called during the pkg_postrm() phase. It only does
312 # useful things for the perl-core category, where it handles the file renaming and symbolic
313 # links that prevent file collisions for dual-life packages installing scripts.
314 # In any other category it immediately exits.
315 perl-module_pkg_postrm() {
316 debug-print-function $FUNCNAME "$@"
317 if [[ ${CATEGORY} != perl-core ]] ; then
318 eqawarn "perl-module.eclass: You are calling perl-module_pkg_postrm outside the perl-core category."
319 eqawarn " This does not do anything; the call can be safely removed."
320 return 0
321 fi
322 perl_link_duallife_scripts
323 }
324
325 # @FUNCTION: perl_set_version
326 # @USAGE: perl_set_version
327 # @DESCRIPTION:
328 # Extract version information and installation paths from the current Perl
329 # interpreter.
330 #
331 # This sets the following variables: PERL_VERSION, SITE_ARCH, SITE_LIB,
332 # ARCH_LIB, VENDOR_LIB, VENDOR_ARCH
333 #
334 # This function used to be called perlinfo as well.
335 perl_set_version() {
336 debug-print-function $FUNCNAME "$@"
337 debug-print "$FUNCNAME: perlinfo_done=${perlinfo_done}"
338 ${perlinfo_done} && return 0
339 perlinfo_done=true
340
341 local f version install{{site,vendor}{arch,lib},archlib}
342 eval "$(perl -V:{version,install{{site,vendor}{arch,lib},archlib}} )"
343 PERL_VERSION=${version}
344 SITE_ARCH=${installsitearch}
345 SITE_LIB=${installsitelib}
346 ARCH_LIB=${installarchlib}
347 VENDOR_LIB=${installvendorlib}
348 VENDOR_ARCH=${installvendorarch}
349 }
350
351 # @FUNCTION: perl_delete_localpod
352 # @USAGE: perl_delete_localpod
353 # @DESCRIPTION:
354 # Remove stray perllocal.pod files in the temporary install directory D.
355 #
356 # This function used to be called fixlocalpod as well.
357 perl_delete_localpod() {
358 debug-print-function $FUNCNAME "$@"
359
360 find "${D}" -type f -name perllocal.pod -delete
361 find "${D}" -depth -mindepth 1 -type d -empty -delete
362 }
363
364 # @FUNCTION: perl_fix_osx_extra
365 # @USAGE: perl_fix_osx_extra
366 # @DESCRIPTION:
367 # Look through ${S} for AppleDouble encoded files and get rid of them.
368 perl_fix_osx_extra() {
369 debug-print-function $FUNCNAME "$@"
370
371 local f
372 find "${S}" -type f -name "._*" -print0 | while read -rd '' f ; do
373 einfo "Removing AppleDouble encoded Macintosh file: ${f#${S}/}"
374 rm -f "${f}"
375 f=${f#${S}/}
376 grep -q "${f}" "${S}"/MANIFEST && \
377 elog "AppleDouble encoded Macintosh file in MANIFEST: ${f#${S}/}"
378 done
379 }
380
381 # @FUNCTION: perl_delete_module_manpages
382 # @USAGE: perl_delete_module_manpages
383 # @DESCRIPTION:
384 # Bump off manpages installed by the current module such as *.3pm files as well
385 # as empty directories.
386 perl_delete_module_manpages() {
387 debug-print-function $FUNCNAME "$@"
388
389 if [[ -d "${ED}"/usr/share/man ]] ; then
390 find "${ED}"/usr/share/man -type f -name "*.3pm" -delete
391 find "${ED}"/usr/share/man -depth -type d -empty -delete
392 fi
393 }
394
395 # @FUNCTION: perl_delete_packlist
396 # @USAGE: perl_delete_packlist
397 # @DESCRIPTION:
398 # Look through ${D} for .packlist files, empty .bs files and empty directories,
399 # and get rid of items found.
400 perl_delete_packlist() {
401 debug-print-function $FUNCNAME "$@"
402 perl_set_version
403 if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
404 find "${D}/${VENDOR_ARCH}" -type f -a \( -name .packlist \
405 -o \( -name '*.bs' -a -empty \) \) -delete
406 find "${D}" -depth -mindepth 1 -type d -empty -delete
407 fi
408 }
409
410 # @FUNCTION: perl_remove_temppath
411 # @USAGE: perl_remove_temppath
412 # @DESCRIPTION:
413 # Look through ${D} for text files containing the temporary installation
414 # folder (i.e. ${D}). If the pattern is found (i.e. " text"), replace it with `/'.
415 perl_remove_temppath() {
416 debug-print-function $FUNCNAME "$@"
417
418 find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
419 if file "${f}" | grep -q -i " text" ; then
420 grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
421 sed -i -e "s:${D}:/:g" "${f}"
422 fi
423 done
424 }
425
426 # @FUNCTION: perl_rm_files
427 # @USAGE: perl_rm_files "file_1" "file_2"
428 # @DESCRIPTION:
429 # Remove certain files from a Perl release and remove them from the MANIFEST
430 # while we're there.
431 #
432 # Most useful in src_prepare for nuking bad tests, and is highly recommended
433 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
434 # test is completely irrelevant to end users, and frequently fail simply
435 # because the authors of Test::Pod... changed their recommendations, and thus
436 # failures are only useful feedback to Authors, not users.
437 #
438 # Removing from MANIFEST also avoids needless log messages warning
439 # users about files "missing from their kit".
440 perl_rm_files() {
441 debug-print-function $FUNCNAME "$@"
442 local skipfile="${T}/.gentoo_makefile_skip"
443 local manifile="${S}/MANIFEST"
444 local manitemp="${T}/.gentoo_manifest_temp"
445 oldifs="$IFS"
446 IFS="\n"
447 for filename in "$@"; do
448 einfo "Removing un-needed ${filename}";
449 # Remove the file
450 rm -f "${S}/${filename}"
451 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
452 done
453 if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
454 einfo "Fixing Manifest"
455 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
456 mv -f -- "${manitemp}" "${manifile}"
457 rm -- "${skipfile}";
458 fi
459 IFS="$oldifs"
460 }
461
462 # @FUNCTION: perl_link_duallife_scripts
463 # @USAGE: perl_link_duallife_scripts
464 # @DESCRIPTION:
465 # Moves files and generates symlinks so dual-life packages installing scripts do not
466 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes
467 # only sense for perl-core packages.
468 perl_link_duallife_scripts() {
469 debug-print-function $FUNCNAME "$@"
470 if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
471 return 0
472 fi
473
474 local i ff
475 if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
476 for i in "${DUALLIFESCRIPTS[@]}" ; do
477 alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
478 done
479 for i in "${DUALLIFEMAN[@]}" ; do
480 ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
481 ff=${ff##*.1}
482 alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
483 done
484 else
485 pushd "${ED}" > /dev/null
486 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
487 mv ${i}{,-${PV}-${P}} || die
488 #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
489 DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
490 done
491 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
492 mv ${i} ${i%.1}-${PV}-${P}.1 || die
493 DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
494 done
495 popd > /dev/null
496 fi
497 }
498
499 # @FUNCTION: perl_check_env
500 # @USAGE: perl_check_env
501 # @DESCRIPTION:
502 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
503 # doing personal perl work, which may accidentally leak into portage and break the
504 # system perl installaton.
505 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
506 # There's a workaround, but you'll have to read the code for it.
507 perl_check_env() {
508 local errored value;
509
510 for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
511 # Next unless match
512 [ -v $i ] || continue;
513
514 # Warn only once, and warn only when one of the bad values are set.
515 # record failure here.
516 if [ ${errored:-0} == 0 ]; then
517 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
518 elog "perl-module.eclass: Suspicious environment values found.";
519 else
520 eerror "perl-module.eclass: Suspicious environment values found.";
521 fi
522 fi
523 errored=1
524
525 # Read ENV Value
526 eval "value=\$$i";
527
528 # Print ENV name/value pair
529 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
530 elog " $i=\"$value\"";
531 else
532 eerror " $i=\"$value\"";
533 fi
534 done
535
536 # Return if there were no failures
537 [ ${errored:-0} == 0 ] && return;
538
539 # Return if user knows what they're doing
540 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
541 elog "Continuing anyway, seems you know what you're doing."
542 return
543 fi
544
545 eerror "Your environment settings may lead to undefined behavior and/or build failures."
546 die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."
547 }

  ViewVC Help
Powered by ViewVC 1.1.20