1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: perl-functions.eclass
8 # Seemant Kulleen <seemant@gentoo.org>
9 # Andreas K. Huettel <dilfridge@gentoo.org>
10 # @BLURB: helper functions eclass for perl modules
12 # The perl-functions eclass is designed to allow easier installation of perl
13 # modules, and their incorporation into the Gentoo Linux system.
14 # It provides helper functions, no phases or variable manipulation in
17 [[ ${CATEGORY} == "perl-core" ]] && inherit alternatives
23 die "EAPI=${EAPI} is not supported by perl-functions.eclass"
29 # @FUNCTION: perl_set_version
30 # @USAGE: perl_set_version
32 # Extract version information and installation paths from the current Perl
35 # This sets the following variables: PERL_VERSION, SITE_ARCH, SITE_LIB,
36 # ARCH_LIB, VENDOR_LIB, VENDOR_ARCH
38 # This function used to be called perlinfo as well.
40 debug-print-function $FUNCNAME "$@"
41 debug-print "$FUNCNAME: perlinfo_done=${perlinfo_done}"
42 ${perlinfo_done} && return 0
45 local f version install{{site,vendor}{arch,lib},archlib}
46 eval "$(perl -V:{version,install{{site,vendor}{arch,lib},archlib}} )"
47 PERL_VERSION=${version}
48 SITE_ARCH=${installsitearch}
49 SITE_LIB=${installsitelib}
50 ARCH_LIB=${installarchlib}
51 VENDOR_LIB=${installvendorlib}
52 VENDOR_ARCH=${installvendorarch}
55 # @FUNCTION: perl_delete_localpod
56 # @USAGE: perl_delete_localpod
58 # Remove stray perllocal.pod files in the temporary install directory D.
60 # This function used to be called fixlocalpod as well.
61 perl_delete_localpod() {
62 debug-print-function $FUNCNAME "$@"
64 find "${D}" -type f -name perllocal.pod -delete
65 find "${D}" -depth -mindepth 1 -type d -empty -delete
68 # @FUNCTION: perl_fix_osx_extra
69 # @USAGE: perl_fix_osx_extra
71 # Look through ${S} for AppleDouble encoded files and get rid of them.
72 perl_fix_osx_extra() {
73 debug-print-function $FUNCNAME "$@"
76 find "${S}" -type f -name "._*" -print0 | while read -rd '' f ; do
77 einfo "Removing AppleDouble encoded Macintosh file: ${f#${S}/}"
80 grep -q "${f}" "${S}"/MANIFEST && \
81 elog "AppleDouble encoded Macintosh file in MANIFEST: ${f#${S}/}"
85 # @FUNCTION: perl_delete_module_manpages
86 # @USAGE: perl_delete_module_manpages
88 # Bump off manpages installed by the current module such as *.3pm files as well
89 # as empty directories.
90 perl_delete_module_manpages() {
91 debug-print-function $FUNCNAME "$@"
93 if [[ -d "${ED}"/usr/share/man ]] ; then
94 find "${ED}"/usr/share/man -type f -name "*.3pm" -delete
95 find "${ED}"/usr/share/man -depth -type d -empty -delete
99 # @FUNCTION: perl_delete_packlist
100 # @USAGE: perl_delete_packlist
102 # Look through ${D} for .packlist files, empty .bs files and empty directories,
103 # and get rid of items found.
104 perl_delete_packlist() {
105 debug-print-function $FUNCNAME "$@"
107 if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
108 find "${D}/${VENDOR_ARCH}" -type f -a -name .packlist -delete
109 perl_delete_emptybsdir
113 # @FUNCTION: perl_delete_emptybsdir
114 # @USAGE: perl_delete_emptybsdir
116 # Look through ${D} for empty .bs files and empty directories,
117 # and get rid of items found.
118 perl_delete_emptybsdir() {
119 debug-print-function $FUNCNAME "$@"
121 if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
122 find "${D}/${VENDOR_ARCH}" -type f \
123 -a -name '*.bs' -a -empty -delete
124 find "${D}" -depth -mindepth 1 -type d -empty -delete
128 # @FUNCTION: perl_fix_packlist
129 # @USAGE: perl_fix_packlist
131 # Look through ${D} for .packlist text files containing the temporary installation
132 # folder (i.e. ${D}). If the pattern is found, silently replace it with `/'.
133 # Remove duplicate entries; then validate all entries in the packlist against ${D}
134 # and prune entries that do not correspond to installed files.
135 perl_fix_packlist() {
136 debug-print-function $FUNCNAME "$@"
138 local packlist_temp="${T}/.gentoo_packlist_temp"
139 find "${D}" -type f -name '.packlist' -print0 | while read -rd '' f ; do
140 if file "${f}" | grep -q -i " text" ; then
141 einfo "Fixing packlist file /${f#${D}}"
143 # remove the temporary build dir path
144 sed -i -e "s:${D}:/:g" "${f}"
146 # remove duplicate entries
147 sort -u "${f}" > "${packlist_temp}"
148 mv "${packlist_temp}" "${f}"
150 # remove files that dont exist
151 cat "${f}" | while read -r entry; do
152 if [ ! -e "${D}/${entry}" ]; then
153 einfo "Pruning surplus packlist entry ${entry}"
154 grep -v -x -F "${entry}" "${f}" > "${packlist_temp}"
155 mv "${packlist_temp}" "${f}"
162 # @FUNCTION: perl_remove_temppath
163 # @USAGE: perl_remove_temppath
165 # Look through ${D} for text files containing the temporary installation
166 # folder (i.e. ${D}). If the pattern is found, replace it with `/' and warn.
167 perl_remove_temppath() {
168 debug-print-function $FUNCNAME "$@"
170 find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
171 if file "${f}" | grep -q -i " text" ; then
172 grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
173 sed -i -e "s:${D}:/:g" "${f}"
178 # @FUNCTION: perl_rm_files
179 # @USAGE: perl_rm_files "file_1" "file_2"
181 # Remove certain files from a Perl release and remove them from the MANIFEST
184 # Most useful in src_prepare for nuking bad tests, and is highly recommended
185 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
186 # test is completely irrelevant to end users, and frequently fail simply
187 # because the authors of Test::Pod... changed their recommendations, and thus
188 # failures are only useful feedback to Authors, not users.
190 # Removing from MANIFEST also avoids needless log messages warning
191 # users about files "missing from their kit".
193 debug-print-function $FUNCNAME "$@"
194 local skipfile="${T}/.gentoo_makefile_skip"
195 local manifile="${S}/MANIFEST"
196 local manitemp="${T}/.gentoo_manifest_temp"
199 for filename in "$@"; do
200 einfo "Removing un-needed ${filename}";
202 rm -f "${S}/${filename}"
203 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
205 if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
206 einfo "Fixing Manifest"
207 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
208 mv -f -- "${manitemp}" "${manifile}"
214 # @FUNCTION: perl_link_duallife_scripts
215 # @USAGE: perl_link_duallife_scripts
217 # Moves files and generates symlinks so dual-life packages installing scripts do not
218 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes
219 # only sense for perl-core packages.
220 perl_link_duallife_scripts() {
221 debug-print-function $FUNCNAME "$@"
222 if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
227 if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
228 for i in "${DUALLIFESCRIPTS[@]}" ; do
229 alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
231 for i in "${DUALLIFEMAN[@]}" ; do
232 ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
234 alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
237 pushd "${ED}" > /dev/null
238 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
239 mv ${i}{,-${PV}-${P}} || die
240 #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
241 DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
243 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
244 mv ${i} ${i%.1}-${PV}-${P}.1 || die
245 DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
251 # @FUNCTION: perl_check_env
252 # @USAGE: perl_check_env
254 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
255 # doing personal perl work, which may accidentally leak into portage and break the
256 # system perl installaton.
257 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
258 # There's a workaround, but you'll have to read the code for it.
262 for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
264 [ -v $i ] || continue;
266 # Warn only once, and warn only when one of the bad values are set.
267 # record failure here.
268 if [ ${errored:-0} == 0 ]; then
269 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
270 elog "perl-module.eclass: Suspicious environment values found.";
272 eerror "perl-module.eclass: Suspicious environment values found.";
280 # Print ENV name/value pair
281 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
282 elog " $i=\"$value\"";
284 eerror " $i=\"$value\"";
288 # Return if there were no failures
289 [ ${errored:-0} == 0 ] && return;
291 # Return if user knows what they're doing
292 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
293 elog "Continuing anyway, seems you know what you're doing."
297 eerror "Your environment settings may lead to undefined behavior and/or build failures."
298 die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."
301 # @FUNCTION: perl_doexamples
302 # @USAGE: perl_doexamples "file_1" "file_2"
304 # Install example files ready-to-run.
305 # Is called under certain circumstances in perl-module.eclass src_install
306 # (see the documentation there).
309 debug-print-function $FUNCNAME "$@"
311 einfo "Installing examples into /usr/share/doc/${PF}/examples"
313 # no compression since we want ready-to-run scripts
314 docompress -x /usr/share/doc/${PF}/examples
319 # is there a way to undo "docinto" ?
322 # @FUNCTION: perl_has_module
323 # @USAGE: perl_has_module "Test::Tester"
325 # Query the installed system Perl to see if a given module is installed.
326 # This does **not** load the module in question, only anticipates if it *might* load.
328 # This is primarily for the purposes of dependency weakening so that conditional
329 # behaviour can be triggered without adding dependencies to portage which would confuse
330 # a dependency resolver.
332 # returns 'true' if the module is available, returns error if the module is not available
335 debug-print-function $FUNCNAME "$@"
337 [[ $# -gt 0 ]] || die "${FUNCNAME}: No module name provided"
338 [[ $# -lt 2 ]] || die "${FUNCNAME}: Too many parameters ($#)"
340 perl -we 'my $mn = $ARGV[0];
341 $mn =~ s{(::|\x{27})}{/}g;
344 exit 0 if -r $_ . q[/] . $mn . q[.pm]
349 # @FUNCTION: perl_has_module_version
350 # @USAGE: perl_has_module_version "Test::Tester" "0.017"
352 # Query the installed system Perl to see if a given module is installed
353 # and is at least a given version.
355 # This requires more caution to use than perl_has_module as it requires
356 # loading the module in question to determine version compatibility,
357 # which can be SLOW, and can have side effects (ie: compilation fails in
358 # require due to some dependency, resulting in a "Fail")
360 # Also take care to note the module version is a *minimum*, *must* be
361 # written in upstream versions format and should be a a legal upstream version
363 # returns a true exit code if the module is both available and is at least
364 # the specified version
366 perl_has_module_version() {
367 debug-print-function $FUNCNAME "$@"
369 [[ $# -gt 0 ]] || die "${FUNCNAME}: No module name provided"
370 [[ $# -gt 1 ]] || die "${FUNCNAME}: No module version provided"
371 [[ $# -lt 3 ]] || die "${FUNCNAME}: Too many parameters ($#)"
373 perl -we 'my $mn = $ARGV[0];
374 $mn =~ s{(::|\x{27})}{/}g;
376 require qq[${mn}.pm];
377 $ARGV[0]->VERSION($ARGV[1]);
382 # @FUNCTION: perl_get_module_version
383 # @USAGE: MODVER=$(perl_get_module_version "Test::Simple")
385 # Query the installed system perl to report the version of the installed
388 # Note this should be strictly for diagnostic purposes to the end user,
389 # and may be of selective use in pkg_info to enhance
390 # emerge --info reports.
392 # Anything that does version comparisons **must not** use the return value
395 # Also note that this **must** at least attempt load the module in
396 # question as part of its operation, and is subsequently prone to SLOWness.
398 # Return codes return error in both compilation-failure and not-installed cases.
400 perl_get_module_version() {
401 debug-print-function $FUNCNAME "$@"
403 [[ $# -gt 0 ]] || die "${FUNCNAME}: No module name provided"
404 [[ $# -lt 2 ]] || die "${FUNCNAME}: Too many parameters ($#)"
406 if ! perl_has_module "$@" ; then
407 echo "(Not Installed)";
411 # Todo: What do we do if require fails? spew to stderr
414 perl -we 'my $mn = $ARGV[0];
415 $mn =~ s{(::|\x{27})}{/}g;
417 eval { require qq[${mn}.pm]; 1 } or do {
418 print q[(Compilation failed in require)];
421 my $stash = \%{ $ARGV[0] . q[::] };
422 if ( not exists $stash->{VERSION} ) {
423 print q[(No VERSION property)];
426 if ( not defined ${$stash->{VERSION}} ) {
430 print ${$stash->{VERSION}};
434 # @FUNCTION: perl_get_raw_vendorlib
435 # @USAGE: perl_get_raw_vendorlib
437 # Convenience function to optimise for a common case without double-handling
438 # variables everywhere.
440 # Note: Will include EPREFIX where relevant
441 perl_get_raw_vendorlib() {
442 debug-print-function $FUNCNAME "$@"
444 [[ $# -lt 1 ]] || die "${FUNCNAME}: Too many parameters ($#)"
447 -e'exists $Config{$ARGV[0]} || die qq{No such Config key "$ARGV[0]"};
448 print $Config{$ARGV[0]};
449 exit 0' -- "installvendorlib" || die "Can't extract installvendorlib from Perl Configuration"