mysql_fx.eclass 8.4 KB

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