summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorJoshua Lock <josh@linux.intel.com>2010-05-05 16:17:07 +0100
committerJoshua Lock <josh@linux.intel.com>2010-05-06 12:53:16 +0100
commite7fa3529f32f4037fe122699e0d7f3789a871834 (patch)
treed5a8d407a5b0ac84a6a69f5aaff76e114d563da6 /meta
parentac023d775b651c9b1e28a7a725e72949fe54ad47 (diff)
downloadpoky-e7fa3529f32f4037fe122699e0d7f3789a871834.tar.gz
Update classes to use lib/oe
Adapt modifications from upstream to make Poky classes use lib/oe for the common Python functionality. Signed-off-by: Joshua Lock <josh@linux.intel.com>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/base.bbclass26
-rw-r--r--meta/classes/insane.bbclass81
-rw-r--r--meta/classes/patch.bbclass465
-rw-r--r--meta/classes/utils.bbclass107
4 files changed, 74 insertions, 605 deletions
diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index d17f485c02..5594bb72d3 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -8,6 +8,32 @@ inherit utils
8inherit utility-tasks 8inherit utility-tasks
9inherit metadata_scm 9inherit metadata_scm
10 10
11python sys_path_eh () {
12 if isinstance(e, bb.event.ConfigParsed):
13 import sys
14 import os
15 import time
16
17 bbpath = e.data.getVar("BBPATH", True).split(":")
18 sys.path[0:0] = [os.path.join(dir, "lib") for dir in bbpath]
19
20 def inject(name, value):
21 """Make a python object accessible from everywhere for the metadata"""
22 if hasattr(bb.utils, "_context"):
23 bb.utils._context[name] = value
24 else:
25 __builtins__[name] = value
26
27 import oe.path
28 import oe.utils
29 inject("bb", bb)
30 inject("sys", sys)
31 inject("time", time)
32 inject("oe", oe)
33}
34
35addhandler sys_path_eh
36
11die() { 37die() {
12 oefatal "$*" 38 oefatal "$*"
13} 39}
diff --git a/meta/classes/insane.bbclass b/meta/classes/insane.bbclass
index d8cc679283..6d82e4df88 100644
--- a/meta/classes/insane.bbclass
+++ b/meta/classes/insane.bbclass
@@ -75,87 +75,6 @@ def package_qa_get_machine_dict():
75 75
76 } 76 }
77 77
78# factory for a class, embedded in a method
79def package_qa_get_elf(path, bits32):
80 class ELFFile:
81 EI_NIDENT = 16
82
83 EI_CLASS = 4
84 EI_DATA = 5
85 EI_VERSION = 6
86 EI_OSABI = 7
87 EI_ABIVERSION = 8
88
89 # possible values for EI_CLASS
90 ELFCLASSNONE = 0
91 ELFCLASS32 = 1
92 ELFCLASS64 = 2
93
94 # possible value for EI_VERSION
95 EV_CURRENT = 1
96
97 # possible values for EI_DATA
98 ELFDATANONE = 0
99 ELFDATA2LSB = 1
100 ELFDATA2MSB = 2
101
102 def my_assert(self, expectation, result):
103 if not expectation == result:
104 #print "'%x','%x' %s" % (ord(expectation), ord(result), self.name)
105 raise Exception("This does not work as expected")
106
107 def __init__(self, name):
108 self.name = name
109
110 def open(self):
111 self.file = file(self.name, "r")
112 self.data = self.file.read(ELFFile.EI_NIDENT+4)
113
114 self.my_assert(len(self.data), ELFFile.EI_NIDENT+4)
115 self.my_assert(self.data[0], chr(0x7f) )
116 self.my_assert(self.data[1], 'E')
117 self.my_assert(self.data[2], 'L')
118 self.my_assert(self.data[3], 'F')
119 if bits32 :
120 self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS32))
121 else:
122 self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS64))
123 self.my_assert(self.data[ELFFile.EI_VERSION], chr(ELFFile.EV_CURRENT) )
124
125 self.sex = self.data[ELFFile.EI_DATA]
126 if self.sex == chr(ELFFile.ELFDATANONE):
127 raise Exception("self.sex == ELFDATANONE")
128 elif self.sex == chr(ELFFile.ELFDATA2LSB):
129 self.sex = "<"
130 elif self.sex == chr(ELFFile.ELFDATA2MSB):
131 self.sex = ">"
132 else:
133 raise Exception("Unknown self.sex")
134
135 def osAbi(self):
136 return ord(self.data[ELFFile.EI_OSABI])
137
138 def abiVersion(self):
139 return ord(self.data[ELFFile.EI_ABIVERSION])
140
141 def isLittleEndian(self):
142 return self.sex == "<"
143
144 def isBigEngian(self):
145 return self.sex == ">"
146
147 def machine(self):
148 """
149 We know the sex stored in self.sex and we
150 know the position
151 """
152 import struct
153 (a,) = struct.unpack(self.sex+"H", self.data[18:20])
154 return a
155
156 return ELFFile(path)
157
158
159# Known Error classes 78# Known Error classes
160# 0 - non dev contains .so 79# 0 - non dev contains .so
161# 1 - package contains a dangerous RPATH 80# 1 - package contains a dangerous RPATH
diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
index 098bb92b89..b8207680ba 100644
--- a/meta/classes/patch.bbclass
+++ b/meta/classes/patch.bbclass
@@ -3,474 +3,26 @@
3# Point to an empty file so any user's custom settings don't break things 3# Point to an empty file so any user's custom settings don't break things
4QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc" 4QUILTRCFILE ?= "${STAGING_BINDIR_NATIVE}/quiltrc"
5 5
6def patch_init(d):
7 class NotFoundError(Exception):
8 def __init__(self, path):
9 self.path = path
10 def __str__(self):
11 return "Error: %s not found." % self.path
12
13 def md5sum(fname):
14 # when we move to Python 2.5 as minimal supported
15 # we can kill that try/except as hashlib is 2.5+
16 try:
17 import hashlib
18 m = hashlib.md5()
19 except ImportError:
20 import md5
21 m = md5.new()
22
23 try:
24 f = file(fname, 'rb')
25 except IOError:
26 raise NotFoundError(fname)
27
28 while True:
29 d = f.read(8096)
30 if not d:
31 break
32 m.update(d)
33 f.close()
34 return m.hexdigest()
35
36 class CmdError(Exception):
37 def __init__(self, exitstatus, output):
38 self.status = exitstatus
39 self.output = output
40
41 def __str__(self):
42 return "Command Error: exit status: %d Output:\n%s" % (self.status, self.output)
43
44
45 def runcmd(args, dir = None):
46 import commands
47
48 if dir:
49 olddir = os.path.abspath(os.curdir)
50 if not os.path.exists(dir):
51 raise NotFoundError(dir)
52 os.chdir(dir)
53 # print("cwd: %s -> %s" % (olddir, dir))
54
55 try:
56 args = [ commands.mkarg(str(arg)) for arg in args ]
57 cmd = " ".join(args)
58 # print("cmd: %s" % cmd)
59 (exitstatus, output) = commands.getstatusoutput(cmd)
60 if exitstatus != 0:
61 raise CmdError(exitstatus >> 8, output)
62 return output
63
64 finally:
65 if dir:
66 os.chdir(olddir)
67
68 class PatchError(Exception):
69 def __init__(self, msg):
70 self.msg = msg
71
72 def __str__(self):
73 return "Patch Error: %s" % self.msg
74
75 class PatchSet(object):
76 defaults = {
77 "strippath": 1
78 }
79
80 def __init__(self, dir, d):
81 self.dir = dir
82 self.d = d
83 self.patches = []
84 self._current = None
85
86 def current(self):
87 return self._current
88
89 def Clean(self):
90 """
91 Clean out the patch set. Generally includes unapplying all
92 patches and wiping out all associated metadata.
93 """
94 raise NotImplementedError()
95
96 def Import(self, patch, force):
97 if not patch.get("file"):
98 if not patch.get("remote"):
99 raise PatchError("Patch file must be specified in patch import.")
100 else:
101 patch["file"] = bb.fetch.localpath(patch["remote"], self.d)
102
103 for param in PatchSet.defaults:
104 if not patch.get(param):
105 patch[param] = PatchSet.defaults[param]
106
107 if patch.get("remote"):
108 patch["file"] = bb.data.expand(bb.fetch.localpath(patch["remote"], self.d), self.d)
109
110 patch["filemd5"] = md5sum(patch["file"])
111
112 def Push(self, force):
113 raise NotImplementedError()
114
115 def Pop(self, force):
116 raise NotImplementedError()
117
118 def Refresh(self, remote = None, all = None):
119 raise NotImplementedError()
120
121
122 class PatchTree(PatchSet):
123 def __init__(self, dir, d):
124 PatchSet.__init__(self, dir, d)
125
126 def Import(self, patch, force = None):
127 """"""
128 PatchSet.Import(self, patch, force)
129
130 if self._current is not None:
131 i = self._current + 1
132 else:
133 i = 0
134 self.patches.insert(i, patch)
135
136 def _applypatch(self, patch, force = False, reverse = False, run = True):
137 shellcmd = ["cat", patch['file'], "|", "patch", "-p", patch['strippath']]
138 if reverse:
139 shellcmd.append('-R')
140
141 if not run:
142 return "sh" + "-c" + " ".join(shellcmd)
143
144 if not force:
145 shellcmd.append('--dry-run')
146
147 output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
148
149 if force:
150 return
151
152 shellcmd.pop(len(shellcmd) - 1)
153 output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
154 return output
155
156 def Push(self, force = False, all = False, run = True):
157 if all:
158 for i in self.patches:
159 if self._current is not None:
160 self._current = self._current + 1
161 else:
162 self._current = 0
163 bb.note("applying patch %s" % i)
164 self._applypatch(i, force)
165 else:
166 if self._current is not None:
167 self._current = self._current + 1
168 else:
169 self._current = 0
170 bb.note("applying patch %s" % self.patches[self._current])
171 return self._applypatch(self.patches[self._current], force)
172
173
174 def Pop(self, force = None, all = None):
175 if all:
176 for i in self.patches:
177 self._applypatch(i, force, True)
178 else:
179 self._applypatch(self.patches[self._current], force, True)
180
181 def Clean(self):
182 """"""
183
184 class GitApplyTree(PatchTree):
185 def __init__(self, dir, d):
186 PatchTree.__init__(self, dir, d)
187
188 def _applypatch(self, patch, force = False, reverse = False, run = True):
189 shellcmd = ["git", "--git-dir=.", "apply", "-p%s" % patch['strippath']]
190
191 if reverse:
192 shellcmd.append('-R')
193
194 shellcmd.append(patch['file'])
195
196 if not run:
197 return "sh" + "-c" + " ".join(shellcmd)
198
199 return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
200
201
202 class QuiltTree(PatchSet):
203 def _runcmd(self, args, run = True):
204 quiltrc = bb.data.getVar('QUILTRCFILE', self.d, 1)
205 if not run:
206 return ["quilt"] + ["--quiltrc"] + [quiltrc] + args
207 runcmd(["quilt"] + ["--quiltrc"] + [quiltrc] + args, self.dir)
208
209 def _quiltpatchpath(self, file):
210 return os.path.join(self.dir, "patches", os.path.basename(file))
211
212
213 def __init__(self, dir, d):
214 PatchSet.__init__(self, dir, d)
215 self.initialized = False
216 p = os.path.join(self.dir, 'patches')
217 if not os.path.exists(p):
218 os.makedirs(p)
219
220 def Clean(self):
221 try:
222 self._runcmd(["pop", "-a", "-f"])
223 except Exception:
224 pass
225 self.initialized = True
226
227 def InitFromDir(self):
228 # read series -> self.patches
229 seriespath = os.path.join(self.dir, 'patches', 'series')
230 if not os.path.exists(self.dir):
231 raise Exception("Error: %s does not exist." % self.dir)
232 if os.path.exists(seriespath):
233 series = file(seriespath, 'r')
234 for line in series.readlines():
235 patch = {}
236 parts = line.strip().split()
237 patch["quiltfile"] = self._quiltpatchpath(parts[0])
238 patch["quiltfilemd5"] = md5sum(patch["quiltfile"])
239 if len(parts) > 1:
240 patch["strippath"] = parts[1][2:]
241 self.patches.append(patch)
242 series.close()
243
244 # determine which patches are applied -> self._current
245 try:
246 output = runcmd(["quilt", "applied"], self.dir)
247 except CmdError:
248 import sys
249 if sys.exc_value.output.strip() == "No patches applied":
250 return
251 else:
252 raise sys.exc_value
253 output = [val for val in output.split('\n') if not val.startswith('#')]
254 for patch in self.patches:
255 if os.path.basename(patch["quiltfile"]) == output[-1]:
256 self._current = self.patches.index(patch)
257 self.initialized = True
258
259 def Import(self, patch, force = None):
260 if not self.initialized:
261 self.InitFromDir()
262 PatchSet.Import(self, patch, force)
263
264 args = ["import", "-p", patch["strippath"]]
265 if force:
266 args.append("-f")
267 args.append("-dn")
268 args.append(patch["file"])
269
270 self._runcmd(args)
271
272 patch["quiltfile"] = self._quiltpatchpath(patch["file"])
273 patch["quiltfilemd5"] = md5sum(patch["quiltfile"])
274
275 # TODO: determine if the file being imported:
276 # 1) is already imported, and is the same
277 # 2) is already imported, but differs
278
279 self.patches.insert(self._current or 0, patch)
280
281
282 def Push(self, force = False, all = False, run = True):
283 # quilt push [-f]
284
285 args = ["push"]
286 if force:
287 args.append("-f")
288 if all:
289 args.append("-a")
290 if not run:
291 return self._runcmd(args, run)
292
293 self._runcmd(args)
294
295 if self._current is not None:
296 self._current = self._current + 1
297 else:
298 self._current = 0
299
300 def Pop(self, force = None, all = None):
301 # quilt pop [-f]
302 args = ["pop"]
303 if force:
304 args.append("-f")
305 if all:
306 args.append("-a")
307
308 self._runcmd(args)
309
310 if self._current == 0:
311 self._current = None
312
313 if self._current is not None:
314 self._current = self._current - 1
315
316 def Refresh(self, **kwargs):
317 if kwargs.get("remote"):
318 patch = self.patches[kwargs["patch"]]
319 if not patch:
320 raise PatchError("No patch found at index %s in patchset." % kwargs["patch"])
321 (type, host, path, user, pswd, parm) = bb.decodeurl(patch["remote"])
322 if type == "file":
323 import shutil
324 if not patch.get("file") and patch.get("remote"):
325 patch["file"] = bb.fetch.localpath(patch["remote"], self.d)
326
327 shutil.copyfile(patch["quiltfile"], patch["file"])
328 else:
329 raise PatchError("Unable to do a remote refresh of %s, unsupported remote url scheme %s." % (os.path.basename(patch["quiltfile"]), type))
330 else:
331 # quilt refresh
332 args = ["refresh"]
333 if kwargs.get("quiltfile"):
334 args.append(os.path.basename(kwargs["quiltfile"]))
335 elif kwargs.get("patch"):
336 args.append(os.path.basename(self.patches[kwargs["patch"]]["quiltfile"]))
337 self._runcmd(args)
338
339 class Resolver(object):
340 def __init__(self, patchset):
341 raise NotImplementedError()
342
343 def Resolve(self):
344 raise NotImplementedError()
345
346 def Revert(self):
347 raise NotImplementedError()
348
349 def Finalize(self):
350 raise NotImplementedError()
351
352 class NOOPResolver(Resolver):
353 def __init__(self, patchset):
354 self.patchset = patchset
355
356 def Resolve(self):
357 olddir = os.path.abspath(os.curdir)
358 os.chdir(self.patchset.dir)
359 try:
360 self.patchset.Push()
361 except Exception:
362 import sys
363 os.chdir(olddir)
364 raise sys.exc_value
365
366 # Patch resolver which relies on the user doing all the work involved in the
367 # resolution, with the exception of refreshing the remote copy of the patch
368 # files (the urls).
369 class UserResolver(Resolver):
370 def __init__(self, patchset):
371 self.patchset = patchset
372
373 # Force a push in the patchset, then drop to a shell for the user to
374 # resolve any rejected hunks
375 def Resolve(self):
376
377 olddir = os.path.abspath(os.curdir)
378 os.chdir(self.patchset.dir)
379 try:
380 self.patchset.Push(False)
381 except CmdError, v:
382 # Patch application failed
383 patchcmd = self.patchset.Push(True, False, False)
384
385 t = bb.data.getVar('T', d, 1)
386 if not t:
387 bb.msg.fatal(bb.msg.domain.Build, "T not set")
388 bb.mkdirhier(t)
389 import random
390 rcfile = "%s/bashrc.%s.%s" % (t, str(os.getpid()), random.random())
391 f = open(rcfile, "w")
392 f.write("echo '*** Manual patch resolution mode ***'\n")
393 f.write("echo 'Dropping to a shell, so patch rejects can be fixed manually.'\n")
394 f.write("echo 'Run \"quilt refresh\" when patch is corrected, press CTRL+D to exit.'\n")
395 f.write("echo ''\n")
396 f.write(" ".join(patchcmd) + "\n")
397 f.write("#" + bb.data.getVar('TERMCMDRUN', d, 1))
398 f.close()
399 os.chmod(rcfile, 0775)
400
401 bb.utils.build_environment(d)
402 os.environ['TERMWINDOWTITLE'] = "Bitbake: Please fix patch rejects manually"
403 os.environ['TERMRCFILE'] = rcfile
404 bb.debug(bb.data.getVar('TERMCMDRUN', d, 1))
405 rc = os.system(bb.data.getVar('TERMCMDRUN', d, 1))
406 if os.WIFEXITED(rc) and os.WEXITSTATUS(rc) != 0:
407 bb.msg.fatal(bb.msg.domain.Build, ("Cannot proceed with manual patch resolution - '%s' not found. " \
408 + "Check TERMCMDRUN variable.") % bb.data.getVar('TERMCMDRUN', d, 1))
409
410 # Construct a new PatchSet after the user's changes, compare the
411 # sets, checking patches for modifications, and doing a remote
412 # refresh on each.
413 oldpatchset = self.patchset
414 self.patchset = oldpatchset.__class__(self.patchset.dir, self.patchset.d)
415 self.patchset.InitFromDir()
416
417 for patch in self.patchset.patches:
418 oldpatch = None
419 for opatch in oldpatchset.patches:
420 if opatch["quiltfile"] == patch["quiltfile"]:
421 oldpatch = opatch
422
423 if oldpatch:
424 patch["remote"] = oldpatch["remote"]
425 if patch["quiltfile"] == oldpatch["quiltfile"]:
426 if patch["quiltfilemd5"] != oldpatch["quiltfilemd5"]:
427 bb.note("Patch %s has changed, updating remote url %s" % (os.path.basename(patch["quiltfile"]), patch["remote"]))
428 # user change? remote refresh
429 self.patchset.Refresh(remote=True, patch=self.patchset.patches.index(patch))
430 else:
431 # User did not fix the problem. Abort.
432 raise PatchError("Patch application failed, and user did not fix and refresh the patch.")
433 except Exception:
434 os.chdir(olddir)
435 raise
436 os.chdir(olddir)
437
438 g = globals()
439 g["PatchSet"] = PatchSet
440 g["PatchTree"] = PatchTree
441 g["QuiltTree"] = QuiltTree
442 g["GitApplyTree"] = GitApplyTree
443 g["Resolver"] = Resolver
444 g["UserResolver"] = UserResolver
445 g["NOOPResolver"] = NOOPResolver
446 g["NotFoundError"] = NotFoundError
447 g["CmdError"] = CmdError
448 g["PatchError"] = PatchError
449
450addtask patch after do_unpack
451do_patch[dirs] = "${WORKDIR}"
452
453PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot" 6PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot"
454do_patch[depends] = "${PATCHDEPENDENCY}"
455 7
456python patch_do_patch() { 8python patch_do_patch() {
457 patch_init(d) 9 import oe.patch
458 10
459 src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split() 11 src_uri = (bb.data.getVar('SRC_URI', d, 1) or '').split()
460 if not src_uri: 12 if not src_uri:
461 return 13 return
462 14
463 patchsetmap = { 15 patchsetmap = {
464 "patch": PatchTree, 16 "patch": oe.patch.PatchTree,
465 "quilt": QuiltTree, 17 "quilt": oe.patch.QuiltTree,
466 "git": GitApplyTree, 18 "git": oe.patch.GitApplyTree,
467 } 19 }
468 20
469 cls = patchsetmap[bb.data.getVar('PATCHTOOL', d, 1) or 'quilt'] 21 cls = patchsetmap[bb.data.getVar('PATCHTOOL', d, 1) or 'quilt']
470 22
471 resolvermap = { 23 resolvermap = {
472 "noop": NOOPResolver, 24 "noop": oe.patch.NOOPResolver,
473 "user": UserResolver, 25 "user": oe.patch.UserResolver,
474 } 26 }
475 27
476 rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'noop'] 28 rcls = resolvermap[bb.data.getVar('PATCHRESOLVE', d, 1) or 'noop']
@@ -558,9 +110,12 @@ python patch_do_patch() {
558 try: 110 try:
559 patchset.Import({"file":unpacked, "remote":url, "strippath": pnum}, True) 111 patchset.Import({"file":unpacked, "remote":url, "strippath": pnum}, True)
560 resolver.Resolve() 112 resolver.Resolve()
561 except: 113 except Exception:
562 import sys 114 import sys
563 raise bb.build.FuncFailed(str(sys.exc_value)) 115 raise bb.build.FuncFailed(str(sys.exc_value))
564} 116}
565 117
118addtask patch after do_unpack
119do_patch[dirs] = "${WORKDIR}"
120do_patch[depends] = "${PATCHDEPENDENCY}"
566EXPORT_FUNCTIONS do_patch 121EXPORT_FUNCTIONS do_patch
diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
index c2d323235b..f37b565da2 100644
--- a/meta/classes/utils.bbclass
+++ b/meta/classes/utils.bbclass
@@ -1,12 +1,42 @@
1# like os.path.join but doesn't treat absolute RHS specially 1# For compatibility
2def base_path_join(a, *p): 2def base_path_join(a, *p):
3 path = a 3 return oe.path.join(a, *p)
4 for b in p: 4
5 if path == '' or path.endswith('/'): 5def base_path_relative(src, dest):
6 path += b 6 return oe.path.relative(src, dest)
7 else: 7
8 path += '/' + b 8def base_path_out(path, d):
9 return path 9 return oe.path.format_display(path, d)
10
11def base_read_file(filename):
12 return oe.utils.read_file(filename)
13
14def base_ifelse(condition, iftrue = True, iffalse = False):
15 return oe.utils.ifelse(condition, iftrue, iffalse)
16
17def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
18 return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d)
19
20def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
21 return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
22
23def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
24 return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
25
26def base_contains(variable, checkvalues, truevalue, falsevalue, d):
27 return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
28
29def base_both_contain(variable1, variable2, checkvalue, d):
30 return oe.utils.both_contain(variable1, variable2, checkvalue, d)
31
32def base_prune_suffix(var, suffixes, d):
33 return oe.utils.prune_suffix(var, suffixes, d)
34
35def oe_filter(f, str, d):
36 return oe.utils.str_filter(f, str, d)
37
38def oe_filter_out(f, str, d):
39 return oe.utils.str_filter_out(f, str, d)
10 40
11# for MD5/SHA handling 41# for MD5/SHA handling
12def base_chk_load_parser(config_path): 42def base_chk_load_parser(config_path):
@@ -80,67 +110,6 @@ def base_chk_file(parser, pn, pv, src_uri, localpath, data):
80 110
81 return True 111 return True
82 112
83def base_read_file(filename):
84 try:
85 f = file( filename, "r" )
86 except IOError, reason:
87 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
88 else:
89 return f.read().strip()
90 return None
91
92def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
93 if bb.data.getVar(variable,d,1) == checkvalue:
94 return truevalue
95 else:
96 return falsevalue
97
98def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
99 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
100 return truevalue
101 else:
102 return falsevalue
103
104def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
105 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
106 if result <= 0:
107 return truevalue
108 else:
109 return falsevalue
110
111def base_contains(variable, checkvalues, truevalue, falsevalue, d):
112 matches = 0
113 if type(checkvalues).__name__ == "str":
114 checkvalues = [checkvalues]
115 for value in checkvalues:
116 if bb.data.getVar(variable,d,1).find(value) != -1:
117 matches = matches + 1
118 if matches == len(checkvalues):
119 return truevalue
120 return falsevalue
121
122def base_both_contain(variable1, variable2, checkvalue, d):
123 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
124 return checkvalue
125 else:
126 return ""
127
128def base_prune_suffix(var, suffixes, d):
129 # See if var ends with any of the suffixes listed and
130 # remove it if found
131 for suffix in suffixes:
132 if var.endswith(suffix):
133 return var.replace(suffix, "")
134 return var
135
136def oe_filter(f, str, d):
137 from re import match
138 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
139
140def oe_filter_out(f, str, d):
141 from re import match
142 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
143
144oe_soinstall() { 113oe_soinstall() {
145 # Purpose: Install shared library file and 114 # Purpose: Install shared library file and
146 # create the necessary links 115 # create the necessary links