summaryrefslogtreecommitdiff
path: root/conf/collections.inc
diff options
context:
space:
mode:
authorKoen Kooi <koen@openembedded.org>2009-04-08 18:38:18 +0200
committerKoen Kooi <koen@openembedded.org>2009-04-08 18:38:18 +0200
commite5f45da5c7f73deba4dd2990bfe2da1dfdd05c23 (patch)
treee6b1538274d85fe934d5aaf5947e0e1b02ca6ec9 /conf/collections.inc
parenteda32159da75298d3ab7664ee1e889f8eb24861f (diff)
parent7ab3964056729b3f2c97710973759e626c0ba5ae (diff)
Merge branch 'org.openembedded.dev' of git@git.openembedded.net:openembedded into org.openembedded.dev
Diffstat (limited to 'conf/collections.inc')
-rw-r--r--conf/collections.inc129
1 files changed, 129 insertions, 0 deletions
diff --git a/conf/collections.inc b/conf/collections.inc
new file mode 100644
index 0000000000..245114aed7
--- /dev/null
+++ b/conf/collections.inc
@@ -0,0 +1,129 @@
+# Take a list of directories in COLLECTIONS, in priority order (highest to
+# lowest), and use those to populate BBFILES, BBFILE_COLLECTIONS,
+# BBFILE_PATTERN_*, and BBFILE_PRIORITY_*. By default, COLLECTIONS is
+# prepopulated with the locations the user specified in their BBPATH.
+#
+# Specifying an archive in COLLECTIONS is also supported. Any archives of a
+# supported format will be unpacked into COLLECTIONS_UNPACKDIR and used from
+# there.
+
+COLLECTIONS = "${@' '.join(d.getVar('BBPATH', 1).split(':'))}"
+COLLECTIONS_UNPACKDIR = "${TMPDIR}/collections"
+
+def collection_unpack(collection, name, d):
+ """ Unpack a collection archive and return the path to it. """
+ import bb
+ import os
+ from md5 import md5
+
+ handlers = {
+ ("tar"): "tar x --no-same-owner -f %s",
+ ("tar.gz", "tgz", "tar.Z"): "tar xz --no-same-owner -f %s",
+ ("tar.bz2", "tbz", "tbz2"): "tar xj --no-same-owner -f %s",
+ ("zip", "jar"): "unzip -q -o %s",
+ }
+
+ outpath = os.path.join(d.getVar("COLLECTIONS_UNPACKDIR", 1), name)
+
+ try:
+ collectiondata = open(collection, "r").read()
+ except IOError:
+ bb.fatal("Unable to open %s to calculate md5 sum" % collection)
+
+ md5obj = md5()
+ md5obj.update(collectiondata)
+ md5sum = md5obj.hexdigest()
+
+ md5file = os.path.join(outpath, "md5")
+ if os.path.exists(md5file):
+ try:
+ oldmd5sum = open(md5file).read()
+ except IOError:
+ pass
+ else:
+ if oldmd5sum == md5sum:
+ bb.debug(1, "Using existing %s for collection %s" % (outpath, name))
+ return outpath
+
+ bb.note("Removing old unpacked collection at %s" % outpath)
+ os.system("rm -rf %s" % outpath)
+
+ try:
+ cmd = (cmd for (exts, cmd) in handlers.iteritems()
+ for e in exts
+ if collection.endswith(e)).next()
+ cmd = "cd %s && PATH=\"%s\" %s" % (outpath, d.getVar("PATH", 1), cmd)
+ except StopIteration:
+ bb.fatal("Unable to find unpack handler for %s" % collection)
+
+ if not os.path.isdir(outpath):
+ os.makedirs(outpath)
+
+ bb.note("Unpacking %s to %s/" % (collection, outpath))
+ ret = os.system(cmd % collection)
+ if ret != 0:
+ bb.fatal("Unable to unpack %s" % collection)
+
+ md5out = open(md5file, "w")
+ md5out.write(md5sum)
+ md5out.close()
+ return outpath
+
+def collections_setup(d):
+ """ Populate collection and bbfiles metadata from the COLLECTIONS var. """
+ import bb
+ import os
+ from itertools import izip, chain
+ from glob import glob
+
+ def setifunset(k, v):
+ if d.getVar(k, 0) is None:
+ d.setVar(k, v)
+
+ collections = d.getVar("COLLECTIONS", 1)
+ if not collections:
+ return
+ globbed = (glob(path) for path in collections.split())
+ collections = list(chain(*globbed))
+
+ collectionmap = {}
+ namemap = {}
+ for collection in collections:
+ basename = os.path.basename(collection).split(os.path.extsep)[0]
+ if namemap.get(basename):
+ basename = "%s-%s" % (basename, hash(collection))
+ namemap[basename] = collection
+ collectionmap[collection] = basename
+
+ for (collection, priority) in izip(collections, xrange(len(collections), 0, -1)):
+ if not os.path.exists(collection):
+ bb.fatal("Collection %s does not exist" % collection)
+
+ name = collectionmap[collection]
+ if not name:
+ bb.fatal("Unable to determine collection name for %s" % collection)
+
+ if not os.path.isdir(collection):
+ del collectionmap[collection]
+ unpacked = collection_unpack(collection, name, d)
+ if unpacked:
+ collection = unpacked
+ collectionmap[collection] = name
+ else:
+ bb.fatal("Unable to unpack collection %s" % collection)
+
+ setifunset("BBFILE_PATTERN_%s" % name, "^%s/" % collection)
+ setifunset("BBFILE_PRIORITY_%s" % name, str(priority))
+
+ setifunset("BBFILE_COLLECTIONS", " ".join(collectionmap.values()))
+ setifunset("BBFILES", " ".join(collectionmap.keys()))
+
+addhandler collections_eh
+python collections_eh () {
+ from bb.event import getName
+
+ if getName(e) == "ConfigParsed":
+ collections_setup(e.data)
+
+ return NotHandled
+}