Merge remote-tracking branch 'remotes/tomboy-64/idea-ultimate'
[gentoo.git] / eclass / perl-functions.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: perl-functions.eclass
6 # @MAINTAINER:
7 # perl@gentoo.org
8 # @AUTHOR:
9 # Seemant Kulleen <seemant@gentoo.org>
10 # Andreas K. Huettel <dilfridge@gentoo.org>
11 # @BLURB: helper functions eclass for perl modules
12 # @DESCRIPTION:
13 # The perl-functions eclass is designed to allow easier installation of perl
14 # modules, and their incorporation into the Gentoo Linux system.
15 # It provides helper functions, no phases or variable manipulation in
16 # global scope.
17
18 [[ ${CATEGORY} == "perl-core" ]] && inherit alternatives
19
20 case "${EAPI:-0}" in
21         5|6)
22                 ;;
23         *)
24                 die "EAPI=${EAPI} is not supported by perl-functions.eclass"
25                 ;;
26 esac
27
28 perlinfo_done=false
29
30 # @FUNCTION: perl_set_version
31 # @USAGE: perl_set_version
32 # @DESCRIPTION:
33 # Extract version information and installation paths from the current Perl 
34 # interpreter. 
35 #
36 # This sets the following variables: PERL_VERSION, SITE_ARCH, SITE_LIB, 
37 # ARCH_LIB, VENDOR_LIB, VENDOR_ARCH
38 #
39 # This function used to be called perlinfo as well.
40 perl_set_version() {
41         debug-print-function $FUNCNAME "$@"
42         debug-print "$FUNCNAME: perlinfo_done=${perlinfo_done}"
43         ${perlinfo_done} && return 0
44         perlinfo_done=true
45
46         local f version install{{site,vendor}{arch,lib},archlib}
47         eval "$(perl -V:{version,install{{site,vendor}{arch,lib},archlib}} )"
48         PERL_VERSION=${version}
49         SITE_ARCH=${installsitearch}
50         SITE_LIB=${installsitelib}
51         ARCH_LIB=${installarchlib}
52         VENDOR_LIB=${installvendorlib}
53         VENDOR_ARCH=${installvendorarch}
54 }
55
56 # @FUNCTION: perl_delete_localpod
57 # @USAGE: perl_delete_localpod
58 # @DESCRIPTION:
59 # Remove stray perllocal.pod files in the temporary install directory D.
60 #
61 # This function used to be called fixlocalpod as well.
62 perl_delete_localpod() {
63         debug-print-function $FUNCNAME "$@"
64
65         find "${D}" -type f -name perllocal.pod -delete
66         find "${D}" -depth -mindepth 1 -type d -empty -delete
67 }
68
69 # @FUNCTION: perl_fix_osx_extra
70 # @USAGE: perl_fix_osx_extra
71 # @DESCRIPTION:
72 # Look through ${S} for AppleDouble encoded files and get rid of them.
73 perl_fix_osx_extra() {
74         debug-print-function $FUNCNAME "$@"
75
76         local f
77         find "${S}" -type f -name "._*" -print0 | while read -rd '' f ; do
78                 einfo "Removing AppleDouble encoded Macintosh file: ${f#${S}/}"
79                 rm -f "${f}"
80                 f=${f#${S}/}
81                 grep -q "${f}" "${S}"/MANIFEST && \
82                         elog "AppleDouble encoded Macintosh file in MANIFEST: ${f#${S}/}"
83         done
84 }
85
86 # @FUNCTION: perl_delete_module_manpages
87 # @USAGE: perl_delete_module_manpages
88 # @DESCRIPTION:
89 # Bump off manpages installed by the current module such as *.3pm files as well
90 # as empty directories.
91 perl_delete_module_manpages() {
92         debug-print-function $FUNCNAME "$@"
93
94         if [[ -d "${ED}"/usr/share/man ]] ; then
95                 find "${ED}"/usr/share/man -type f -name "*.3pm" -delete
96                 find "${ED}"/usr/share/man -depth -type d -empty -delete
97         fi
98 }
99
100 # @FUNCTION: perl_delete_packlist
101 # @USAGE: perl_delete_packlist
102 # @DESCRIPTION:
103 # Look through ${D} for .packlist files, empty .bs files and empty directories,
104 # and get rid of items found.
105 perl_delete_packlist() {
106         debug-print-function $FUNCNAME "$@"
107         perl_set_version
108         if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
109                 find "${D}/${VENDOR_ARCH}" -type f -a \( -name .packlist \
110                         -o \( -name '*.bs' -a -empty \) \) -delete
111                 find "${D}" -depth -mindepth 1 -type d -empty -delete
112         fi
113 }
114
115 # @FUNCTION: perl_remove_temppath
116 # @USAGE: perl_remove_temppath
117 # @DESCRIPTION:
118 # Look through ${D} for text files containing the temporary installation
119 # folder (i.e. ${D}). If the pattern is found (i.e. " text"), replace it with `/'.
120 perl_remove_temppath() {
121         debug-print-function $FUNCNAME "$@"
122
123         find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
124                 if file "${f}" | grep -q -i " text" ; then
125                         grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
126                         sed -i -e "s:${D}:/:g" "${f}"
127                 fi
128         done
129 }
130
131 # @FUNCTION: perl_rm_files
132 # @USAGE: perl_rm_files "file_1" "file_2"
133 # @DESCRIPTION:
134 # Remove certain files from a Perl release and remove them from the MANIFEST
135 # while we're there.
136 #
137 # Most useful in src_prepare for nuking bad tests, and is highly recommended
138 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
139 # test is completely irrelevant to end users, and frequently fail simply
140 # because the authors of Test::Pod... changed their recommendations, and thus
141 # failures are only useful feedback to Authors, not users.
142 #
143 # Removing from MANIFEST also avoids needless log messages warning
144 # users about files "missing from their kit".
145 perl_rm_files() {
146         debug-print-function $FUNCNAME "$@"
147         local skipfile="${T}/.gentoo_makefile_skip"
148         local manifile="${S}/MANIFEST"
149         local manitemp="${T}/.gentoo_manifest_temp"
150         oldifs="$IFS"
151         IFS="\n"
152         for filename in "$@"; do
153                 einfo "Removing un-needed ${filename}";
154                 # Remove the file
155                 rm -f "${S}/${filename}"
156                 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
157         done
158         if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
159                 einfo "Fixing Manifest"
160                 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
161                 mv -f -- "${manitemp}" "${manifile}"
162                 rm -- "${skipfile}";
163         fi
164         IFS="$oldifs"
165 }
166
167 # @FUNCTION: perl_link_duallife_scripts
168 # @USAGE: perl_link_duallife_scripts
169 # @DESCRIPTION:
170 # Moves files and generates symlinks so dual-life packages installing scripts do not
171 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes 
172 # only sense for perl-core packages.
173 perl_link_duallife_scripts() {
174         debug-print-function $FUNCNAME "$@"
175         if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
176                 return 0
177         fi
178
179         local i ff
180         if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
181                 for i in "${DUALLIFESCRIPTS[@]}" ; do
182                         alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
183                 done
184                 for i in "${DUALLIFEMAN[@]}" ; do
185                         ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
186                         ff=${ff##*.1}
187                         alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
188                 done
189         else
190                 pushd "${ED}" > /dev/null
191                 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
192                         mv ${i}{,-${PV}-${P}} || die
193                         #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
194                         DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
195                 done
196                 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
197                         mv ${i} ${i%.1}-${PV}-${P}.1 || die
198                         DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
199                 done
200                 popd > /dev/null
201         fi
202 }
203
204 # @FUNCTION: perl_check_env
205 # @USAGE: perl_check_env
206 # @DESCRIPTION:
207 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
208 # doing personal perl work, which may accidentally leak into portage and break the
209 # system perl installaton.
210 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
211 # There's a workaround, but you'll have to read the code for it.
212 perl_check_env() {
213         local errored value;
214
215         for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
216                 # Next unless match
217                 [ -v $i ] || continue;
218
219                 # Warn only once, and warn only when one of the bad values are set.
220                 # record failure here.
221                 if [ ${errored:-0} == 0 ]; then
222                         if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
223                                 elog "perl-module.eclass: Suspicious environment values found.";
224                         else
225                                 eerror "perl-module.eclass: Suspicious environment values found.";
226                         fi
227                 fi
228                 errored=1
229
230                 # Read ENV Value
231                 eval "value=\$$i";
232
233                 # Print ENV name/value pair
234                 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
235                         elog "    $i=\"$value\"";
236                 else
237                         eerror "    $i=\"$value\"";
238                 fi
239         done
240
241         # Return if there were no failures
242         [ ${errored:-0} == 0 ] && return;
243
244         # Return if user knows what they're doing
245         if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
246                 elog "Continuing anyway, seems you know what you're doing."
247                 return
248         fi
249
250         eerror "Your environment settings may lead to undefined behavior and/or build failures."
251         die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."
252 }