summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-04-06 15:29:19 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-07-02 15:41:31 +0100
commita7f05ea4af0aab88cdd8699ed8d73ae3cca04044 (patch)
treef92af687bf067a354f96702b47f21e4dc60764a8 /bitbake/lib
parent2cd161171a245aa758aa14ea3711defc5f60400d (diff)
downloadpoky-a7f05ea4af0aab88cdd8699ed8d73ae3cca04044.tar.gz
Resurrect the old bb.vercmp as bb.utils.vercmp, and its deps
This is just for compatibility. We may drop it in the future, or rewrite it, as it's not particularly pythonic. (Bitbake rev: c4e31d7fe1d15a1e3ef2a453e7c7812d403d22cb) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/__init__.py2
-rw-r--r--bitbake/lib/bb/utils.py143
2 files changed, 144 insertions, 1 deletions
diff --git a/bitbake/lib/bb/__init__.py b/bitbake/lib/bb/__init__.py
index c7cd0f62dd..61973c38a9 100644
--- a/bitbake/lib/bb/__init__.py
+++ b/bitbake/lib/bb/__init__.py
@@ -85,7 +85,7 @@ def fatal(*args):
85from bb.fetch import MalformedUrl, encodeurl, decodeurl 85from bb.fetch import MalformedUrl, encodeurl, decodeurl
86from bb.data import VarExpandError 86from bb.data import VarExpandError
87from bb.utils import mkdirhier, movefile, copyfile, which 87from bb.utils import mkdirhier, movefile, copyfile, which
88from bb.utils import vercmp 88from bb.utils import vercmp_string as vercmp
89 89
90 90
91if __name__ == "__main__": 91if __name__ == "__main__":
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 2e3937ec12..dce80b6342 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -92,6 +92,149 @@ def vercmp(ta, tb):
92 r = vercmp_part(ra, rb) 92 r = vercmp_part(ra, rb)
93 return r 93 return r
94 94
95_package_weights_ = {"pre":-2,"p":0,"alpha":-4,"beta":-3,"rc":-1} # dicts are unordered
96_package_ends_ = ["pre", "p", "alpha", "beta", "rc", "cvs", "bk", "HEAD" ] # so we need ordered list
97
98def relparse(myver):
99 """Parses the last elements of a version number into a triplet, that can
100 later be compared:
101
102 >>> relparse('1.2_pre3')
103 [1.2, -2, 3.0]
104 >>> relparse('1.2b')
105 [1.2, 98, 0]
106 >>> relparse('1.2')
107 [1.2, 0, 0]
108 """
109
110 number = 0
111 p1 = 0
112 p2 = 0
113 mynewver = myver.split('_')
114 if len(mynewver)==2:
115 # an _package_weights_
116 number = float(mynewver[0])
117 match = 0
118 for x in _package_ends_:
119 elen = len(x)
120 if mynewver[1][:elen] == x:
121 match = 1
122 p1 = _package_weights_[x]
123 try:
124 p2 = float(mynewver[1][elen:])
125 except:
126 p2 = 0
127 break
128 if not match:
129 # normal number or number with letter at end
130 divider = len(myver)-1
131 if myver[divider:] not in "1234567890":
132 # letter at end
133 p1 = ord(myver[divider:])
134 number = float(myver[0:divider])
135 else:
136 number = float(myver)
137 else:
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 return [number,p1,p2]
147
148__vercmp_cache__ = {}
149
150def vercmp_string(val1,val2):
151 """This takes two version strings and returns an integer to tell you whether
152 the versions are the same, val1>val2 or val2>val1.
153
154 >>> vercmp('1', '2')
155 -1.0
156 >>> vercmp('2', '1')
157 1.0
158 >>> vercmp('1', '1.0')
159 0
160 >>> vercmp('1', '1.1')
161 -1.0
162 >>> vercmp('1.1', '1_p2')
163 1.0
164 """
165
166 # quick short-circuit
167 if val1 == val2:
168 return 0
169 valkey = val1+" "+val2
170
171 # cache lookup
172 try:
173 return __vercmp_cache__[valkey]
174 try:
175 return - __vercmp_cache__[val2+" "+val1]
176 except KeyError:
177 pass
178 except KeyError:
179 pass
180
181 # consider 1_p2 vc 1.1
182 # after expansion will become (1_p2,0) vc (1,1)
183 # then 1_p2 is compared with 1 before 0 is compared with 1
184 # to solve the bug we need to convert it to (1,0_p2)
185 # by splitting _prepart part and adding it back _after_expansion
186
187 val1_prepart = val2_prepart = ''
188 if val1.count('_'):
189 val1, val1_prepart = val1.split('_', 1)
190 if val2.count('_'):
191 val2, val2_prepart = val2.split('_', 1)
192
193 # replace '-' by '.'
194 # FIXME: Is it needed? can val1/2 contain '-'?
195
196 val1 = string.split(val1,'-')
197 if len(val1) == 2:
198 val1[0] = val1[0] +"."+ val1[1]
199 val2 = string.split(val2,'-')
200 if len(val2) == 2:
201 val2[0] = val2[0] +"."+ val2[1]
202
203 val1 = string.split(val1[0],'.')
204 val2 = string.split(val2[0],'.')
205
206 # add back decimal point so that .03 does not become "3" !
207 for x in range(1,len(val1)):
208 if val1[x][0] == '0' :
209 val1[x] = '.' + val1[x]
210 for x in range(1,len(val2)):
211 if val2[x][0] == '0' :
212 val2[x] = '.' + val2[x]
213
214 # extend varion numbers
215 if len(val2) < len(val1):
216 val2.extend(["0"]*(len(val1)-len(val2)))
217 elif len(val1) < len(val2):
218 val1.extend(["0"]*(len(val2)-len(val1)))
219
220 # add back _prepart tails
221 if val1_prepart:
222 val1[-1] += '_' + val1_prepart
223 if val2_prepart:
224 val2[-1] += '_' + val2_prepart
225 # The above code will extend version numbers out so they
226 # have the same number of digits.
227 for x in range(0,len(val1)):
228 cmp1 = relparse(val1[x])
229 cmp2 = relparse(val2[x])
230 for y in range(0,3):
231 myret = cmp1[y] - cmp2[y]
232 if myret != 0:
233 __vercmp_cache__[valkey] = myret
234 return myret
235 __vercmp_cache__[valkey] = 0
236 return 0
237
95def explode_deps(s): 238def explode_deps(s):
96 """ 239 """
97 Take an RDEPENDS style string of format: 240 Take an RDEPENDS style string of format: