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

Contents of /eclass/mysql_fx.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Wed Jul 13 07:07:15 2011 UTC (7 years, 3 months ago) by robbat2
Branch: MAIN
Changes since 1.22: +99 -22 lines
Part 2 of MySQL eclass revamp: the split cmake/autotools support.

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

  ViewVC Help
Powered by ViewVC 1.1.20