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

Diff of /eclass/versionator.eclass

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

Revision 1.2 Revision 1.3
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.2 2004/09/10 21:42:21 ciaranm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/versionator.eclass,v 1.3 2005/01/01 22:58:14 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# delete_version_separator index ver_str
27# delete_all_version_separators ver_str
28#
29# Rather than being a number, the index parameter can be a separator character
30# such as '-', '.' or '_'. In this case, the first separator of this kind is
31# selected.
26# 32#
27# There's also: 33# There's also:
28# version_is_at_least want have 34# version_is_at_least want have
29# but it's *really* experimental... 35# but it doesn't work in all cases, so only use it if you know what you're
36# doing.
30 37
31ECLASS=versionator 38ECLASS=versionator
32INHERITED="$INHERITED $ECLASS" 39INHERITED="$INHERITED $ECLASS"
33 40
34shopt -s extglob 41shopt -s extglob
153# Replace the $1th separator with $2 in $3 (defaults to $PV if $3 is not 160# Replace the $1th separator with $2 in $3 (defaults to $PV if $3 is not
154# supplied). If there are fewer than $1 separators, don't change anything. 161# supplied). If there are fewer than $1 separators, don't change anything.
155# 1 '_' 1.2.3 -> 1_2.3 162# 1 '_' 1.2.3 -> 1_2.3
156# 2 '_' 1.2.3 -> 1.2_3 163# 2 '_' 1.2.3 -> 1.2_3
157# 1 '_' 1b-2.3 -> 1b_2.3 164# 1 '_' 1b-2.3 -> 1b_2.3
165# Rather than being a number, $1 can be a separator character such as '-', '.'
166# or '_'. In this case, the first separator of this kind is selected.
158replace_version_separator() { 167replace_version_separator() {
159 local i c found=0 v="${3:-${PV}}" 168 local w i c found=0 v="${3:-${PV}}"
169 w=${1:-1}
160 c=( $(get_all_version_components ${v} ) ) 170 c=( $(get_all_version_components ${v} ) )
171 if [[ "${w//[[:digit:]]/}" == "${w}" ]] ; then
172 # it's a character, not an index
161 for (( i = 0 ; i < ${#c[@]} ; i = $i + 1 )) ; do 173 for (( i = 0 ; i < ${#c[@]} ; i = $i + 1 )) ; do
162 if [[ -n "${c[${i}]//[^-._]}" ]] ; then 174 if [[ "${c[${i}]}" == "${w}" ]] ; then
163 found=$(($found + 1))
164 if [[ "$found" == "${1:-1}" ]] ; then
165 c[${i}]="${2}" 175 c[${i}]="${2}"
166 break 176 break
167 fi 177 fi
168 fi
169 done 178 done
179 else
180 for (( i = 0 ; i < ${#c[@]} ; i = $i + 1 )) ; do
181 if [[ -n "${c[${i}]//[^-._]}" ]] ; then
182 found=$(($found + 1))
183 if [[ "$found" == "${w}" ]] ; then
184 c[${i}]="${2}"
185 break
186 fi
187 fi
188 done
189 fi
170 c=${c[@]} 190 c=${c[@]}
171 echo ${c// } 191 echo ${c// }
172} 192}
173 193
174# Replace all version separators in $2 (defaults to $PV) with $1. 194# Replace all version separators in $2 (defaults to $PV) with $1.
176replace_all_version_separators() { 196replace_all_version_separators() {
177 local c 197 local c
178 c=( $(get_all_version_components "${2:-${PV}}" ) ) 198 c=( $(get_all_version_components "${2:-${PV}}" ) )
179 c="${c[@]//[-._]/$1}" 199 c="${c[@]//[-._]/$1}"
180 echo ${c// } 200 echo ${c// }
201}
202
203# Delete the $1th separator in $3 (defaults to $PV if $3 is not supplied). If
204# there are fewer than $1 separators, don't change anything.
205# 1 1.2.3 -> 12.3
206# 2 1.2.3 -> 1.23
207# 1 1b-2.3 -> 1b2.3
208# Rather than being a number, $1 can be a separator character such as '-', '.'
209# or '_'. In this case, the first separator of this kind is deleted.
210delete_version_separator() {
211 replace_version_separator "${1}" "" "${2}"
212}
213
214# Delete all version separators in $1 (defaults to $PV).
215# '_' 1b.2.3 -> 1b_2_3
216delete_all_version_separators() {
217 replace_all_version_separators "${1}"
181} 218}
182 219
183# Is $2 (defaults to $PVR) at least version $1? Intended for use in eclasses 220# 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 221# 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 222# reaaaallly well before using this. Prod ciaranm if you need it to support more

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

  ViewVC Help
Powered by ViewVC 1.1.20