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_*.
5 # Specifying an archive in COLLECTIONS is also supported. Any archives of a
6 # supported format will be unpacked into COLLECTIONS_UNPACKDIR and used from
9 COLLECTIONS = "${@' '.join(d.getVar('BBPATH', 1).split(':'))}"
10 COLLECTIONS_UNPACKDIR = "${TMPDIR}/collections"
12 def collection_unpack(collection, name, d):
13 """ Unpack a collection archive and return the path to it. """
19 ("tar"): "tar x --no-same-owner -f %s",
20 ("tar.gz", "tgz", "tar.Z"): "tar xz --no-same-owner -f %s",
21 ("tar.bz2", "tbz", "tbz2"): "tar xj --no-same-owner -f %s",
22 ("zip", "jar"): "unzip -q -o %s",
25 outpath = os.path.join(d.getVar("COLLECTIONS_UNPACKDIR", 1), name)
28 collectiondata = open(collection, "r").read()
30 bb.fatal("Unable to open %s to calculate md5 sum" % collection)
33 md5obj.update(collectiondata)
34 md5sum = md5obj.hexdigest()
36 md5file = os.path.join(outpath, "md5")
37 if os.path.exists(md5file):
39 oldmd5sum = open(md5file).read()
43 if oldmd5sum == md5sum:
44 bb.note("Using existing %s for collection '%s'" % (outpath, name))
47 bb.note("Removing old unpacked collection at %s" % outpath)
48 os.system("rm -rf %s" % outpath)
51 cmd = (cmd for (exts, cmd) in handlers.iteritems()
53 if collection.endswith(e)).next()
54 cmd = "cd %s && PATH=\"%s\" %s" % (outpath, d.getVar("PATH", 1), cmd)
56 bb.fatal("Unable to find unpack handler for %s" % collection)
58 if not os.path.isdir(outpath):
61 bb.note("Unpacking %s to %s/" % (collection, outpath))
62 ret = os.system(cmd % collection)
64 bb.fatal("Unable to unpack %s" % collection)
66 md5out = open(md5file, "w")
71 def collections_setup(d):
72 """ Populate collection and bbfiles metadata from the COLLECTIONS var. """
75 from itertools import izip, chain
79 if d.getVar(k, 0) is None:
82 collections = d.getVar("COLLECTIONS", 1)
86 bb.debug(1, "Processing COLLECTIONS (%s)" % collections)
89 for path in collections.split():
90 paths = glob(os.path.normpath(path))
92 bb.msg.warn(None, "No matches in filesystem for %s in COLLECTIONS" % path)
98 for collection in collections:
99 basename = os.path.basename(collection).split(os.path.extsep)[0]
100 if namemap.get(basename):
101 basename = "%s-%s" % (basename, hash(collection))
102 namemap[basename] = collection
103 collectionmap[collection] = basename
105 unpackedthisexec = False
106 oldbbpath = d.getVar("BBPATH", 1)
107 bbpath = (oldbbpath or "").split(":")
108 for (collection, priority) in izip(collections, xrange(len(collections), 0, -1)):
109 if not os.path.exists(collection):
110 bb.fatal("Collection %s does not exist" % collection)
112 name = collectionmap[collection]
114 bb.fatal("Unable to determine collection name for %s" % collection)
116 if not os.path.isdir(collection):
117 del collectionmap[collection]
118 unpacked, unpackedthisexec = collection_unpack(collection, name, d)
120 collection = unpacked
121 collectionmap[collection] = name
122 for dir in glob("%s/*/" % collection):
123 if not dir in bbpath:
126 bb.fatal("Unable to unpack collection %s" % collection)
128 if not collection in bbpath:
129 bbpath.append(collection)
131 setifunset("BBFILE_PATTERN_%s" % name, "^%s/" % collection)
132 setifunset("BBFILE_PRIORITY_%s" % name, str(priority))
134 setifunset("BBFILE_COLLECTIONS", " ".join(collectionmap.values()))
135 setifunset("BBFILES", " ".join(collectionmap.keys()))
137 # Strip out the fallback bitbake.conf from BB_RUN_LOCATION
138 bbpath = [os.path.realpath(dir) for dir in bbpath if os.path.exists(dir)]
140 bbpath.remove(os.path.realpath(bb.data.expand("${BB_RUN_LOCATION}/../share/bitbake", d)))
141 except (OSError, ValueError):
145 d.setVar("BBPATH", ":".join(bbpath))
146 if unpackedthisexec or Set(bbpath).symmetric_difference(Set(oldbbpath.split(":"))):
147 bb.debug(1, "Re-executing bitbake with BBPATH of %s" % d.getVar("BBPATH", 0))
149 os.environ["BBPATH"] = d.getVar("BBPATH", 0)
150 os.execvpe("bitbake", sys.argv, os.environ)
152 addhandler collections_eh
153 python collections_eh () {
154 from bb.event import getName
156 if getName(e) == "ConfigParsed":
157 collections_setup(e.data)