]> code.ossystems Code Review - openembedded-core.git/commitdiff
classes/buildhistory: write out files in UTF-8 format
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Thu, 6 Feb 2014 11:02:55 +0000 (11:02 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 6 Feb 2014 15:23:39 +0000 (15:23 +0000)
If the package information contained unicode characters (for example, in
the package file listing) then writing them out as ASCII would fail, so
write them out using codecs.open() instead of open() using UTF-8. This
fixes ca-certificates failing in do_packagedata when buildhistory is
enabled.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/buildhistory.bbclass

index 6b097ea20f7179694ba5852019d1a33d68f14c78..6d1e74afe1364ecfc6457dadd5d646c17da7fac0 100644 (file)
@@ -242,21 +242,25 @@ python buildhistory_emit_pkghistory() {
 
 
 def write_recipehistory(rcpinfo, d):
+    import codecs
+
     bb.debug(2, "Writing recipe history")
 
     pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
 
     infofile = os.path.join(pkghistdir, "latest")
-    with open(infofile, "w") as f:
+    with codecs.open(infofile, "w", encoding='utf8') as f:
         if rcpinfo.pe != "0":
-            f.write("PE = %s\n" %  rcpinfo.pe)
-        f.write("PV = %s\n" %  rcpinfo.pv)
-        f.write("PR = %s\n" %  rcpinfo.pr)
-        f.write("DEPENDS = %s\n" %  rcpinfo.depends)
-        f.write("PACKAGES = %s\n" %  rcpinfo.packages)
+            f.write(u"PE = %s\n" %  rcpinfo.pe)
+        f.write(u"PV = %s\n" %  rcpinfo.pv)
+        f.write(u"PR = %s\n" %  rcpinfo.pr)
+        f.write(u"DEPENDS = %s\n" %  rcpinfo.depends)
+        f.write(u"PACKAGES = %s\n" %  rcpinfo.packages)
 
 
 def write_pkghistory(pkginfo, d):
+    import codecs
+
     bb.debug(2, "Writing package history for package %s" % pkginfo.name)
 
     pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
@@ -266,11 +270,11 @@ def write_pkghistory(pkginfo, d):
         bb.utils.mkdirhier(pkgpath)
 
     infofile = os.path.join(pkgpath, "latest")
-    with open(infofile, "w") as f:
+    with codecs.open(infofile, "w", encoding='utf8') as f:
         if pkginfo.pe != "0":
-            f.write("PE = %s\n" %  pkginfo.pe)
-        f.write("PV = %s\n" %  pkginfo.pv)
-        f.write("PR = %s\n" %  pkginfo.pr)
+            f.write(u"PE = %s\n" %  pkginfo.pe)
+        f.write(u"PV = %s\n" %  pkginfo.pv)
+        f.write(u"PR = %s\n" %  pkginfo.pr)
 
         pkgvars = {}
         pkgvars['PKG'] = pkginfo.pkg if pkginfo.pkg != pkginfo.name else ''
@@ -280,26 +284,26 @@ def write_pkghistory(pkginfo, d):
         for pkgvar in pkgvars:
             val = pkgvars[pkgvar]
             if val:
-                f.write("%s = %s\n" % (pkgvar, val))
+                f.write(u"%s = %s\n" % (pkgvar, val))
 
-        f.write("RPROVIDES = %s\n" %  pkginfo.rprovides)
-        f.write("RDEPENDS = %s\n" %  pkginfo.rdepends)
-        f.write("RRECOMMENDS = %s\n" %  pkginfo.rrecommends)
+        f.write(u"RPROVIDES = %s\n" %  pkginfo.rprovides)
+        f.write(u"RDEPENDS = %s\n" %  pkginfo.rdepends)
+        f.write(u"RRECOMMENDS = %s\n" %  pkginfo.rrecommends)
         if pkginfo.rsuggests:
-            f.write("RSUGGESTS = %s\n" %  pkginfo.rsuggests)
+            f.write(u"RSUGGESTS = %s\n" %  pkginfo.rsuggests)
         if pkginfo.rreplaces:
-            f.write("RREPLACES = %s\n" %  pkginfo.rreplaces)
+            f.write(u"RREPLACES = %s\n" %  pkginfo.rreplaces)
         if pkginfo.rconflicts:
-            f.write("RCONFLICTS = %s\n" %  pkginfo.rconflicts)
-        f.write("PKGSIZE = %d\n" %  pkginfo.size)
-        f.write("FILES = %s\n" %  pkginfo.files)
-        f.write("FILELIST = %s\n" %  pkginfo.filelist)
+            f.write(u"RCONFLICTS = %s\n" %  pkginfo.rconflicts)
+        f.write(u"PKGSIZE = %d\n" %  pkginfo.size)
+        f.write(u"FILES = %s\n" %  pkginfo.files)
+        f.write(u"FILELIST = %s\n" %  pkginfo.filelist)
 
     for filevar in pkginfo.filevars:
         filevarpath = os.path.join(pkgpath, "latest.%s" % filevar)
         val = pkginfo.filevars[filevar]
         if val:
-            with open(filevarpath, "w") as f:
+            with codecs.open(filevarpath, "w", encoding='utf8') as f:
                 f.write(val)
         else:
             if os.path.exists(filevarpath):