[oe] [STABLE][PATCH] base.bbclass: add support for checksums in .bb files

Vitus Jensen vjensen at gmx.de
Tue Apr 13 13:35:27 UTC 2010


From: Phil Blundell <philb at gnu.org>

Ported from .dev branch to allow easy sharing of recipes between
.dev and stable branches.

Signed-off-by: Vitus Jensen <vjensen at gmx.de>
---
  classes/base.bbclass |   56 ++++++++++++++++++++++++++++++++++++++++++++-----
  1 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/classes/base.bbclass b/classes/base.bbclass
index 69d1979..459fbe9 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -56,6 +56,50 @@ def base_chk_load_parser(config_paths):

      return parser

+def base_chk_file_vars(parser, localpath, params, data):
+    try:
+        name = params["name"]
+    except KeyError:
+        return False
+    flagName = "%s.md5sum" % name
+    want_md5sum = bb.data.getVarFlag("SRC_URI", flagName, data)
+    flagName = "%s.sha256sum" % name
+    want_sha256sum = bb.data.getVarFlag("SRC_URI", flagName, data)
+
+    if (want_sha256sum == None and want_md5sum == None):
+        # no checksums to check, nothing to do
+        return False
+
+    if not os.path.exists(localpath):
+        localpath = base_path_out(localpath, data)
+        bb.note("The localpath does not exist '%s'" % localpath)
+        raise Exception("The path does not exist '%s'" % localpath)
+
+    if want_md5sum:
+        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:
+            raise Exception("Executing md5sum failed")
+        if want_md5sum != md5data:
+            bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (want_md5sum, md5data))
+            raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (want_md5sum, md5data))
+
+    if want_sha256sum:
+        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:
+            raise Exception("Executing shasum failed")
+        if want_sha256sum != sha256data:
+            bb.note("The SHA256Sums did not match. Wanted: '%s' and Got: '%s'" % (want_sha256sum, sha256data))
+            raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (want_sha256sum, sha256data))
+
+    return True
+
+
  def base_chk_file(parser, pn, pv, src_uri, localpath, data):
      import os, bb
      no_checksum = False
@@ -652,15 +696,15 @@ python base_do_fetch() {
  	# Check each URI
  	for url in src_uri.split():
  		localpath = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
-		(type,host,path,_,_,_) = bb.decodeurl(url)
+		(type,host,path,_,_,params) = bb.decodeurl(url)
  		uri = "%s://%s%s" % (type,host,path)
  		try:
-			if type == "http" or type == "https" or type == "ftp" or type == "ftps":
-				if not base_chk_file(parser, pn, pv,uri, localpath, d):
-					if not bb.data.getVar("OE_ALLOW_INSECURE_DOWNLOADS",d, True):
-						bb.fatal("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
+			if type in [ "http", "https", "ftp", "ftps" ]:
+				if not (base_chk_file_vars(parser, localpath, params, d) or base_chk_file(parser, pn, pv,uri, localpath, d)):
+					if not bb.data.getVar("OE_ALLOW_INSECURE_DOWNLOADS", d, True):
+						bb.fatal("%s-%s: %s has no checksum defined, cannot check archive integrity" % (pn,pv,uri))
  					else:
-						bb.note("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
+						bb.note("%s-%s: %s has no checksum defined, archive integrity not checked" % (pn,pv,uri))
  		except Exception:
  			raise bb.build.FuncFailed("Checksum of '%s' failed" % uri)
  }
-- 
1.6.4.4


-- 
Vitus Jensen, Hannover, Germany, Universe (current)
pgp public key available from keyservers




More information about the Openembedded-devel mailing list