[OE-core] [v2][PATCH] license class: try alt encoding when copying license file

Armin Kuster akuster808 at gmail.com
Sun Mar 12 15:27:32 UTC 2017


From: Armin Kuster <akuster at mvista.com>

v2: fix typos

Try another encoding if utf-8 fails in file read.

line 20 of irdadump.c contains:  University of Tromsø

fixes:
WARNING: irda-utils-0.9.18-r0 do_populate_lic: Could not copy license file /home/akuster/oss/maint/openembedded-core/build/tmp-glibc/work/aarch64-mvl-linux/irda-utils/0.9.18-r0/irda-utils-0.9.18/irdadump/irdadump.c to /home/akuster/oss/maint/openembedded-core/build/tmp-glibc/work/aarch64-mvl-linux/irda-utils/0.9.18-r0/license-destdir/irda-utils/irdadump.c: 'utf-8' codec can't decode byte 0xf8 in position 874: invalid start byte

Signed-off-by: Armin Kuster <akuster at mvista.com>
---
 meta/classes/license.bbclass | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 0ff6560..3dab8d9 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -386,9 +386,19 @@ def copy_license_files(lic_files_paths, destdir):
                 if begin_idx is None and end_idx is None:
                     shutil.copyfile(src, dst)
                 else:
-                    with open(src, 'r') as src_f:
+                    with open(src, "r", encoding="utf-8") as src_f:
+                        try:
+                            src_chunk = ''.join(src_f.readlines()[begin_idx:end_idx])
+                        except UnicodeDecodeError:
+                            bb.debug(1, "Failed to copy license file %s using UTF-8 encoding"
+                            " trying with iso8859-1" %  src)
+                            src_f.close()
+                            with open(src, "r", encoding="iso8859-1") as src_f:
+                                src_chunk = ''.join(src_f.readlines()[begin_idx:end_idx])
+
+
                         with open(dst, 'w') as dst_f:
-                            dst_f.write(''.join(src_f.readlines()[begin_idx:end_idx]))
+                            dst_f.write(src_chunk)
 
         except Exception as e:
             bb.warn("Could not copy license file %s to %s: %s" % (src, dst, e))
-- 
2.7.4




More information about the Openembedded-core mailing list