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

Diff of /eclass/versionator.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.2
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2004 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/versionator.eclass,v 1.1 2004/09/10 18:45:01 ciaranm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/versionator.eclass,v 1.2 2004/09/10 21:42:21 ciaranm Exp $
4# 4#
5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org> 5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
6# 6#
7# This eclass provides functions which simplify manipulating $PV and similar 7# This eclass provides functions which simplify manipulating $PV and similar
8# variables. Most functions default to working with $PV, although other 8# variables. Most functions default to working with $PV, although other
21# get_major_version ver_str 21# get_major_version ver_str
22# get_version_component_range range ver_str 22# get_version_component_range range ver_str
23# get_after_major_version ver_str 23# get_after_major_version ver_str
24# replace_version_separator index newvalue ver_str 24# replace_version_separator index newvalue ver_str
25# replace_all_version_separators newvalue ver_str 25# replace_all_version_separators newvalue ver_str
26#
27# There's also:
28# version_is_at_least want have
29# but it's *really* experimental...
26 30
27ECLASS=versionator 31ECLASS=versionator
28INHERITED="$INHERITED $ECLASS" 32INHERITED="$INHERITED $ECLASS"
29 33
30shopt -s extglob 34shopt -s extglob
174 c=( $(get_all_version_components "${2:-${PV}}" ) ) 178 c=( $(get_all_version_components "${2:-${PV}}" ) )
175 c="${c[@]//[-._]/$1}" 179 c="${c[@]//[-._]/$1}"
176 echo ${c// } 180 echo ${c// }
177} 181}
178 182
183# Is $2 (defaults to $PVR) at least version $1? Intended for use in eclasses
184# only. Not very reliable, doesn't understand most things, make sure you test
185# reaaaallly well before using this. Prod ciaranm if you need it to support more
186# things... WARNING: DOES NOT HANDLE 1.2b style versions. WARNING: not very well
187# tested, needs lots of work before it's totally reliable. Use with extreme
188# caution.
189version_is_at_least() {
190 local want_s="$1" have_s="${2:-${PVR}}" want_c have_c
191 want_c=( $(get_version_components "$want_s" ) )
192 have_c=( $(get_version_components "$have_s" ) )
193
194 # Stage 1: compare the version numbers part.
195 local done_w="" done_h="" i=0
196 while [[ -z "${done_w}" ]] || [[ -z "${done_h}" ]] ; do
197 local cur_w="${want_c[$i]}" cur_h="${have_c[$i]}"
198 [[ -z "${cur_w##[^[:digit:]]*}" ]] && done_w="yes"
199 [[ -z "${cur_h##[^[:digit:]]*}" ]] && done_h="yes"
200 [[ -z "${done_w}" ]] || cur_w=0
201 [[ -z "${done_h}" ]] || cur_h=0
202 if [[ ${cur_w} -lt ${cur_h} ]] ; then return 0 ; fi
203 if [[ ${cur_w} -gt ${cur_h} ]] ; then return 1 ; fi
204 i=$(($i + 1))
205 done
206
207 local part
208 for part in "_alpha" "_beta" "_pre" "_rc" "_p" "-r" ; do
209 local part_w= part_h=
210
211 for (( i = 0 ; i < ${#want_c[@]} ; i = $i + 1 )) ; do
212 if [[ -z "${want_c[$i]##${part#[-._]}*}" ]] ; then
213 part_w="${want_c[$i]##${part#[-._]}}"
214 break
215 fi
216 done
217 for (( i = 0 ; i < ${#have_c[@]} ; i = $i + 1 )) ; do
218 if [[ -z "${have_c[$i]##${part#[-._]}*}" ]] ; then
219 part_h="${have_c[$i]##${part#[-._]}}"
220 break
221 fi
222 done
223
224 if [[ "${part}" == "_p" ]] || [[ "${part}" == "-r" ]] ; then
225 # if present in neither want nor have, go to the next item
226 [[ -z "${part_w}" ]] && [[ -z "${part_h}" ]] && continue
227
228 [[ -z "${part_w}" ]] && [[ -n "${part_h}" ]] && return 0
229 [[ -n "${part_w}" ]] && [[ -z "${part_h}" ]] && return 1
230
231 if [[ ${part_w} -lt ${part_h} ]] ; then return 0 ; fi
232 if [[ ${part_w} -gt ${part_h} ]] ; then return 1 ; fi
233
234 else
235 # if present in neither want nor have, go to the next item
236 [[ -z "${part_w}" ]] && [[ -z "${part_h}" ]] && continue
237
238 [[ -z "${part_w}" ]] && [[ -n "${part_h}" ]] && return 1
239 [[ -n "${part_w}" ]] && [[ -z "${part_h}" ]] && return 0
240
241 if [[ ${part_w} -lt ${part_h} ]] ; then return 0 ; fi
242 if [[ ${part_w} -gt ${part_h} ]] ; then return 1 ; fi
243 fi
244 done
245
246 return 0
247}
248
249# Test function thing. To use, source versionator.eclass and then run it.
250__versionator__test_version_is_at_least() {
251 version_is_at_least "1.2" "1.2" || echo "test 1 failed"
252 version_is_at_least "1.2" "1.2.3" || echo "test 2 failed"
253 version_is_at_least "1.2.3" "1.2" && echo "test 3 failed"
254
255 version_is_at_least "1.2_beta1" "1.2" || echo "test 4 failed"
256 version_is_at_least "1.2_alpha1" "1.2" || echo "test 5 failed"
257 version_is_at_least "1.2_alpha1" "1.2_beta1" || echo "test 6 failed"
258
259 version_is_at_least "1.2" "1.2_beta1" && echo "test 7 failed"
260 version_is_at_least "1.2" "1.2_alpha1" && echo "test 8 failed"
261 version_is_at_least "1.2_beta1" "1.2_alpha1" && echo "test 9 failed"
262
263 version_is_at_least "1.2_beta1" "1.2_beta1" || echo "test 10 failed"
264 version_is_at_least "1.2_beta2" "1.2_beta1" && echo "test 11 failed"
265 version_is_at_least "1.2_beta2" "1.2_beta3" || echo "test 12 failed"
266
267 version_is_at_least "1.2-r1" "1.2" && echo "test 13 failed"
268 version_is_at_least "1.2" "1.2-r1" || echo "test 14 failed"
269 version_is_at_least "1.2-r1" "1.3" || echo "test 15 failed"
270 version_is_at_least "1.2-r1" "1.2-r2" || echo "test 16 failed"
271 version_is_at_least "1.2-r3" "1.2-r2" && echo "test 17 failed"
272
273 version_is_at_least "1.2-r1" "1.2_beta2-r3" && echo "test 18 failed"
274 version_is_at_least "1.2-r1" "1.3_beta2-r3" || echo "test 19 failed"
275 return 0
276}
277

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.20