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

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

  ViewVC Help
Powered by ViewVC 1.1.20