dev-python/PyGithub: Bump to 1.46
[gentoo.git] / eclass / db.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: db.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @BLURB: Internal eclass used by sys-libs/db ebuilds
8
9 inherit eutils multilib multiprocessing
10
11 IUSE="doc test examples"
12
13 EXPORT_FUNCTIONS src_test
14
15 DEPEND="test? ( >=dev-lang/tcl-8.4 )"
16
17 RDEPEND=""
18
19 db_fix_so() {
20         has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
21         LIB="${EROOT}/usr/$(get_libdir)"
22
23         cd "${LIB}" || die
24
25         # first clean up old symlinks
26         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so' -delete || die
27         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so.[23]' -delete || die
28         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -delete || die
29
30         # now rebuild all the correct ones
31         local ext
32         for ext in so a; do
33                 for name in libdb libdb_{cxx,tcl,java,sql,stl}; do
34                         target="$(find . -maxdepth 1 -type f -name "${name}-*.${ext}" |sort -V |tail -n 1)"
35                         [[ -n "${target}" ]] && ln -sf ${target//.\//} ${name}.${ext}
36                 done;
37         done;
38
39         # db[23] gets some extra-special stuff
40         if [[ -f libdb1.so.2 ]]; then
41                 ln -sf libdb1.so.2 libdb.so.2
42                 ln -sf libdb1.so.2 libdb1.so
43                 ln -sf libdb1.so.2 libdb-1.so
44         fi
45         # what do we do if we ever get 3.3 ?
46         local i
47         for i in libdb libdb_{cxx,tcl,java,sql,stl}; do
48                 if [[ -f ${i}-3.2.so ]]; then
49                         ln -sf ${i}-3.2.so ${i}-3.so
50                         ln -sf ${i}-3.2.so ${i}.so.3
51                 fi
52         done
53
54         # do the same for headers now
55         # but since there are only two of them, just overwrite them
56         cd "${EROOT}"/usr/include
57         target="$(find . -maxdepth 1 -type d -name 'db[0-9]*' | sort -V |cut -d/ -f2- | tail -n1)"
58         if [[ -n "${target}" ]] && [[ -e "${target}/db.h" ]] && ( ! [[ -e db.h ]] || [[ -h db.h ]] ); then
59                 einfo "Creating db.h symlinks to ${target}"
60                 ln -sf "${target}"/db.h .
61                 ln -sf "${target}"/db_185.h .
62         elif [[ ! -e "${target}/db.h" ]]; then
63                 if [[ -n "${target}" ]]; then
64                         ewarn "Could not find ${target}/db.h"
65                 elif [[ -h db.h ]]; then
66                         einfo "Apparently you just removed the last instance of $PN. Removing the symlinks"
67                         rm -f db.h db_185.h
68                 fi
69         fi
70 }
71
72 db_src_install_doc() {
73         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
74         # not everybody wants this wad of documentation as it is primarily API docs
75         if use doc; then
76                 dodir /usr/share/doc/${PF}/html
77                 mv "${ED}"/usr/docs/* "${ED}"/usr/share/doc/${PF}/html/ || die
78                 rm -rf "${ED}"/usr/docs
79         else
80                 rm -rf "${ED}"/usr/docs
81         fi
82
83         db_src_install_examples
84 }
85
86 db_src_install_examples() {
87         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
88         if use examples ; then
89                 local langs=( c cxx stl )
90                 [[ "${IUSE/java}" != "${IUSE}" ]] \
91                         && use java \
92                         && langs+=( java )
93                 local i
94                 for i in ${langs[@]} ; do
95                         destdir="/usr/share/doc/${PF}/"
96                         src="${S}/../examples_${i}/"
97                         if [[ -f "${src}" ]]; then
98                                 dodir "${destdir}"
99                                 cp -ra "${src}" "${ED}${destdir}/" || die
100                         fi
101                 done
102         fi
103 }
104
105 db_src_install_usrbinslot() {
106         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
107         # slot all program names to avoid overwriting
108         local fname
109         for fname in "${ED}"/usr/bin/db*
110         do
111                 dn="$(dirname "${fname}")"
112                 bn="$(basename "${fname}")"
113                 bn="${bn/db/db${SLOT}}"
114                 mv "${fname}" "${dn}/${bn}" || \
115                         die "Failed to rename ${fname} to ${dn}/${bn}"
116         done
117 }
118
119 db_src_install_headerslot() {
120         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
121         # install all headers in a slotted location
122         dodir /usr/include/db${SLOT}
123         mv "${ED}"/usr/include/*.h "${ED}"/usr/include/db${SLOT}/ || die
124 }
125
126 db_src_install_usrlibcleanup() {
127         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
128         LIB="${ED}/usr/$(get_libdir)"
129         # Clean out the symlinks so that they will not be recorded in the
130         # contents (bug #60732)
131
132         if [[ "${ED}" = "" ]]; then
133                 die "Calling clean_links while \${ED} not defined"
134         fi
135
136         if [[ -e "${LIB}"/libdb.a ]] && [[ ! -e "${LIB}"/libdb-${SLOT}.a ]]; then
137                 einfo "Moving libdb.a to a versioned name"
138                 mv "${LIB}/libdb.a" "${LIB}/libdb-${SLOT}.a" || die
139         fi
140
141         if [[ -e "${LIB}"/libdb_cxx.a ]] && [[ ! -e "${LIB}"/libdb_cxx-${SLOT}.a ]]; then
142                 einfo "Moving libdb_cxx.a to a versioned name"
143                 mv "${LIB}/libdb_cxx.a" "${LIB}/libdb_cxx-${SLOT}.a" || die
144         fi
145
146         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so' -delete || die
147         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*so.[23]' -delete || die
148         einfo "removing unversioned static archives"
149         find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -delete || die
150
151         rm -f \
152                 "${ED}"/usr/include/{db,db_185}.h \
153                 "${LIB}"/libdb{,_{cxx,sql,stl,java,tcl}}.a
154 }
155
156 db_src_test() {
157         if [[ $UID -eq 0 ]]; then
158                 M="You must run the testsuite as non-root, skipping"
159                 ewarn "${M}"
160                 elog "${M}"
161                 return 0
162         fi
163
164         if use tcl; then
165                 einfo "Running sys-libs/db testsuite"
166                 ewarn "This can take 6+ hours on modern machines"
167                 # Fix stuff that fails with relative paths, and upstream moving files
168                 # around...
169                 local test_parallel='' t
170                 for t in \
171                         "${S}"/test/parallel.tcl \
172                         "${S}"/../test/parallel.tcl \
173                         "${S}"/test/tcl/parallel.tcl \
174                         "${S}"/../test/tcl/parallel.tcl \
175                         ; do
176                         [[ -f "${t}" ]] && test_parallel="${t}" && break
177                 done
178
179                 sed -ri \
180                         -e '/regsub .test_path ./s,(regsub),#\1,g' \
181                         -e '/regsub .src_root ./s,(regsub),#\1,g' \
182                         -e '/regsub .tcl_utils ./s,(regsub),#\1,g' \
183                         "${test_parallel}"
184                 cd "${S}"
185                 for t in \
186                         ../test/test.tcl \
187                         ../test/tcl/test.tcl \
188                         ; do
189                         [[ -f "${t}" ]] && testbase="${t}" && break
190                 done
191                 echo "source ${t}" > testrunner.tcl
192                 echo "run_parallel $(makeopts_jobs) run_std" >> testrunner.tcl
193
194                 tclsh testrunner.tcl
195                 grep -Eqs '^FAIL' ALL.OUT* && die "Some tests failed, please see ${S}/ALL.OUT*"
196         else
197                 eerror "You must have USE=tcl to run the sys-libs/db testsuite."
198         fi
199 }