sci-mathematics/rstudio: Thanks to tomboy-64 for fixing bug Bug 534152 - sci-mathemat...
[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 -delete
110                 perl_delete_emptybsdir
111         fi
112 }
113
114 # @FUNCTION: perl_delete_emptybsdir
115 # @USAGE: perl_delete_emptybsdir
116 # @DESCRIPTION:
117 # Look through ${D} for empty .bs files and empty directories,
118 # and get rid of items found.
119 perl_delete_emptybsdir() {
120         debug-print-function $FUNCNAME "$@"
121         perl_set_version
122         if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
123                 find "${D}/${VENDOR_ARCH}" -type f \
124                         -a -name '*.bs' -a -empty -delete
125                 find "${D}" -depth -mindepth 1 -type d -empty -delete
126         fi
127 }
128
129 # @FUNCTION: perl_fix_packlist
130 # @USAGE: perl_fix_packlist
131 # @DESCRIPTION:
132 # Look through ${D} for .packlist text files containing the temporary installation
133 # folder (i.e. ${D}). If the pattern is found, silently replace it with `/'.
134 perl_fix_packlist() {
135         debug-print-function $FUNCNAME "$@"
136
137         find "${D}" -type f -name '.packlist' -print0 | while read -rd '' f ; do
138                 if file "${f}" | grep -q -i " text" ; then
139                         sed -i -e "s:${D}:/:g" "${f}"
140                 fi
141         done
142 }
143
144 # @FUNCTION: perl_remove_temppath
145 # @USAGE: perl_remove_temppath
146 # @DESCRIPTION:
147 # Look through ${D} for text files containing the temporary installation
148 # folder (i.e. ${D}). If the pattern is found, replace it with `/' and warn.
149 perl_remove_temppath() {
150         debug-print-function $FUNCNAME "$@"
151
152         find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
153                 if file "${f}" | grep -q -i " text" ; then
154                         grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
155                         sed -i -e "s:${D}:/:g" "${f}"
156                 fi
157         done
158 }
159
160 # @FUNCTION: perl_rm_files
161 # @USAGE: perl_rm_files "file_1" "file_2"
162 # @DESCRIPTION:
163 # Remove certain files from a Perl release and remove them from the MANIFEST
164 # while we're there.
165 #
166 # Most useful in src_prepare for nuking bad tests, and is highly recommended
167 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
168 # test is completely irrelevant to end users, and frequently fail simply
169 # because the authors of Test::Pod... changed their recommendations, and thus
170 # failures are only useful feedback to Authors, not users.
171 #
172 # Removing from MANIFEST also avoids needless log messages warning
173 # users about files "missing from their kit".
174 perl_rm_files() {
175         debug-print-function $FUNCNAME "$@"
176         local skipfile="${T}/.gentoo_makefile_skip"
177         local manifile="${S}/MANIFEST"
178         local manitemp="${T}/.gentoo_manifest_temp"
179         oldifs="$IFS"
180         IFS="\n"
181         for filename in "$@"; do
182                 einfo "Removing un-needed ${filename}";
183                 # Remove the file
184                 rm -f "${S}/${filename}"
185                 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
186         done
187         if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
188                 einfo "Fixing Manifest"
189                 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
190                 mv -f -- "${manitemp}" "${manifile}"
191                 rm -- "${skipfile}";
192         fi
193         IFS="$oldifs"
194 }
195
196 # @FUNCTION: perl_link_duallife_scripts
197 # @USAGE: perl_link_duallife_scripts
198 # @DESCRIPTION:
199 # Moves files and generates symlinks so dual-life packages installing scripts do not
200 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes 
201 # only sense for perl-core packages.
202 perl_link_duallife_scripts() {
203         debug-print-function $FUNCNAME "$@"
204         if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
205                 return 0
206         fi
207
208         local i ff
209         if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
210                 for i in "${DUALLIFESCRIPTS[@]}" ; do
211                         alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
212                 done
213                 for i in "${DUALLIFEMAN[@]}" ; do
214                         ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
215                         ff=${ff##*.1}
216                         alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
217                 done
218         else
219                 pushd "${ED}" > /dev/null
220                 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
221                         mv ${i}{,-${PV}-${P}} || die
222                         #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
223                         DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
224                 done
225                 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
226                         mv ${i} ${i%.1}-${PV}-${P}.1 || die
227                         DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
228                 done
229                 popd > /dev/null
230         fi
231 }
232
233 # @FUNCTION: perl_check_env
234 # @USAGE: perl_check_env
235 # @DESCRIPTION:
236 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
237 # doing personal perl work, which may accidentally leak into portage and break the
238 # system perl installaton.
239 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
240 # There's a workaround, but you'll have to read the code for it.
241 perl_check_env() {
242         local errored value;
243
244         for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
245                 # Next unless match
246                 [ -v $i ] || continue;
247
248                 # Warn only once, and warn only when one of the bad values are set.
249                 # record failure here.
250                 if [ ${errored:-0} == 0 ]; then
251                         if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
252                                 elog "perl-module.eclass: Suspicious environment values found.";
253                         else
254                                 eerror "perl-module.eclass: Suspicious environment values found.";
255                         fi
256                 fi
257                 errored=1
258
259                 # Read ENV Value
260                 eval "value=\$$i";
261
262                 # Print ENV name/value pair
263                 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
264                         elog "    $i=\"$value\"";
265                 else
266                         eerror "    $i=\"$value\"";
267                 fi
268         done
269
270         # Return if there were no failures
271         [ ${errored:-0} == 0 ] && return;
272
273         # Return if user knows what they're doing
274         if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
275                 elog "Continuing anyway, seems you know what you're doing."
276                 return
277         fi
278
279         eerror "Your environment settings may lead to undefined behavior and/or build failures."
280         die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."
281 }