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

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

  ViewVC Help
Powered by ViewVC 1.1.20