/[gentoo-x86]/eclass/mysql_fx.eclass
Gentoo

Diff of /eclass/mysql_fx.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.32

  ViewVC Help
Powered by ViewVC 1.1.20