Use the python modules for checksum generation where we can
authorChris Larson <chris_larson@mentor.com>
Thu, 22 Apr 2010 20:57:01 +0000 (13:57 -0700)
committerChris Larson <chris_larson@mentor.com>
Thu, 22 Apr 2010 22:52:00 +0000 (15:52 -0700)
Based on df32920678d15c86897b50b752b937210a01edea.

Signed-off-by: Chris Larson <chris_larson@mentor.com>
Tested-by: Khem Raj <raj.khem@gmail.com>
Acked-by: Khem Raj <raj.khem@gmail.com>
classes/base.bbclass
classes/utils.bbclass

index d3bfa76..b8499b9 100644 (file)
@@ -37,11 +37,10 @@ def base_dep_prepend(d):
        # the case where host == build == target, for now we don't work in
        # that case though.
        #
-       deps = "shasum-native coreutils-native"
-       if bb.data.getVar('PN', d, True) == "shasum-native" or bb.data.getVar('PN', d, True) == "stagemanager-native":
+       deps = "coreutils-native"
+       if bb.data.getVar('PN', d, True) in ("shasum-native", "stagemanager-native",
+                                            "coreutils-native"):
                deps = ""
-       if bb.data.getVar('PN', d, True) == "coreutils-native":
-               deps = "shasum-native"
 
        # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command.  Whether or  not
        # we need that built is the responsibility of the patch function / class, not
@@ -76,7 +75,6 @@ addtask setscene before do_fetch
 
 addtask fetch
 do_fetch[dirs] = "${DL_DIR}"
-do_fetch[depends] = "shasum-native:do_populate_staging"
 python base_do_fetch() {
        import sys
 
@@ -365,6 +363,8 @@ python () {
     if use_nls != None:
         bb.data.setVar('USE_NLS', use_nls, d)
 
+    setup_checksum_deps(d)
+
     # Git packages should DEPEND on git-native
     srcuri = bb.data.getVar('SRC_URI', d, 1)
     if "git://" in srcuri:
index 1cc6d2b..0252a43 100644 (file)
@@ -84,6 +84,15 @@ def base_chk_load_parser(config_paths):
 
     return parser
 
+def setup_checksum_deps(d):
+    try:
+        import hashlib
+    except ImportError:
+        if d.getVar("PN", True) != "shasum-native":
+            depends = d.getVarFlag("do_fetch", "depends") or ""
+            d.setVarFlag("do_fetch", "depends", "%s %s" %
+                         (depends, "shasum-native:do_populate_staging"))
+
 def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data):
     strict_checking =  bb.data.getVar("OE_STRICT_CHECKSUMS", data, True)
     if not os.path.exists(localpath):
@@ -91,25 +100,18 @@ def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256s
         bb.note("The localpath does not exist '%s'" % localpath)
         raise Exception("The path does not exist '%s'" % localpath)
 
-    try:
-        md5pipe = os.popen('PATH=%s md5sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
-        md5data = (md5pipe.readline().split() or [ "" ])[0]
-        md5pipe.close()
-    except OSError, e:
-        if strict_checking:
-            raise Exception("Executing md5sum failed")
-        else:
-            bb.note("Executing md5sum failed")
-
-    try:
-        shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
-        sha256data = (shapipe.readline().split() or [ "" ])[0]
-        shapipe.close()
-    except OSError, e:
-        if strict_checking:
-            raise Exception("Executing shasum failed")
-        else:
-            bb.note("Executing shasum failed")
+    md5data = bb.utils.md5_file(localpath)
+    sha256data = bb.utils.sha256_file(localpath)
+    if not sha256data:
+        try:
+            shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
+            sha256data = (shapipe.readline().split() or [ "" ])[0]
+            shapipe.close()
+        except OSError, e:
+            if strict_checking:
+                raise Exception("Executing shasum failed")
+            else:
+                bb.note("Executing shasum failed")
 
     if (expected_md5sum == None or expected_md5sum == None):
         from string import maketrans