kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / mysql_fx.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # DEPRECATED
5 # Recent versions have begun deprecating this eclass.
6 # Do not use it in new series.
7
8 # @ECLASS: mysql_fx.eclass
9 # @MAINTAINER:
10 #   - MySQL Team <mysql-bugs@gentoo.org>
11 #   - Luca Longinotti <chtekk@gentoo.org>
12 # @AUTHOR: Francesco Riosa (Retired) <vivo@gentoo.org>
13 # @BLURB: This eclass provides some helper functions for mysql ebuilds
14 # @DESCRIPTION:
15 # This eclass providers helpers to build mysql servers including patching
16 # from an index and initializing certain variables as part of the build.
17
18 inherit multilib
19
20 # @FUNCTION: stripdots
21 # @DESCRIPTION:
22 # Helper function, version (integer) may have sections separated by dots
23 # for readability.
24 stripdots() {
25         local dotver=${1:-"0"}
26         local v=""
27         local ret=0
28         if [[ "${dotver/./}" != "${dotver}" ]] ; then
29                 # dotted version number
30                 for i in 1000000 10000 100 1 ; do
31                         v=${dotver%%\.*}
32                         # remove leading zeroes
33                         while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
34                         # increment integer version number
35                         ret=$(( ${v} * ${i} + ${ret} ))
36                         if [[ "${dotver}" == "${dotver/\.}" ]] ; then
37                                 dotver=0
38                         else
39                                 dotver=${dotver#*\.}
40                         fi
41                 done
42                 echo "${ret}"
43         else
44                 # already an integer
45                 v=${dotver}
46                 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
47                 echo "${v}"
48         fi
49 }
50
51 # @FUNCTION: mysql_check_version_range
52 # @DESCRIPTION:
53 # Check if a version number falls inside a given range.
54 # The range includes the extremes and must be specified as
55 # "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
56 # Returns true if inside the range.
57 mysql_check_version_range() {
58         local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
59         local rbound="${1#* to }"  ; rbound=$(stripdots "${rbound}")
60         local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
61         [[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
62         return 1
63 }
64
65 # @FUNCTION: _mysql_test_patch_ver_pn
66 # @INTERNAL
67 # @DESCRIPTION:
68 # True if at least one applicable range is found for the patch.
69 _mysql_test_patch_ver_pn() {
70         local allelements=", version, package name"
71         # So that it fails the directory test if none of them exist
72         local filesdir="/dev/null"
73         for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
74                 "${WORKDIR}/mysql-extras" ; do
75                 if [ -d "${d}" ]; then
76                         filesdir="${d}"
77                         break
78                 fi
79         done
80
81         [[ -d "${filesdir}" ]] || die "Source dir must be a directory"
82         local flags=$1 pname=$2
83         if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
84                 einfo "using '${pname}'"
85                 ln -sf "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
86                 return 0
87         fi
88
89         [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
90         && allelements="${allelements//", version"}"
91
92         [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
93         && allelements="${allelements//", package name"}"
94
95         [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
96         && ewarn "QA notice: ${allelements} missing in ${pname} patch"
97
98         return 1
99 }
100
101 # @FUNCTION: mysql_mv_patches
102 # @DESCRIPTION:
103 # Parse a "index_file" looking for patches to apply to the
104 # current MySQL version.
105 # If the patch applies, print its description.
106 #
107 mysql_mv_patches() {
108         # So that it fails the directory test if none of them exist
109         local filesdir="/dev/null"
110         if [[ -z "${1}" ]]; then
111                 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
112                         "${WORKDIR}/mysql-extras" ; do
113                         if [ -d "${d}" ]; then
114                                 filesdir="${d}"
115                                 break
116                         fi
117                 done
118                 [[ -d "${filesdir}" ]] || die "No patches directory found!"
119         fi
120
121         for i in "$1" "${filesdir}/0000_index.txt" "${filesdir}/000_index.txt" ; do
122                 if [ -n "$i" -a -f "$i" ]; then
123                         local index_file="$i"
124                         break
125                 fi
126         done
127
128         local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
129         local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
130         _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
131 }
132
133 # @FUNCTION: _mysql_mv_patches
134 # @INTERNAL
135 _mysql_mv_patches() {
136         local index_file="${1}"
137         local my_ver="${2}"
138         local my_test_fx="${3}"
139         local dsc ndsc=0 i
140         dsc=( )
141
142         # Values for flags are (2^x):
143         #  1 - one patch found
144         #  2 - at least one version range is wrong
145         #  4 - at least one version range is ok
146         #  8 - at least one ${PN} did not match
147         #  16 - at least one ${PN} has been matched
148         local flags=0 pname=""
149         while read row ; do
150                 case "${row}" in
151                         @patch\ *)
152                                 [[ -n "${pname}" ]] \
153                                 && ${my_test_fx} ${flags} "${pname}" \
154                                 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo ">    ${dsc[$i]}" ; done
155                                 flags=1 ; ndsc=0 ; dsc=( )
156                                 pname=${row#"@patch "}
157                                 ;;
158                         @ver\ *)
159                                 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
160                                         flags=$(( ${flags} | 4 ))
161                                 else
162                                         flags=$(( ${flags} | 2 ))
163                                 fi
164                                 ;;
165                         @pn\ *)
166                                 if [[ ${row#"@pn "} == "${PN}" ]] ; then
167                                         flags=$(( ${flags} | 16 ))
168                                 else
169                                         flags=$(( ${flags} | 8 ))
170                                 fi
171                                 ;;
172                         # @use\ *) ;;
173                         @@\ *)
174                                 dsc[$ndsc]="${row#"@@ "}"
175                                 (( ++ndsc ))
176                                 ;;
177                 esac
178         done < "${index_file}"
179
180         ${my_test_fx} ${flags} "${pname}" \
181         && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo ">    ${dsc[$i]}" ; done
182 }
183
184 # @FUNCTION: mysql_version_is_at_least
185 # @DESCRIPTION:
186 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
187 # (nice) idea from versionator.eclass
188 #
189 mysql_version_is_at_least() {
190         local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
191         [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
192         [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
193 }
194
195 # @FUNCTION: mysql_lib_symlinks
196 # @DESCRIPTION:
197 # To be called on the live filesystem, reassigning symlinks of each MySQL
198 # library to the best version available. (Obsolete)
199 #
200 mysql_lib_symlinks() {
201
202         local d dirlist maxdots libname libnameln libsuffix reldir
203         libsuffix=$(get_libname)
204
205         einfo "libsuffix = ${libsuffix}"
206         einfo "Updating MySQL libraries symlinks"
207
208         reldir="${1}"
209         pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
210
211         # dirlist must contain the less significative directory left
212         dirlist="mysql"
213
214         # waste some time in removing and recreating symlinks
215         for d in $dirlist ; do
216                 for libname in $( find "${d}" -mindepth 1 -maxdepth 1 -name "*${libsuffix}*" -and -not -type "l" 2>/dev/null ) ; do
217                         # maxdot is a limit versus infinite loop
218                         maxdots=0
219                         libnameln=${libname##*/}
220                         # loop in version of the library to link it, similar to how
221                         # libtool works
222                         if [[ ${CHOST} == *-darwin* ]] ; then
223                                 # macho: libname.x.y.z.dylib
224                                 local libbasename=${libnameln%%.*}       # libname
225                                 local libver=${libnameln#${libbasename}} # .x.y.z.dylib
226                                 libver=${libver%${libsuffix}}            # .x.y.z
227                                 while [[ -n ${libver} ]] && [[ ${maxdots} -lt 6 ]] ; do
228                                         libnameln="${libbasename}${libver}${libsuffix}"
229                                         rm -f "${libnameln}"
230                                         ln -s "${libname}" "${libnameln}"
231                                         (( ++maxdots ))
232                                         libver=${libver%.*}
233                                 done
234                                 libnameln="${libbasename}${libsuffix}"
235                                 rm -f "${libnameln}"
236                                 ln -s "${libname}" "${libnameln}"
237                         else
238                                 # elf: libname.so.x.y.z
239                                 while [[ ${libnameln:0-3} != '${libsuffix}' ]] && [[ ${maxdots} -lt 6 ]] ; do
240                                         rm -f "${libnameln}"
241                                         ln -s "${libname}" "${libnameln}"
242                                         (( ++maxdots ))
243                                         libnameln="${libnameln%.*}"
244                                 done
245                                 rm -f "${libnameln}"
246                                 ln -s "${libname}" "${libnameln}"
247                         fi
248                 done
249         done
250
251         popd &> /dev/null
252 }
253
254 # @FUNCTION: mysql_init_vars
255 # @DESCRIPTION:
256 # void mysql_init_vars()
257 # Initialize global variables
258 # 2005-11-19 <vivo@gentoo.org>
259 mysql_init_vars() {
260         MY_SHAREDSTATEDIR=${MY_SHAREDSTATEDIR="${EPREFIX}/usr/share/mysql"}
261         MY_SYSCONFDIR=${MY_SYSCONFDIR="${EPREFIX}/etc/mysql"}
262         MY_LOCALSTATEDIR=${MY_LOCALSTATEDIR="${EPREFIX}/var/lib/mysql"}
263         MY_LOGDIR=${MY_LOGDIR="${EPREFIX}/var/log/mysql"}
264         MY_INCLUDEDIR=${MY_INCLUDEDIR="${EPREFIX}/usr/include/mysql"}
265         MY_LIBDIR=${MY_LIBDIR="${EPREFIX}/usr/$(get_libdir)/mysql"}
266
267         if [[ -z "${MY_DATADIR}" ]] ; then
268                 MY_DATADIR=""
269                 if [[ -f "${MY_SYSCONFDIR}/my.cnf" ]] ; then
270                         MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
271                                 | sed -ne '/datadir/s|^--datadir=||p' \
272                                 | tail -n1`
273                         if [[ -z "${MY_DATADIR}" ]] ; then
274                                 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
275                                 | sed -e 's/.*=\s*//' \
276                                 | tail -n1`
277                         fi
278                 fi
279                 if [[ -z "${MY_DATADIR}" ]] ; then
280                         MY_DATADIR="${MY_LOCALSTATEDIR}"
281                         einfo "Using default MY_DATADIR"
282                 fi
283                 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
284
285                 if [[ -z "${PREVIOUS_DATADIR}" ]] ; then
286                         if [[ -e "${MY_DATADIR}" ]] ; then
287                                 # If you get this and you're wondering about it, see bug #207636
288                                 elog "MySQL datadir found in ${MY_DATADIR}"
289                                 elog "A new one will not be created."
290                                 PREVIOUS_DATADIR="yes"
291                         else
292                                 PREVIOUS_DATADIR="no"
293                         fi
294                         export PREVIOUS_DATADIR
295                 fi
296         else
297                 if [[ ${EBUILD_PHASE} == "config" ]]; then
298                         local new_MY_DATADIR
299                         new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
300                                 | sed -ne '/datadir/s|^--datadir=||p' \
301                                 | tail -n1`
302
303                         if [[ ( -n "${new_MY_DATADIR}" ) && ( "${new_MY_DATADIR}" != "${MY_DATADIR}" ) ]]; then
304                                 ewarn "MySQL MY_DATADIR has changed"
305                                 ewarn "from ${MY_DATADIR}"
306                                 ewarn "to ${new_MY_DATADIR}"
307                                 MY_DATADIR="${new_MY_DATADIR}"
308                         fi
309                 fi
310         fi
311
312         if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
313                 MY_SOURCEDIR=${SERVER_URI##*/}
314                 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
315         fi
316
317         export MY_SHAREDSTATEDIR MY_SYSCONFDIR
318         export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
319         export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR
320 }