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

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.20