bitbake.conf, collections.inc: Add COLLECTIONS mechanism w/ a sane default.
[vuplus_openembedded] / conf / collections.inc
1 # Take a list of directories in COLLECTIONS, in priority order (highest to
2 # lowest), and use those to populate BBFILES, BBFILE_COLLECTIONS,
3 # BBFILE_PATTERN_*, and BBFILE_PRIORITY_*.  By default, COLLECTIONS is
4 # prepopulated with the locations the user specified in their BBPATH.
5
6 COLLECTIONS = "${@' '.join(d.getVar('BBPATH', 1).split(':'))}"
7
8 def collections_setup(d):
9     """ Populate collection and bbfiles metadata from the COLLECTIONS var. """
10     import bb
11     import os
12     from itertools import izip, chain
13     from glob import glob
14
15     def setifunset(k, v):
16         if d.getVar(k, 0) is None:
17             d.setVar(k, v)
18
19     collections = d.getVar("COLLECTIONS", 1)
20     if not collections:
21         return
22     globbed = (glob(path) for path in collections.split())
23     collections = list(chain(*globbed))
24
25     collectionmap = {}
26     namemap = {}
27     for collection in collections:
28         basename = os.path.basename(collection).split(os.path.extsep)[0]
29         if namemap.get(basename):
30             basename = "%s-%s" % (basename, hash(collection))
31         namemap[basename] = collection
32         collectionmap[collection] = basename
33
34     for (collection, priority) in izip(collections, xrange(len(collections), 0, -1)):
35         if not os.path.exists(collection):
36             bb.fatal("Collection %s does not exist" % collection)
37
38         name = collectionmap[collection]
39         if not name:
40             bb.fatal("Unable to determine collection name for %s" % collection)
41
42         setifunset("BBFILE_PATTERN_%s" % name, "^%s/" % collection)
43         setifunset("BBFILE_PRIORITY_%s" % name, str(priority))
44
45     setifunset("BBFILE_COLLECTIONS", " ".join(collectionmap.values()))
46     setifunset("BBFILES", " ".join(collectionmap.keys()))
47
48 addhandler collections_eh
49 python collections_eh () {
50     from bb.event import getName
51
52     if getName(e) == "ConfigParsed":
53         collections_setup(e.data)
54
55     return NotHandled
56 }