[oe-commits] Chris Larson : collections.inc: sync with MVL6.

git version control git at git.openembedded.org
Wed Aug 19 21:57:06 UTC 2009


Module: openembedded.git
Branch: org.openembedded.dev
Commit: 08f57c984f40665424512f3d5e201e471ad70cd2
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=08f57c984f40665424512f3d5e201e471ad70cd2

Author: Chris Larson <clarson at mvista.com>
Date:   Wed Aug 19 14:49:02 2009 -0700

collections.inc: sync with MVL6.

- Gather info on the collections into COLLECTIONSINFO.
- Store the collection info for the current file in COLLECTIONINFO.
- Add has_collection() and get_collection() utility functions.
- Make collection_unpack pass back the collection name.
- Just use != rather than symmetric_difference on the set comparision.
- Set PYTHONPATH for the bitbake re-execution.
- Make the 'Using existing' message use bb.debug.

Signed-off-by: Chris Larson <clarson at mvista.com>

---

 conf/collections.inc |   95 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 58 insertions(+), 37 deletions(-)

diff --git a/conf/collections.inc b/conf/collections.inc
index 0ef6e75..831ca93 100644
--- a/conf/collections.inc
+++ b/conf/collections.inc
@@ -1,3 +1,7 @@
+# Copyright (c) 2009 MontaVista Software, Inc.  All rights reserved.
+#
+# Released under the MIT license (see COPYING.MIT for the terms)
+#
 # 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_*.
@@ -9,7 +13,24 @@
 COLLECTIONS = "${@' '.join(d.getVar('BBPATH', 1).split(':'))}"
 COLLECTIONS_UNPACKDIR = "${TMPDIR}/collections"
 
-def collection_unpack(collection, name, d):
+COLLECTIONINFO = "${@get_collection(d.getVar('FILE', 1), d)}"
+
+def has_collection(name, d):
+    for (uniquename, info) in d.getVar("COLLECTIONSINFO", 1).iteritems():
+        if info["name"] == name:
+            return True
+    return False
+
+def get_collection(file, d):
+    if not os.path.isabs(file):
+        file = bb.which(d.getVar("BBPATH", 1), file)
+    filedir = os.path.realpath(os.path.dirname(file))
+    for (uniquename, info) in d.getVar("COLLECTIONSINFO", 1).iteritems():
+        path = os.path.realpath(info["path"])
+        if filedir.startswith(path + os.path.sep):
+            return info
+
+def collection_unpack(collection, d):
     """ Unpack a collection archive and return the path to it. """
     import bb
     import os
@@ -22,7 +43,16 @@ def collection_unpack(collection, name, d):
         ("zip", "jar"): "unzip -q -o %s",
     }
 
-    outpath = os.path.join(d.getVar("COLLECTIONS_UNPACKDIR", 1), name)
+    basename = os.path.basename(collection)
+    try:
+        cmd, name = ((cmd, basename[:-len(e)-1]) for (exts, cmd) in handlers.iteritems()
+                     for e in exts
+                     if basename.endswith(e)).next()
+    except StopIteration:
+        bb.fatal("No method available to unpack %s (unsupported file type?)" % collection)
+    else:
+        outpath = os.path.join(d.getVar("COLLECTIONS_UNPACKDIR", 1), name)
+        cmd = "cd %s && PATH=\"%s\" %s" % (outpath, d.getVar("PATH", 1), cmd)
 
     try:
         collectiondata = open(collection, "r").read()
@@ -41,20 +71,12 @@ def collection_unpack(collection, name, d):
             pass
         else:
             if oldmd5sum == md5sum:
-                bb.note("Using existing %s for collection '%s'" % (outpath, name))
-                return outpath, False
+                bb.debug(1, "Using existing %s for collection '%s'" % (outpath, name))
+                return outpath, False, name
 
         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)
 
@@ -66,7 +88,7 @@ def collection_unpack(collection, name, d):
     md5out = open(md5file, "w")
     md5out.write(md5sum)
     md5out.close()
-    return outpath, True
+    return outpath, True, name
 
 def collections_setup(d):
     """ Populate collection and bbfiles metadata from the COLLECTIONS var. """
@@ -95,13 +117,7 @@ def collections_setup(d):
 
     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
-
+    collectioninfo = {}
     unpackedthisexec = False
     oldbbpath = d.getVar("BBPATH", 1)
     bbpath = (oldbbpath or "").split(":")
@@ -109,45 +125,50 @@ def collections_setup(d):
         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)
-
+        origpath = collection
         if not os.path.isdir(collection):
-            del collectionmap[collection]
-            unpacked, unpackedthisexec = collection_unpack(collection, name, d)
+            unpacked, unpackedthisexec, name = collection_unpack(collection, d)
             if unpacked:
                 collection = unpacked
-                collectionmap[collection] = name
                 for dir in glob("%s/*/" % collection):
                     if not dir in bbpath:
                         bbpath.append(dir)
             else:
                 bb.fatal("Unable to unpack collection %s" % collection)
         else:
+            name = os.path.basename(collection)
             if not collection in bbpath:
                 bbpath.append(collection)
 
+        if namemap.get(name):
+            name = "%s-%s" % (name, hash(collection))
+        namemap[name] = collection
+        collectionmap[collection] = name
+
+        collectioninfo[name] = {
+            "name": name,
+            "originalpath": origpath,
+            "path": collection,
+            "priority": priority,
+        }
+
         setifunset("BBFILE_PATTERN_%s" % name, "^%s/" % collection)
         setifunset("BBFILE_PRIORITY_%s" % name, str(priority))
 
+    d.setVar("COLLECTIONSINFO", collectioninfo)
+
     setifunset("BBFILE_COLLECTIONS", " ".join(collectionmap.values()))
     setifunset("BBFILES", " ".join(collectionmap.keys()))
 
-    # Strip out the fallback bitbake.conf from BB_RUN_LOCATION
     bbpath = [os.path.realpath(dir) for dir in bbpath if os.path.exists(dir)]
-    try:
-        bbpath.remove(os.path.realpath(bb.data.expand("${BB_RUN_LOCATION}/../share/bitbake", d)))
-    except (OSError, ValueError):
-        pass
-
-    from sets import Set
     d.setVar("BBPATH", ":".join(bbpath))
-    if unpackedthisexec or Set(bbpath).symmetric_difference(Set(oldbbpath.split(":"))):
-        bb.debug(1, "Re-executing bitbake with BBPATH of %s" % d.getVar("BBPATH", 0))
+    if unpackedthisexec or (set(bbpath) != set(oldbbpath.split(":"))):
         import sys
+        bb.debug(1, "Re-executing bitbake with BBPATH of %s" % d.getVar("BBPATH", 0))
         os.environ["BBPATH"] = d.getVar("BBPATH", 0)
-        os.execvpe("bitbake", sys.argv, os.environ)
+        os.environ["PYTHONPATH"] = ":".join(sys.path)
+        sys.argv.insert(0, sys.executable)
+        os.execvpe(sys.executable, sys.argv, os.environ)
 
 addhandler collections_eh
 python collections_eh () {





More information about the Openembedded-commits mailing list