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

Contents of /eclass/versionator.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Tue Nov 22 18:42:10 2011 UTC (3 years ago) by vapier
Branch: MAIN
Changes since 1.19: +3 -2 lines
fix @MAINTAINER formatting

1 vapier 1.14 # Copyright 1999-2008 Gentoo Foundation
2 ciaranm 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.20 # $Header: /var/cvsroot/gentoo-x86/eclass/versionator.eclass,v 1.19 2011/11/22 18:40:14 vapier Exp $
4 vapier 1.14
5     # @ECLASS: versionator.eclass
6     # @MAINTAINER:
7 vapier 1.20 # Jonathan Callen <abcd@gentoo.org>
8     # base-system@gentoo.org
9 vapier 1.14 # @BLURB: functions which simplify manipulation of ${PV} and similar version strings
10     # @DESCRIPTION:
11 ciaranm 1.1 # This eclass provides functions which simplify manipulating $PV and similar
12     # variables. Most functions default to working with $PV, although other
13     # values can be used.
14 vapier 1.14 # @EXAMPLE:
15 ciaranm 1.1 # Simple Example 1: $PV is 1.2.3b, we want 1_2.3b:
16     # MY_PV=$(replace_version_separator 1 '_' )
17     #
18     # Simple Example 2: $PV is 1.4.5, we want 1:
19     # MY_MAJORV=$(get_major_version )
20     #
21 ciaranm 1.3 # Rather than being a number, the index parameter can be a separator character
22     # such as '-', '.' or '_'. In this case, the first separator of this kind is
23     # selected.
24 ciaranm 1.2 #
25     # There's also:
26     # version_is_at_least want have
27 vapier 1.14 # which may be buggy, so use with caution.
28 ciaranm 1.1
29 vapier 1.17 inherit eutils
30 ciaranm 1.1
31 vapier 1.14 # @FUNCTION: get_all_version_components
32     # @USAGE: [version]
33     # @DESCRIPTION:
34 ciaranm 1.1 # Split up a version string into its component parts. If no parameter is
35     # supplied, defaults to $PV.
36     # 0.8.3 -> 0 . 8 . 3
37     # 7c -> 7 c
38     # 3.0_p2 -> 3 . 0 _ p2
39     # 20040905 -> 20040905
40     # 3.0c-r1 -> 3 . 0 c - r1
41     get_all_version_components() {
42 vapier 1.17 eshopts_push -s extglob
43 abcd 1.18 local ver_str=${1:-${PV}} result
44     result=()
45 ciaranm 1.1
46     # sneaky cache trick cache to avoid having to parse the same thing several
47     # times.
48 abcd 1.18 if [[ ${VERSIONATOR_CACHE_VER_STR} == ${ver_str} ]] ; then
49 ciaranm 1.1 echo ${VERSIONATOR_CACHE_RESULT}
50 vapier 1.17 eshopts_pop
51 ciaranm 1.1 return
52     fi
53 abcd 1.18 export VERSIONATOR_CACHE_VER_STR=${ver_str}
54 ciaranm 1.1
55 abcd 1.18 while [[ -n $ver_str ]] ; do
56     case "${ver_str::1}" in
57 ciaranm 1.1 # number: parse whilst we have a number
58     [[:digit:]])
59 abcd 1.18 result+=("${ver_str%%[^[:digit:]]*}")
60     ver_str=${ver_str##+([[:digit:]])}
61 ciaranm 1.1 ;;
62    
63     # separator: single character
64     [-_.])
65 abcd 1.18 result+=("${ver_str::1}")
66     ver_str=${ver_str:1}
67 ciaranm 1.1 ;;
68    
69     # letter: grab the letters plus any following numbers
70     [[:alpha:]])
71 abcd 1.18 local not_match=${ver_str##+([[:alpha:]])*([[:digit:]])}
72     # Can't say "${ver_str::-${#not_match}}" in Bash 3.2
73     result+=("${ver_str::${#ver_str} - ${#not_match}}")
74     ver_str=${not_match}
75 ciaranm 1.1 ;;
76    
77     # huh?
78     *)
79 abcd 1.18 result+=("${ver_str::1}")
80     ver_str=${ver_str:1}
81 ciaranm 1.1 ;;
82     esac
83     done
84    
85 abcd 1.18 export VERSIONATOR_CACHE_RESULT=${result[*]}
86 ciaranm 1.1 echo ${result[@]}
87 vapier 1.17 eshopts_pop
88 ciaranm 1.1 }
89    
90 vapier 1.14 # @FUNCTION: get_version_components
91     # @USAGE: [version]
92     # @DESCRIPTION:
93 ciaranm 1.1 # Get the important version components, excluding '.', '-' and '_'. Defaults to
94     # $PV if no parameter is supplied.
95     # 0.8.3 -> 0 8 3
96     # 7c -> 7 c
97     # 3.0_p2 -> 3 0 p2
98     # 20040905 -> 20040905
99     # 3.0c-r1 -> 3 0 c r1
100     get_version_components() {
101 abcd 1.18 local c=$(get_all_version_components "${1:-${PV}}")
102     echo ${c//[-._]/ }
103 ciaranm 1.1 }
104    
105 vapier 1.14 # @FUNCTION: get_major_version
106     # @USAGE: [version]
107     # @DESCRIPTION:
108 ciaranm 1.1 # Get the major version of a value. Defaults to $PV if no parameter is supplied.
109     # 0.8.3 -> 0
110     # 7c -> 7
111     # 3.0_p2 -> 3
112     # 20040905 -> 20040905
113     # 3.0c-r1 -> 3
114     get_major_version() {
115 abcd 1.18 local c=($(get_all_version_components "${1:-${PV}}"))
116 ciaranm 1.1 echo ${c[0]}
117     }
118    
119 vapier 1.14 # @FUNCTION: get_version_component_range
120 vapier 1.19 # @USAGE: <range> [version]
121 vapier 1.14 # @DESCRIPTION:
122 ciaranm 1.1 # Get a particular component or range of components from the version. If no
123     # version parameter is supplied, defaults to $PV.
124     # 1 1.2.3 -> 1
125     # 1-2 1.2.3 -> 1.2
126     # 2- 1.2.3 -> 2.3
127     get_version_component_range() {
128 vapier 1.17 eshopts_push -s extglob
129 abcd 1.18 local c v="${2:-${PV}}" range="${1}" range_start range_end
130     local -i i=-1 j=0
131     c=($(get_all_version_components "${v}"))
132     range_start=${range%-*}; range_start=${range_start:-1}
133     range_end=${range#*-} ; range_end=${range_end:-${#c[@]}}
134    
135     while ((j < range_start)); do
136     i+=1
137     ((i > ${#c[@]})) && eshopts_pop && return
138     [[ -n "${c[i]//[-._]}" ]] && j+=1
139 ciaranm 1.1 done
140    
141 abcd 1.18 while ((j <= range_end)); do
142     echo -n ${c[i]}
143     ((i > ${#c[@]})) && eshopts_pop && return
144     [[ -n "${c[i]//[-._]}" ]] && j+=1
145     i+=1
146 ciaranm 1.1 done
147 vapier 1.17 eshopts_pop
148 ciaranm 1.1 }
149    
150 vapier 1.14 # @FUNCTION: get_after_major_version
151     # @USAGE: [version]
152     # @DESCRIPTION:
153 ciaranm 1.1 # Get everything after the major version and its separator (if present) of a
154     # value. Defaults to $PV if no parameter is supplied.
155     # 0.8.3 -> 8.3
156     # 7c -> c
157     # 3.0_p2 -> 0_p2
158     # 20040905 -> (empty string)
159     # 3.0c-r1 -> 0c-r1
160     get_after_major_version() {
161 abcd 1.18 echo $(get_version_component_range 2- "${1:-${PV}}")
162 ciaranm 1.1 }
163    
164 opfer 1.15 # @FUNCTION: replace_version_separator
165 vapier 1.14 # @USAGE: <search> <replacement> [subject]
166     # @DESCRIPTION:
167 ciaranm 1.1 # Replace the $1th separator with $2 in $3 (defaults to $PV if $3 is not
168     # supplied). If there are fewer than $1 separators, don't change anything.
169     # 1 '_' 1.2.3 -> 1_2.3
170     # 2 '_' 1.2.3 -> 1.2_3
171     # 1 '_' 1b-2.3 -> 1b_2.3
172 ciaranm 1.3 # Rather than being a number, $1 can be a separator character such as '-', '.'
173     # or '_'. In this case, the first separator of this kind is selected.
174 ciaranm 1.1 replace_version_separator() {
175 vapier 1.17 eshopts_push -s extglob
176 abcd 1.18 local w c v="${3:-${PV}}"
177     declare -i i found=0
178 ciaranm 1.3 w=${1:-1}
179 abcd 1.18 c=($(get_all_version_components ${v}))
180     if [[ ${w} != *[[:digit:]]* ]] ; then
181 ciaranm 1.3 # it's a character, not an index
182 abcd 1.18 for ((i = 0; i < ${#c[@]}; i++)); do
183     if [[ ${c[i]} == ${w} ]]; then
184     c[i]=${2}
185 ciaranm 1.1 break
186     fi
187 ciaranm 1.3 done
188     else
189 abcd 1.18 for ((i = 0; i < ${#c[@]}; i++)); do
190     if [[ -n "${c[i]//[^-._]}" ]]; then
191     found+=1
192     if ((found == w)); then
193     c[i]=${2}
194 ciaranm 1.3 break
195     fi
196     fi
197     done
198     fi
199 abcd 1.18 c=${c[*]}
200 ciaranm 1.1 echo ${c// }
201 vapier 1.17 eshopts_pop
202 ciaranm 1.1 }
203    
204 vapier 1.14 # @FUNCTION: replace_all_version_separators
205     # @USAGE: <replacement> [subject]
206     # @DESCRIPTION:
207 ciaranm 1.1 # Replace all version separators in $2 (defaults to $PV) with $1.
208     # '_' 1b.2.3 -> 1b_2_3
209     replace_all_version_separators() {
210 abcd 1.18 local c=($(get_all_version_components "${2:-${PV}}"))
211     c=${c[@]//[-._]/$1}
212 ciaranm 1.1 echo ${c// }
213     }
214    
215 vapier 1.14 # @FUNCTION: delete_version_separator
216     # @USAGE: <search> [subject]
217     # @DESCRIPTION:
218 ciaranm 1.4 # Delete the $1th separator in $2 (defaults to $PV if $2 is not supplied). If
219 ciaranm 1.3 # there are fewer than $1 separators, don't change anything.
220     # 1 1.2.3 -> 12.3
221     # 2 1.2.3 -> 1.23
222     # 1 1b-2.3 -> 1b2.3
223     # Rather than being a number, $1 can be a separator character such as '-', '.'
224     # or '_'. In this case, the first separator of this kind is deleted.
225     delete_version_separator() {
226     replace_version_separator "${1}" "" "${2}"
227     }
228    
229 vapier 1.14 # @FUNCTION: delete_all_version_separators
230     # @USAGE: [subject]
231     # @DESCRIPTION:
232 ciaranm 1.3 # Delete all version separators in $1 (defaults to $PV).
233 ciaranm 1.5 # 1b.2.3 -> 1b23
234 ciaranm 1.3 delete_all_version_separators() {
235 ciaranm 1.5 replace_all_version_separators "" "${1}"
236 ciaranm 1.3 }
237    
238 vapier 1.14 # @FUNCTION: get_version_component_count
239     # @USAGE: [version]
240     # @DESCRIPTION:
241 kugelfang 1.10 # How many version components are there in $1 (defaults to $PV)?
242     # 1.0.1 -> 3
243     # 3.0c-r1 -> 4
244     get_version_component_count() {
245 abcd 1.18 local a=($(get_version_components "${1:-${PV}}"))
246 kugelfang 1.10 echo ${#a[@]}
247     }
248    
249 vapier 1.14 # @FUNCTION: get_last_version_component_index
250     # @USAGE: [version]
251     # @DESCRIPTION:
252 kugelfang 1.10 # What is the index of the last version component in $1 (defaults to $PV)?
253     # Equivalent to get_version_component_count - 1.
254 abcd 1.18 # 1.0.1 -> 2
255     # 3.0c-r1 -> 3
256 kugelfang 1.10 get_last_version_component_index() {
257 abcd 1.18 echo $(($(get_version_component_count "${1:-${PV}}" ) - 1))
258 kugelfang 1.10 }
259    
260 vapier 1.14 # @FUNCTION: version_is_at_least
261     # @USAGE: <want> [have]
262     # @DESCRIPTION:
263 ciaranm 1.2 # Is $2 (defaults to $PVR) at least version $1? Intended for use in eclasses
264 ciaranm 1.7 # only. May not be reliable, be sure to do very careful testing before actually
265 vapier 1.14 # using this.
266 ciaranm 1.2 version_is_at_least() {
267 ciaranm 1.7 local want_s="$1" have_s="${2:-${PVR}}" r
268     version_compare "${want_s}" "${have_s}"
269     r=$?
270     case $r in
271     1|2)
272     return 0
273     ;;
274     3)
275     return 1
276     ;;
277     *)
278     die "versionator compare bug [atleast, ${want_s}, ${have_s}, ${r}]"
279     ;;
280     esac
281     }
282    
283 vapier 1.14 # @FUNCTION: version_compare
284     # @USAGE: <A> <B>
285     # @DESCRIPTION:
286     # Takes two parameters (A, B) which are versions. If A is an earlier version
287     # than B, returns 1. If A is identical to B, return 2. If A is later than B,
288 ciaranm 1.7 # return 3. You probably want version_is_at_least rather than this function.
289     # May not be very reliable. Test carefully before using this.
290     version_compare() {
291 vapier 1.17 eshopts_push -s extglob
292 abcd 1.18 local ver_a=${1} ver_b=${2} parts_a parts_b
293     local cur_tok_a cur_tok_b num_part_a num_part_b
294     local -i cur_idx_a=0 cur_idx_b=0 prev_idx_a prev_idx_b
295 ciaranm 1.7 parts_a=( $(get_all_version_components "${ver_a}" ) )
296     parts_b=( $(get_all_version_components "${ver_b}" ) )
297    
298     ### compare number parts.
299 abcd 1.18 local -i inf_loop=0
300     while true; do
301     inf_loop+=1
302     ((inf_loop > 20)) && \
303 ciaranm 1.7 die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]"
304    
305 abcd 1.18 # Store the current index to test later
306     prev_idx_a=cur_idx_a
307     prev_idx_b=cur_idx_b
308    
309 ciaranm 1.7 # grab the current number components
310 abcd 1.18 cur_tok_a=${parts_a[cur_idx_a]}
311     cur_tok_b=${parts_b[cur_idx_b]}
312 ciaranm 1.7
313     # number?
314     if [[ -n ${cur_tok_a} ]] && [[ -z ${cur_tok_a//[[:digit:]]} ]] ; then
315 abcd 1.18 cur_idx_a+=1
316     [[ ${parts_a[cur_idx_a]} == . ]] \
317     && cur_idx_a+=1
318 ciaranm 1.7 else
319 abcd 1.18 cur_tok_a=
320 ciaranm 1.7 fi
321    
322     if [[ -n ${cur_tok_b} ]] && [[ -z ${cur_tok_b//[[:digit:]]} ]] ; then
323 abcd 1.18 cur_idx_b+=1
324     [[ ${parts_b[cur_idx_b]} == . ]] \
325     && cur_idx_b+=1
326 ciaranm 1.7 else
327 abcd 1.18 cur_tok_b=
328 ciaranm 1.7 fi
329    
330     # done with number components?
331 abcd 1.18 [[ -z ${cur_tok_a} && -z ${cur_tok_b} ]] && break
332 ciaranm 1.7
333 abcd 1.18 # if a component is blank, then it is the lesser value
334     [[ -z ${cur_tok_a} ]] && eshopts_pop && return 1
335     [[ -z ${cur_tok_b} ]] && eshopts_pop && return 3
336    
337     # According to PMS, if we are *not* in the first number part, and either
338     # token begins with "0", then we use a different algorithm (that
339     # effectively does floating point comparison)
340     if (( prev_idx_a != 0 && prev_idx_b != 0 )) \
341     && [[ ${cur_tok_a} == 0* || ${cur_tok_b} == 0* ]] ; then
342    
343     # strip trailing zeros
344     cur_tok_a=${cur_tok_a%%+(0)}
345     cur_tok_b=${cur_tok_b%%+(0)}
346    
347     # do a *string* comparison of the resulting values: 2 > 11
348     [[ ${cur_tok_a} < ${cur_tok_b} ]] && eshopts_pop && return 1
349     [[ ${cur_tok_a} > ${cur_tok_b} ]] && eshopts_pop && return 3
350     else
351     # to avoid going into octal mode, strip any leading zeros. otherwise
352     # bash will throw a hissy fit on versions like 6.3.068.
353     cur_tok_a=${cur_tok_a##+(0)}
354     cur_tok_b=${cur_tok_b##+(0)}
355    
356     # now if a component is blank, it was originally 0 -- make it so
357     : ${cur_tok_a:=0}
358     : ${cur_tok_b:=0}
359    
360     # compare
361     ((cur_tok_a < cur_tok_b)) && eshopts_pop && return 1
362     ((cur_tok_a > cur_tok_b)) && eshopts_pop && return 3
363     fi
364 ciaranm 1.2 done
365    
366 ciaranm 1.7 ### number parts equal. compare letter parts.
367     local letter_a=
368 abcd 1.18 letter_a=${parts_a[cur_idx_a]}
369     if [[ ${#letter_a} -eq 1 && -z ${letter_a/[a-z]} ]] ; then
370     cur_idx_a+=1
371 ciaranm 1.7 else
372 abcd 1.18 letter_a=@
373 ciaranm 1.7 fi
374    
375     local letter_b=
376 abcd 1.18 letter_b=${parts_b[cur_idx_b]}
377     if [[ ${#letter_b} -eq 1 && -z ${letter_b/[a-z]} ]] ; then
378     cur_idx_b+=1
379 ciaranm 1.7 else
380 abcd 1.18 letter_b=@
381 ciaranm 1.7 fi
382    
383     # compare
384 vapier 1.17 [[ ${letter_a} < ${letter_b} ]] && eshopts_pop && return 1
385     [[ ${letter_a} > ${letter_b} ]] && eshopts_pop && return 3
386 ciaranm 1.7
387     ### letter parts equal. compare suffixes in order.
388 abcd 1.18 inf_loop=0
389     while true ; do
390     inf_loop+=1
391     ((inf_loop > 20)) && \
392     die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]"
393     [[ ${parts_a[cur_idx_a]} == _ ]] && ((cur_idx_a++))
394     [[ ${parts_b[cur_idx_b]} == _ ]] && ((cur_idx_b++))
395    
396     cur_tok_a=${parts_a[cur_idx_a]}
397     cur_tok_b=${parts_b[cur_idx_b]}
398     num_part_a=0
399     num_part_b=0
400    
401     if has ${cur_tok_a%%+([0-9])} "alpha" "beta" "pre" "rc" "p"; then
402     cur_idx_a+=1
403     num_part_a=${cur_tok_a##+([a-z])}
404     # I don't like octal
405     num_part_a=${num_part_a##+(0)}
406     : ${num_part_a:=0}
407     cur_tok_a=${cur_tok_a%%+([0-9])}
408     else
409     cur_tok_a=
410     fi
411 ciaranm 1.7
412 abcd 1.18 if has ${cur_tok_b%%+([0-9])} alpha beta pre rc p; then
413     cur_idx_b+=1
414     num_part_b=${cur_tok_b##+([a-z])}
415     # I still don't like octal
416     num_part_b=${num_part_b##+(0)}
417     : ${num_part_b:=0}
418     cur_tok_b=${cur_tok_b%%+([0-9])}
419     else
420     cur_tok_b=
421     fi
422 ciaranm 1.2
423 abcd 1.18 if [[ ${cur_tok_a} != ${cur_tok_b} ]]; then
424     local suffix
425     for suffix in alpha beta pre rc "" p; do
426     [[ ${cur_tok_a} == ${suffix} ]] && eshopts_pop && return 1
427     [[ ${cur_tok_b} == ${suffix} ]] && eshopts_pop && return 3
428     done
429     elif [[ -z ${cur_tok_a} && -z ${cur_tok_b} ]]; then
430     break
431     else
432     ((num_part_a < num_part_b)) && eshopts_pop && return 1
433     ((num_part_a > num_part_b)) && eshopts_pop && return 3
434     fi
435     done
436 ciaranm 1.2
437 abcd 1.18 # At this point, the only thing that should be left is the -r# part
438     [[ ${parts_a[cur_idx_a]} == - ]] && ((cur_idx_a++))
439     [[ ${parts_b[cur_idx_b]} == - ]] && ((cur_idx_b++))
440    
441     # Sanity check
442     if [[ ${parts_a[cur_idx_a]/r+([0-9])} || ${parts_b[cur_idx_b]/r+([0-9])} ]]; then
443     die "versionator compare bug [revisions, ${ver_a}, ${ver_b}]"
444     fi
445 ciaranm 1.2
446 abcd 1.18 num_part_a=${parts_a[cur_idx_a]#r}
447     num_part_a=${num_part_a##+(0)}
448     : ${num_part_a:=0}
449     num_part_b=${parts_b[cur_idx_b]#r}
450     num_part_b=${num_part_b##+(0)}
451     : ${num_part_b:=0}
452 ciaranm 1.2
453 abcd 1.18 ((num_part_a < num_part_b)) && eshopts_pop && return 1
454     ((num_part_a > num_part_b)) && eshopts_pop && return 3
455 ciaranm 1.7
456     ### no differences.
457 vapier 1.17 eshopts_pop
458 ciaranm 1.7 return 2
459     }
460    
461 vapier 1.14 # @FUNCTION: version_sort
462     # @USAGE: <version> [more versions...]
463     # @DESCRIPTION:
464 ciaranm 1.7 # Returns its parameters sorted, highest version last. We're using a quadratic
465     # algorithm for simplicity, so don't call it with more than a few dozen items.
466     # Uses version_compare, so be careful.
467     version_sort() {
468 vapier 1.17 eshopts_push -s extglob
469 abcd 1.18 local items=
470     local -i left=0
471     items=("$@")
472     while ((left < ${#items[@]})); do
473     local -i lowest_idx=left
474     local -i idx=lowest_idx+1
475     while ((idx < ${#items[@]})); do
476     version_compare "${items[lowest_idx]}" "${items[idx]}"
477     [[ $? -eq 3 ]] && lowest_idx=idx
478     idx+=1
479 ciaranm 1.7 done
480 abcd 1.18 local tmp=${items[lowest_idx]}
481     items[lowest_idx]=${items[left]}
482     items[left]=${tmp}
483     left+=1
484 ciaranm 1.7 done
485     echo ${items[@]}
486 vapier 1.17 eshopts_pop
487 ciaranm 1.7 }
488    
489 vapier 1.16 # @FUNCTION: version_format_string
490     # @USAGE: <format> [version]
491     # @DESCRIPTION:
492     # Reformat complicated version strings. The first argument is the string
493     # to reformat with while the rest of the args are passed on to the
494     # get_version_components function. You should make sure to single quote
495 abcd 1.18 # the first argument since it'll have variables that get delayed expansions.
496 vapier 1.16 # @EXAMPLE:
497     # P="cow-hat-1.2.3_p4"
498     # MY_P=$(version_format_string '${PN}_source_$1_$2-$3_$4')
499     # Now MY_P will be: cow-hat_source_1_2-3_p4
500     version_format_string() {
501     local fstr=$1
502     shift
503     set -- $(get_version_components "$@")
504     eval echo "${fstr}"
505     }
506    
507 ciaranm 1.7 __versionator__test_version_compare() {
508 vapier 1.17 eshopts_push -s extglob
509 ciaranm 1.7 local lt=1 eq=2 gt=3 p q
510    
511     __versionator__test_version_compare_t() {
512     version_compare "${1}" "${3}"
513     local r=$?
514     [[ ${r} -eq ${2} ]] || echo "FAIL: ${@} (got ${r} exp ${2})"
515     }
516    
517     echo "
518     0 $lt 1
519     1 $lt 2
520     2 $gt 1
521     2 $eq 2
522     0 $eq 0
523     10 $lt 20
524     68 $eq 068
525     068 $gt 67
526     068 $lt 69
527    
528     1.0 $lt 2.0
529     2.0 $eq 2.0
530     2.0 $gt 1.0
531    
532     1.0 $gt 0.0
533     0.0 $eq 0.0
534     0.0 $lt 1.0
535    
536     0.1 $lt 0.2
537     0.2 $eq 0.2
538     0.3 $gt 0.2
539    
540     1.2 $lt 2.1
541     2.1 $gt 1.2
542    
543     1.2.3 $lt 1.2.4
544     1.2.4 $gt 1.2.3
545    
546 abcd 1.18 1.2.0 $gt 1.2
547 ciaranm 1.7 1.2.1 $gt 1.2
548     1.2 $lt 1.2.1
549    
550     1.2b $eq 1.2b
551     1.2b $lt 1.2c
552     1.2b $gt 1.2a
553     1.2b $gt 1.2
554     1.2 $lt 1.2a
555    
556     1.3 $gt 1.2a
557     1.3 $lt 1.3a
558    
559     1.0_alpha7 $lt 1.0_beta7
560     1.0_beta $lt 1.0_pre
561     1.0_pre5 $lt 1.0_rc2
562     1.0_rc2 $lt 1.0
563    
564     1.0_p1 $gt 1.0
565     1.0_p1-r1 $gt 1.0_p1
566    
567     1.0_alpha6-r1 $gt 1.0_alpha6
568     1.0_beta6-r1 $gt 1.0_alpha6-r2
569    
570 abcd 1.18 1.0_pre1 $lt 1.0_p1
571 ciaranm 1.7
572     1.0p $gt 1.0_p1
573     1.0r $gt 1.0-r1
574     1.6.15 $gt 1.6.10-r2
575     1.6.10-r2 $lt 1.6.15
576    
577     " | while read a b c ; do
578     [[ -z "${a}${b}${c}" ]] && continue;
579     __versionator__test_version_compare_t "${a}" "${b}" "${c}"
580     done
581 ciaranm 1.2
582    
583 abcd 1.18 for q in "alpha beta pre rc=${lt};${gt}" "p=${gt};${lt}" ; do
584 ciaranm 1.7 for p in ${q%%=*} ; do
585     local c=${q##*=}
586     local alt=${c%%;*} agt=${c##*;}
587     __versionator__test_version_compare_t "1.0" $agt "1.0_${p}"
588     __versionator__test_version_compare_t "1.0" $agt "1.0_${p}1"
589     __versionator__test_version_compare_t "1.0" $agt "1.0_${p}068"
590    
591     __versionator__test_version_compare_t "2.0_${p}" $alt "2.0"
592     __versionator__test_version_compare_t "2.0_${p}1" $alt "2.0"
593     __versionator__test_version_compare_t "2.0_${p}068" $alt "2.0"
594    
595     __versionator__test_version_compare_t "1.0_${p}" $eq "1.0_${p}"
596     __versionator__test_version_compare_t "0.0_${p}" $lt "0.0_${p}1"
597     __versionator__test_version_compare_t "666_${p}3" $gt "666_${p}"
598    
599     __versionator__test_version_compare_t "1_${p}7" $lt "1_${p}8"
600     __versionator__test_version_compare_t "1_${p}7" $eq "1_${p}7"
601     __versionator__test_version_compare_t "1_${p}7" $gt "1_${p}6"
602     __versionator__test_version_compare_t "1_${p}09" $eq "1_${p}9"
603 abcd 1.18
604     __versionator__test_version_compare_t "1_${p}7-r0" $eq "1_${p}7"
605     __versionator__test_version_compare_t "1_${p}7-r0" $lt "1_${p}7-r1"
606     __versionator__test_version_compare_t "1_${p}7-r0" $lt "1_${p}7-r01"
607     __versionator__test_version_compare_t "1_${p}7-r01" $eq "1_${p}7-r1"
608     __versionator__test_version_compare_t "1_${p}8-r1" $gt "1_${p}7-r100"
609    
610     __versionator__test_version_compare_t "1_${p}_alpha" $lt "1_${p}_beta"
611 ciaranm 1.7 done
612 ciaranm 1.2 done
613    
614 ciaranm 1.7 for p in "-r" "_p" ; do
615     __versionator__test_version_compare_t "7.2${p}1" $lt "7.2${p}2"
616     __versionator__test_version_compare_t "7.2${p}2" $gt "7.2${p}1"
617     __versionator__test_version_compare_t "7.2${p}3" $gt "7.2${p}2"
618     __versionator__test_version_compare_t "7.2${p}2" $lt "7.2${p}3"
619     done
620 abcd 1.18
621     # The following tests all come from portage's test cases:
622     __versionator__test_version_compare_t "6.0" $gt "5.0"
623     __versionator__test_version_compare_t "5.0" $gt "5"
624     __versionator__test_version_compare_t "1.0-r1" $gt "1.0-r0"
625     __versionator__test_version_compare_t "1.0-r1" $gt "1.0"
626     __versionator__test_version_compare_t "999999999999999999999999999999" $gt "999999999999999999999999999998"
627     __versionator__test_version_compare_t "1.0.0" $gt "1.0"
628     __versionator__test_version_compare_t "1.0.0" $gt "1.0b"
629     __versionator__test_version_compare_t "1b" $gt "1"
630     __versionator__test_version_compare_t "1b_p1" $gt "1_p1"
631     __versionator__test_version_compare_t "1.1b" $gt "1.1"
632     __versionator__test_version_compare_t "12.2.5" $gt "12.2b"
633    
634     __versionator__test_version_compare_t "4.0" $lt "5.0"
635     __versionator__test_version_compare_t "5" $lt "5.0"
636     __versionator__test_version_compare_t "1.0_pre2" $lt "1.0_p2"
637     __versionator__test_version_compare_t "1.0_alpha2" $lt "1.0_p2"
638     __versionator__test_version_compare_t "1.0_alpha1" $lt "1.0_beta1"
639     __versionator__test_version_compare_t "1.0_beta3" $lt "1.0_rc3"
640     __versionator__test_version_compare_t "1.001000000000000000001" $lt "1.001000000000000000002"
641     __versionator__test_version_compare_t "1.00100000000" $lt "1.0010000000000000001"
642     __versionator__test_version_compare_t "999999999999999999999999999998" $lt "999999999999999999999999999999"
643     __versionator__test_version_compare_t "1.01" $lt "1.1"
644     __versionator__test_version_compare_t "1.0-r0" $lt "1.0-r1"
645     __versionator__test_version_compare_t "1.0" $lt "1.0-r1"
646     __versionator__test_version_compare_t "1.0" $lt "1.0.0"
647     __versionator__test_version_compare_t "1.0b" $lt "1.0.0"
648     __versionator__test_version_compare_t "1_p1" $lt "1b_p1"
649     __versionator__test_version_compare_t "1" $lt "1b"
650     __versionator__test_version_compare_t "1.1" $lt "1.1b"
651     __versionator__test_version_compare_t "12.2b" $lt "12.2.5"
652    
653     __versionator__test_version_compare_t "4.0" $eq "4.0"
654     __versionator__test_version_compare_t "1.0" $eq "1.0"
655     __versionator__test_version_compare_t "1.0-r0" $eq "1.0"
656     __versionator__test_version_compare_t "1.0" $eq "1.0-r0"
657     __versionator__test_version_compare_t "1.0-r0" $eq "1.0-r0"
658     __versionator__test_version_compare_t "1.0-r1" $eq "1.0-r1"
659    
660     # The following were just tests for != in portage, we need something a bit
661     # more precise
662     __versionator__test_version_compare_t "1" $lt "2"
663     __versionator__test_version_compare_t "1.0_alpha" $lt "1.0_pre"
664     __versionator__test_version_compare_t "1.0_beta" $gt "1.0_alpha"
665     __versionator__test_version_compare_t "0" $lt "0.0"
666     __versionator__test_version_compare_t "1.0-r0" $lt "1.0-r1"
667     __versionator__test_version_compare_t "1.0-r1" $gt "1.0-r0"
668     __versionator__test_version_compare_t "1.0" $lt "1.0-r1"
669     __versionator__test_version_compare_t "1.0-r1" $gt "1.0"
670     __versionator__test_version_compare_t "1_p1" $lt "1b_p1"
671     __versionator__test_version_compare_t "1b" $gt "1"
672     __versionator__test_version_compare_t "1.1b" $gt "1.1"
673     __versionator__test_version_compare_t "12.2b" $gt "12.2"
674    
675     # The following tests all come from paludis's test cases:
676     __versionator__test_version_compare_t "1.0" $gt "1"
677     __versionator__test_version_compare_t "1" $lt "1.0"
678     __versionator__test_version_compare_t "1.0_alpha" $gt "1_alpha"
679     __versionator__test_version_compare_t "1.0_alpha" $gt "1"
680     __versionator__test_version_compare_t "1.0_alpha" $lt "1.0"
681     __versionator__test_version_compare_t "1.2.0.0_alpha7-r4" $gt "1.2_alpha7-r4"
682    
683     __versionator__test_version_compare_t "0001" $eq "1"
684     __versionator__test_version_compare_t "01" $eq "001"
685     __versionator__test_version_compare_t "0001.1" $eq "1.1"
686     __versionator__test_version_compare_t "01.01" $eq "1.01"
687     __versionator__test_version_compare_t "1.010" $eq "1.01"
688     __versionator__test_version_compare_t "1.00" $eq "1.0"
689     __versionator__test_version_compare_t "1.0100" $eq "1.010"
690     __versionator__test_version_compare_t "1" $eq "1-r0"
691     __versionator__test_version_compare_t "1-r00" $eq "1-r0"
692    
693 vapier 1.17 eshopts_pop
694 ciaranm 1.2 }

  ViewVC Help
Powered by ViewVC 1.1.20