1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Recent versions have begun deprecating this eclass.
6 # Do not use it in new series.
8 # @ECLASS: mysql_fx.eclass
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
15 # This eclass providers helpers to build mysql servers including patching
16 # from an index and initializing certain variables as part of the build.
20 # @FUNCTION: stripdots
22 # Helper function, version (integer) may have sections separated by dots
25 local dotver=${1:-"0"}
28 if [[ "${dotver/./}" != "${dotver}" ]] ; then
29 # dotted version number
30 for i in 1000000 10000 100 1 ; do
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
46 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
51 # @FUNCTION: mysql_check_version_range
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
65 # @FUNCTION: _mysql_test_patch_ver_pn
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
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}"
89 [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
90 && allelements="${allelements//", version"}"
92 [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
93 && allelements="${allelements//", package name"}"
95 [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
96 && ewarn "QA notice: ${allelements} missing in ${pname} patch"
101 # @FUNCTION: mysql_mv_patches
103 # Parse a "index_file" looking for patches to apply to the
104 # current MySQL version.
105 # If the patch applies, print its description.
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
118 [[ -d "${filesdir}" ]] || die "No patches directory found!"
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"
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}"
133 # @FUNCTION: _mysql_mv_patches
135 _mysql_mv_patches() {
136 local index_file="${1}"
138 local my_test_fx="${3}"
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=""
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 "}
159 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
160 flags=$(( ${flags} | 4 ))
162 flags=$(( ${flags} | 2 ))
166 if [[ ${row#"@pn "} == "${PN}" ]] ; then
167 flags=$(( ${flags} | 16 ))
169 flags=$(( ${flags} | 8 ))
174 dsc[$ndsc]="${row#"@@ "}"
178 done < "${index_file}"
180 ${my_test_fx} ${flags} "${pname}" \
181 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
184 # @FUNCTION: mysql_version_is_at_least
186 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
187 # (nice) idea from versionator.eclass
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
195 # @FUNCTION: mysql_lib_symlinks
197 # To be called on the live filesystem, reassigning symlinks of each MySQL
198 # library to the best version available. (Obsolete)
200 mysql_lib_symlinks() {
202 local d dirlist maxdots libname libnameln libsuffix reldir
203 libsuffix=$(get_libname)
205 einfo "libsuffix = ${libsuffix}"
206 einfo "Updating MySQL libraries symlinks"
209 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
211 # dirlist must contain the less significative directory left
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
219 libnameln=${libname##*/}
220 # loop in version of the library to link it, similar to how
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}"
230 ln -s "${libname}" "${libnameln}"
234 libnameln="${libbasename}${libsuffix}"
236 ln -s "${libname}" "${libnameln}"
238 # elf: libname.so.x.y.z
239 while [[ ${libnameln:0-3} != '${libsuffix}' ]] && [[ ${maxdots} -lt 6 ]] ; do
241 ln -s "${libname}" "${libnameln}"
243 libnameln="${libnameln%.*}"
246 ln -s "${libname}" "${libnameln}"
254 # @FUNCTION: mysql_init_vars
256 # void mysql_init_vars()
257 # Initialize global variables
258 # 2005-11-19 <vivo@gentoo.org>
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"}
267 if [[ -z "${MY_DATADIR}" ]] ; then
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' \
273 if [[ -z "${MY_DATADIR}" ]] ; then
274 MY_DATADIR=`grep ^datadir "${MY_SYSCONFDIR}/my.cnf" \
275 | sed -e 's/.*=\s*//' \
279 if [[ -z "${MY_DATADIR}" ]] ; then
280 MY_DATADIR="${MY_LOCALSTATEDIR}"
281 einfo "Using default MY_DATADIR"
283 elog "MySQL MY_DATADIR is ${MY_DATADIR}"
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"
292 PREVIOUS_DATADIR="no"
294 export PREVIOUS_DATADIR
297 if [[ ${EBUILD_PHASE} == "config" ]]; then
299 new_MY_DATADIR=`"my_print_defaults" mysqld 2>/dev/null \
300 | sed -ne '/datadir/s|^--datadir=||p' \
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}"
312 if [ "${MY_SOURCEDIR:-unset}" == "unset" ]; then
313 MY_SOURCEDIR=${SERVER_URI##*/}
314 MY_SOURCEDIR=${MY_SOURCEDIR%.tar*}
317 export MY_SHAREDSTATEDIR MY_SYSCONFDIR
318 export MY_LIBDIR MY_LOCALSTATEDIR MY_LOGDIR
319 export MY_INCLUDEDIR MY_DATADIR MY_SOURCEDIR