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

Contents of /eclass/mysql_fx.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (show annotations) (download)
Thu Feb 12 05:05:14 2009 UTC (9 years, 4 months ago) by robbat2
Branch: MAIN
Changes since 1.21: +9 -2 lines
Support for four-digit control data.

1 # Copyright 1999-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/mysql_fx.eclass,v 1.21 2008/03/09 21:07:55 robbat2 Exp $
4
5 # Author: Francesco Riosa (Retired) <vivo@gentoo.org>
6 # Maintainer: Luca Longinotti <chtekk@gentoo.org>
7
8 inherit multilib
9
10 #
11 # Helper function, version (integer) may have sections separated by dots
12 # for readability.
13 #
14 stripdots() {
15 local dotver=${1:-"0"}
16 local v=""
17 local ret=0
18 if [[ "${dotver/./}" != "${dotver}" ]] ; then
19 # dotted version number
20 for i in 1000000 10000 100 1 ; do
21 v=${dotver%%\.*}
22 # remove leading zeroes
23 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
24 # increment integer version number
25 ret=$(( ${v} * ${i} + ${ret} ))
26 if [[ "${dotver}" == "${dotver/\.}" ]] ; then
27 dotver=0
28 else
29 dotver=${dotver#*\.}
30 fi
31 done
32 echo "${ret}"
33 else
34 # already an integer
35 v=${dotver}
36 while [[ ${#v} -gt 1 ]] && [[ ${v:0:1} == "0" ]] ; do v=${v#0} ; done
37 echo "${v}"
38 fi
39 }
40
41 #
42 # Check if a version number falls inside a given range.
43 # The range includes the extremes and must be specified as
44 # "low_version to high_version" i.e. "4.1.2 to 5.1.99.99".
45 # Returns true if inside the range.
46 #
47 mysql_check_version_range() {
48 local lbound="${1%% to *}" ; lbound=$(stripdots "${lbound}")
49 local rbound="${1#* to }" ; rbound=$(stripdots "${rbound}")
50 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
51 [[ ${lbound} -le ${my_ver} ]] && [[ ${my_ver} -le ${rbound} ]] && return 0
52 return 1
53 }
54
55 #
56 # True if at least one applicable range is found for the patch.
57 #
58 _mysql_test_patch_ver_pn() {
59 local allelements=", version, package name"
60 # So that it fails the directory test if none of them exist
61 local filesdir="/dev/null"
62 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
63 "${WORKDIR}/mysql-extras" ; do
64 if [ -d "${d}" ]; then
65 filesdir="${d}"
66 break
67 fi
68 done
69
70 [[ -d "${filesdir}" ]] || die "Source dir must be a directory"
71 local flags=$1 pname=$2
72 if [[ $(( $flags & $(( 1 + 4 + 16 )) )) -eq 21 ]] ; then
73 einfo "using '${pname}'"
74 ln -sf "${filesdir}/${pname}" "${EPATCH_SOURCE}" || die "Couldn't move ${pname}"
75 return 0
76 fi
77
78 [[ $(( $flags & $(( 2 + 4 )) )) -gt 0 ]] \
79 && allelements="${allelements//", version"}"
80
81 [[ $(( $flags & $(( 8 + 16 )) )) -gt 0 ]] \
82 && allelements="${allelements//", package name"}"
83
84 [[ -n "${allelements}" ]] && [[ "${flags}" -gt 0 ]] \
85 && ewarn "QA notice: ${allelements} missing in ${pname} patch"
86
87 return 1
88 }
89
90 #
91 # Parse a "index_file" looking for patches to apply to the
92 # current MySQL version.
93 # If the patch applies, print its description.
94 #
95 mysql_mv_patches() {
96 # So that it fails the directory test if none of them exist
97 local filesdir="/dev/null"
98 if [[ -z "${1}" ]]; then
99 for d in "${WORKDIR}/mysql-extras-${MY_EXTRAS_VER}" \
100 "${WORKDIR}/mysql-extras" ; do
101 if [ -d "${d}" ]; then
102 filesdir="${d}"
103 break
104 fi
105 done
106 [[ -d "${filesdir}" ]] || die "No patches directory found!"
107 fi
108
109 for i in "$1" "${filesdir}/0000_index.txt" "${filesdir}/000_index.txt" ; do
110 if [ -n "$i" -a -f "$i" ]; then
111 local index_file="$i"
112 break
113 fi
114 done
115
116 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
117 local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
118 _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
119 }
120
121 _mysql_mv_patches() {
122 local index_file="${1}"
123 local my_ver="${2}"
124 local my_test_fx="${3}"
125 local dsc ndsc=0 i
126 dsc=( )
127
128 # Values for flags are (2^x):
129 # 1 - one patch found
130 # 2 - at least one version range is wrong
131 # 4 - at least one version range is ok
132 # 8 - at least one ${PN} did not match
133 # 16 - at least one ${PN} has been matched
134 local flags=0 pname=""
135 while read row ; do
136 case "${row}" in
137 @patch\ *)
138 [[ -n "${pname}" ]] \
139 && ${my_test_fx} ${flags} "${pname}" \
140 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
141 flags=1 ; ndsc=0 ; dsc=( )
142 pname=${row#"@patch "}
143 ;;
144 @ver\ *)
145 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
146 flags=$(( ${flags} | 4 ))
147 else
148 flags=$(( ${flags} | 2 ))
149 fi
150 ;;
151 @pn\ *)
152 if [[ ${row#"@pn "} == "${PN}" ]] ; then
153 flags=$(( ${flags} | 16 ))
154 else
155 flags=$(( ${flags} | 8 ))
156 fi
157 ;;
158 # @use\ *) ;;
159 @@\ *)
160 dsc[$ndsc]="${row#"@@ "}"
161 (( ++ndsc ))
162 ;;
163 esac
164 done < "${index_file}"
165
166 ${my_test_fx} ${flags} "${pname}" \
167 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
168 }
169
170 #
171 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
172 # (nice) idea from versionator.eclass
173 #
174 mysql_version_is_at_least() {
175 local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
176 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
177 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
178 }
179
180 #
181 # To be called on the live filesystem, reassigning symlinks of each MySQL
182 # library to the best version available.
183 #
184 mysql_lib_symlinks() {
185 einfo "Updating MySQL .so symlinks"
186 local d dirlist maxdots soname sonameln reldir
187 reldir="${1}"
188 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
189 # dirlist must contain the less significative directory left
190 dirlist="mysql"
191
192 # waste some time in removing and recreating symlinks
193 for d in $dirlist ; do
194 for soname in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null ) ; do
195 # maxdot is a limit versus infinite loop
196 maxdots=0
197 sonameln=${soname##*/}
198 # loop in version of the library to link it, similar to how
199 # libtool works
200 while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]] ; do
201 rm -f "${sonameln}"
202 ln -s "${soname}" "${sonameln}"
203 (( ++maxdots ))
204 sonameln="${sonameln%.*}"
205 done
206 rm -f "${sonameln}"
207 ln -s "${soname}" "${sonameln}"
208 done
209 done
210 popd &> /dev/null
211 }

  ViewVC Help
Powered by ViewVC 1.1.20