Openembedded Devel Discussions
 help / color / mirror / Atom feed
From: Chris Larson <clarson@mvista.com>
To: openembedded-devel@openembedded.org
Subject: [PATCH 2/2] collections.inc: add support for collection archives.
Date: Wed,  1 Apr 2009 17:27:18 -0700	[thread overview]
Message-ID: <12386320392475-git-send-email-clarson@mvista.com> (raw)
In-Reply-To: <12386320381719-git-send-email-clarson@mvista.com>

From: Chris Larson <clarson@kergoth.com>

Adds the ability to specify an archive in COLLECTIONS.  Any archives of a
supported format (default tar.gz/tgz/tar.X, tar.bz2/tbz/tbz2, zip/jar) will be
unpacked into COLLECTIONS_UNPACKDIR and used from there.  The default value of COLLECTIONS_UNPACKDIR is ${TMPDIR}/collections.

Signed-off-by: Chris Larson <clarson@kergoth.com>
---
 conf/collections.inc |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/conf/collections.inc b/conf/collections.inc
index 9355b00..e692811 100644
--- a/conf/collections.inc
+++ b/conf/collections.inc
@@ -1,8 +1,72 @@
 # 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_*.
+#
+# 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. """
@@ -38,6 +102,15 @@ def collections_setup(d):
         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))
 
-- 
1.5.2.1




  reply	other threads:[~2009-04-02  0:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02  0:27 [PATCH 1/2] bitbake.conf, collections.inc: Add COLLECTIONS mechanism w/ a sane default Chris Larson
2009-04-02  0:27 ` Chris Larson [this message]
2009-04-02 10:07 ` Graeme Gregory
2009-04-02 19:56   ` Denys Dmytriyenko
2009-04-02 20:28     ` Otavio Salvador
2009-04-03  6:45 ` Holger Schurig
2009-04-03 15:19   ` Chris Larson
2009-04-03  8:54 ` Holger Schurig
2009-04-03 15:17   ` Chris Larson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12386320392475-git-send-email-clarson@mvista.com \
    --to=clarson@mvista.com \
    --cc=openembedded-devel@lists.openembedded.org \
    --cc=openembedded-devel@openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox