summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/ast.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-03-19 17:22:19 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2010-03-25 17:25:45 +0000
commitc24424327409544807a781bba4e6f9a8e178dcce (patch)
tree5df97b6f8665f6cdf9a9698c05e2a98f58bd5975 /bitbake/lib/bb/parse/ast.py
parentcefeeb1aa30a9d8744a6ff9c51811ebc8d18c735 (diff)
downloadpoky-c24424327409544807a781bba4e6f9a8e178dcce.tar.gz
Implement BBVERSIONS
This implements a feature similar to BBCLASSEXTEND, but for generating multiple versions of a given recipe. For example: BBVERSIONS = "1.0 2.0 git". In addition to the above, one can utilize [a-b] style patterns, and can have a :<basever> postfix, which allows you to essentially name the range of versions. Both the current version and the basever end up in OVERRIDES, and the basever gets placed into the BPV variable. The default BPV, if none is specified, is the original PV of the recipe, before bbversions processing. In this way, you can do things like: BBVERSIONS = "1.0.[0-6]:1.0.0+ 1.0.[7-9]:1.0.7+" SRC_URI_append_1.0.7+ = "file://some_extra_patch.patch;patch=1" Or you can create a recipe per range, and name the recipe file as such: nano_1.0.7+.bb. (Bitbake rev: 4ee9a56e16f1eb3c1649eaa3127b09ab0e93d1ec) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/parse/ast.py')
-rw-r--r--bitbake/lib/bb/parse/ast.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index 70a69b8d14..59aa44bee0 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -22,9 +22,11 @@
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 23
24import bb, re, string 24import bb, re, string
25from itertools import chain
25 26
26__word__ = re.compile(r"\S+") 27__word__ = re.compile(r"\S+")
27__parsed_methods__ = bb.methodpool.get_parsed_dict() 28__parsed_methods__ = bb.methodpool.get_parsed_dict()
29_bbversions_re = re.compile(r"\[(?P<from>[0-9]+)-(?P<to>[0-9]+)\]")
28 30
29class StatementGroup(list): 31class StatementGroup(list):
30 def eval(self, data): 32 def eval(self, data):
@@ -335,3 +337,115 @@ def finalise(fn, d):
335 337
336 bb.event.fire(bb.event.RecipeParsed(fn), d) 338 bb.event.fire(bb.event.RecipeParsed(fn), d)
337 339
340def _create_variants(datastores, names, function):
341 def create_variant(name, orig_d, arg = None):
342 new_d = bb.data.createCopy(orig_d)
343 function(arg or name, new_d)
344 datastores[name] = new_d
345
346 for variant, variant_d in datastores.items():
347 for name in names:
348 if not variant:
349 # Based on main recipe
350 create_variant(name, variant_d)
351 else:
352 create_variant("%s-%s" % (variant, name), variant_d, name)
353
354def _expand_versions(versions):
355 def expand_one(version, start, end):
356 for i in xrange(start, end + 1):
357 ver = _bbversions_re.sub(str(i), version, 1)
358 yield ver
359
360 versions = iter(versions)
361 while True:
362 try:
363 version = versions.next()
364 except StopIteration:
365 break
366
367 range_ver = _bbversions_re.search(version)
368 if not range_ver:
369 yield version
370 else:
371 newversions = expand_one(version, int(range_ver.group("from")),
372 int(range_ver.group("to")))
373 versions = chain(newversions, versions)
374
375def multi_finalize(fn, d):
376 safe_d = d
377
378 d = bb.data.createCopy(safe_d)
379 try:
380 finalise(fn, d)
381 except bb.parse.SkipPackage:
382 bb.data.setVar("__SKIPPED", True, d)
383 datastores = {"": safe_d}
384
385 versions = (d.getVar("BBVERSIONS", True) or "").split()
386 if versions:
387 pv = orig_pv = d.getVar("PV", True)
388 baseversions = {}
389
390 def verfunc(ver, d, pv_d = None):
391 if pv_d is None:
392 pv_d = d
393
394 overrides = d.getVar("OVERRIDES", True).split(":")
395 pv_d.setVar("PV", ver)
396 overrides.append(ver)
397 bpv = baseversions.get(ver) or orig_pv
398 pv_d.setVar("BPV", bpv)
399 overrides.append(bpv)
400 d.setVar("OVERRIDES", ":".join(overrides))
401
402 versions = list(_expand_versions(versions))
403 for pos, version in enumerate(list(versions)):
404 try:
405 pv, bpv = version.split(":", 2)
406 except ValueError:
407 pass
408 else:
409 versions[pos] = pv
410 baseversions[pv] = bpv
411
412 if pv in versions and not baseversions.get(pv):
413 versions.remove(pv)
414 else:
415 pv = versions.pop()
416
417 # This is necessary because our existing main datastore
418 # has already been finalized with the old PV, we need one
419 # that's been finalized with the new PV.
420 d = bb.data.createCopy(safe_d)
421 verfunc(pv, d, safe_d)
422 try:
423 finalise(fn, d)
424 except bb.parse.SkipPackage:
425 bb.data.setVar("__SKIPPED", True, d)
426
427 _create_variants(datastores, versions, verfunc)
428
429 extended = d.getVar("BBCLASSEXTEND", True) or ""
430 if extended:
431 pn = d.getVar("PN", True)
432 def extendfunc(name, d):
433 d.setVar("PN", "%s-%s" % (pn, name))
434 bb.parse.BBHandler.inherit([name], d)
435
436 safe_d.setVar("BBCLASSEXTEND", extended)
437 _create_variants(datastores, extended.split(), extendfunc)
438
439 for variant, variant_d in datastores.items():
440 if variant:
441 try:
442 finalise(fn, variant_d)
443 except bb.parse.SkipPackage:
444 bb.data.setVar("__SKIPPED", True, variant_d)
445
446 if len(datastores) > 1:
447 variants = filter(None, datastores.keys())
448 safe_d.setVar("__VARIANTS", " ".join(variants))
449
450 datastores[""] = d
451 return datastores