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

Contents of /eclass/mysql_fx.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Sun Mar 9 21:07:55 2008 UTC (10 years, 3 months ago) by robbat2
Branch: MAIN
Changes since 1.20: +2 -2 lines
Symlink patches instead of moving them.

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.20 2007/04/23 19:35:05 swegener 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 local index_file="${1:-"${filesdir}/000_index.txt"}"
110 local my_ver="${2:-"${MYSQL_VERSION_ID}"}"
111 local my_test_fx=${3:-"_mysql_test_patch_ver_pn"}
112 _mysql_mv_patches "${index_file}" "${my_ver}" "${my_test_fx}"
113 }
114
115 _mysql_mv_patches() {
116 local index_file="${1}"
117 local my_ver="${2}"
118 local my_test_fx="${3}"
119 local dsc ndsc=0 i
120 dsc=( )
121
122 # Values for flags are (2^x):
123 # 1 - one patch found
124 # 2 - at least one version range is wrong
125 # 4 - at least one version range is ok
126 # 8 - at least one ${PN} did not match
127 # 16 - at least one ${PN} has been matched
128 local flags=0 pname=""
129 while read row ; do
130 case "${row}" in
131 @patch\ *)
132 [[ -n "${pname}" ]] \
133 && ${my_test_fx} ${flags} "${pname}" \
134 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
135 flags=1 ; ndsc=0 ; dsc=( )
136 pname=${row#"@patch "}
137 ;;
138 @ver\ *)
139 if mysql_check_version_range "${row#"@ver "}" "${my_ver}" ; then
140 flags=$(( ${flags} | 4 ))
141 else
142 flags=$(( ${flags} | 2 ))
143 fi
144 ;;
145 @pn\ *)
146 if [[ ${row#"@pn "} == "${PN}" ]] ; then
147 flags=$(( ${flags} | 16 ))
148 else
149 flags=$(( ${flags} | 8 ))
150 fi
151 ;;
152 # @use\ *) ;;
153 @@\ *)
154 dsc[$ndsc]="${row#"@@ "}"
155 (( ++ndsc ))
156 ;;
157 esac
158 done < "${index_file}"
159
160 ${my_test_fx} ${flags} "${pname}" \
161 && for (( i=0 ; $i < $ndsc ; i++ )) ; do einfo "> ${dsc[$i]}" ; done
162 }
163
164 #
165 # Is $2 (defaults to $MYSQL_VERSION_ID) at least version $1?
166 # (nice) idea from versionator.eclass
167 #
168 mysql_version_is_at_least() {
169 local want_s=$(stripdots "$1") have_s=$(stripdots "${2:-${MYSQL_VERSION_ID}}")
170 [[ -z "${want_s}" ]] && die "mysql_version_is_at_least missing value to check"
171 [[ ${want_s} -le ${have_s} ]] && return 0 || return 1
172 }
173
174 #
175 # To be called on the live filesystem, reassigning symlinks of each MySQL
176 # library to the best version available.
177 #
178 mysql_lib_symlinks() {
179 local d dirlist maxdots soname sonameln reldir
180 reldir="${1}"
181 pushd "${reldir}/usr/$(get_libdir)" &> /dev/null
182 # dirlist must contain the less significative directory left
183 dirlist="mysql"
184
185 # waste some time in removing and recreating symlinks
186 for d in $dirlist ; do
187 for soname in $( find "${d}" -name "*.so*" -and -not -type "l" 2>/dev/null ) ; do
188 # maxdot is a limit versus infinite loop
189 maxdots=0
190 sonameln=${soname##*/}
191 # loop in version of the library to link it, similar to how
192 # libtool works
193 while [[ ${sonameln:0-3} != '.so' ]] && [[ ${maxdots} -lt 6 ]] ; do
194 rm -f "${sonameln}"
195 ln -s "${soname}" "${sonameln}"
196 (( ++maxdots ))
197 sonameln="${sonameln%.*}"
198 done
199 rm -f "${sonameln}"
200 ln -s "${soname}" "${sonameln}"
201 done
202 done
203 popd &> /dev/null
204 }

  ViewVC Help
Powered by ViewVC 1.1.20