summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-04 15:03:33 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-05-04 16:44:57 +0100
commitdfd0116a52b1a0d69b7125be5040ef424fc4fa88 (patch)
tree1e6d402f97d9dea5d11956e26bdf9bdb262e8487 /bitbake/lib/bb/utils.py
parent1c34d5822d9cccdfb5954c583f31fa8bdceaf075 (diff)
downloadpoky-dfd0116a52b1a0d69b7125be5040ef424fc4fa88.tar.gz
bitbake/utils: Convert vercmp_string() to use vercmp internally
Having two different version comparision algorithms in bitbake has never seemed like a sensible idea. Worryingly, they also return different results to each other. The vercmp_string API is relatively unused with no users in OE-Core or BitBake itself for example. This patch converts it to use vercmp internalls, bringing consitency to the comparisions which is easy now we have other recently added functions. Yes, this changes behaviour but in this case I'd prefer we were consistent than having two different comparisions. (Bitbake rev: a569c816e016447d60624c59a750709d59a0f455) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py128
1 files changed, 4 insertions, 124 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 1d98bca6ce..7a73419fa3 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -108,130 +108,10 @@ def vercmp(ta, tb):
108 r = vercmp_part(ra, rb) 108 r = vercmp_part(ra, rb)
109 return r 109 return r
110 110
111_package_weights_ = {"pre":-2, "p":0, "alpha":-4, "beta":-3, "rc":-1} # dicts are unordered 111def vercmp_string(a, b):
112_package_ends_ = ["pre", "p", "alpha", "beta", "rc", "cvs", "bk", "HEAD" ] # so we need ordered list 112 ta = split_version(a)
113 113 tb = split_version(b)
114def relparse(myver): 114 return vercmp(ta, tb)
115 """Parses the last elements of a version number into a triplet, that can
116 later be compared.
117 """
118
119 number = 0
120 p1 = 0
121 p2 = 0
122 mynewver = myver.split('_')
123 if len(mynewver) == 2:
124 # an _package_weights_
125 number = float(mynewver[0])
126 match = 0
127 for x in _package_ends_:
128 elen = len(x)
129 if mynewver[1][:elen] == x:
130 match = 1
131 p1 = _package_weights_[x]
132 try:
133 p2 = float(mynewver[1][elen:])
134 except:
135 p2 = 0
136 break
137 if not match:
138 # normal number or number with letter at end
139 divider = len(myver)-1
140 if myver[divider:] not in "1234567890":
141 # letter at end
142 p1 = ord(myver[divider:])
143 number = float(myver[0:divider])
144 else:
145 number = float(myver)
146 else:
147 # normal number or number with letter at end
148 divider = len(myver)-1
149 if myver[divider:] not in "1234567890":
150 #letter at end
151 p1 = ord(myver[divider:])
152 number = float(myver[0:divider])
153 else:
154 number = float(myver)
155 return [number, p1, p2]
156
157__vercmp_cache__ = {}
158
159def vercmp_string(val1, val2):
160 """This takes two version strings and returns an integer to tell you whether
161 the versions are the same, val1>val2 or val2>val1.
162 """
163
164 # quick short-circuit
165 if val1 == val2:
166 return 0
167 valkey = val1 + " " + val2
168
169 # cache lookup
170 try:
171 return __vercmp_cache__[valkey]
172 try:
173 return - __vercmp_cache__[val2 + " " + val1]
174 except KeyError:
175 pass
176 except KeyError:
177 pass
178
179 # consider 1_p2 vc 1.1
180 # after expansion will become (1_p2,0) vc (1,1)
181 # then 1_p2 is compared with 1 before 0 is compared with 1
182 # to solve the bug we need to convert it to (1,0_p2)
183 # by splitting _prepart part and adding it back _after_expansion
184
185 val1_prepart = val2_prepart = ''
186 if val1.count('_'):
187 val1, val1_prepart = val1.split('_', 1)
188 if val2.count('_'):
189 val2, val2_prepart = val2.split('_', 1)
190
191 # replace '-' by '.'
192 # FIXME: Is it needed? can val1/2 contain '-'?
193
194 val1 = val1.split("-")
195 if len(val1) == 2:
196 val1[0] = val1[0] + "." + val1[1]
197 val2 = val2.split("-")
198 if len(val2) == 2:
199 val2[0] = val2[0] + "." + val2[1]
200
201 val1 = val1[0].split('.')
202 val2 = val2[0].split('.')
203
204 # add back decimal point so that .03 does not become "3" !
205 for x in xrange(1, len(val1)):
206 if val1[x][0] == '0' :
207 val1[x] = '.' + val1[x]
208 for x in xrange(1, len(val2)):
209 if val2[x][0] == '0' :
210 val2[x] = '.' + val2[x]
211
212 # extend varion numbers
213 if len(val2) < len(val1):
214 val2.extend(["0"]*(len(val1)-len(val2)))
215 elif len(val1) < len(val2):
216 val1.extend(["0"]*(len(val2)-len(val1)))
217
218 # add back _prepart tails
219 if val1_prepart:
220 val1[-1] += '_' + val1_prepart
221 if val2_prepart:
222 val2[-1] += '_' + val2_prepart
223 # The above code will extend version numbers out so they
224 # have the same number of digits.
225 for x in xrange(0, len(val1)):
226 cmp1 = relparse(val1[x])
227 cmp2 = relparse(val2[x])
228 for y in xrange(0, 3):
229 myret = cmp1[y] - cmp2[y]
230 if myret != 0:
231 __vercmp_cache__[valkey] = myret
232 return myret
233 __vercmp_cache__[valkey] = 0
234 return 0
235 115
236def explode_deps(s): 116def explode_deps(s):
237 """ 117 """