buildman: properly translate strings for log and err files to ASCII
authorDaniel Schwierzeck <daniel.schwierzeck@gmail.com>
Thu, 8 Jun 2017 01:07:09 +0000 (03:07 +0200)
committerSimon Glass <sjg@chromium.org>
Fri, 9 Jun 2017 19:45:34 +0000 (13:45 -0600)
The build output can still produce unicode encoded output. But in
the buildman's log and err files we only want plain ASCII characters.

To handle all situations with unicode and non-unicode output, encode
the stdout and stderr strings to UTF-8 and afterwards to ASCII with
replacing all special characters.

Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
tools/buildman/builderthread.py

index acaf5007f50cbfbe813e54008efd83389846c9ca..9e8ca80c5b535b10f9f88414c01d7da5930ad3e9 100644 (file)
@@ -280,13 +280,15 @@ class BuilderThread(threading.Thread):
         outfile = os.path.join(build_dir, 'log')
         with open(outfile, 'w') as fd:
             if result.stdout:
-                fd.write(result.stdout.encode('latin-1', 'ignore'))
+                # We don't want unicode characters in log files
+                fd.write(result.stdout.decode('UTF-8').encode('ASCII', 'replace'))
 
         errfile = self.builder.GetErrFile(result.commit_upto,
                 result.brd.target)
         if result.stderr:
             with open(errfile, 'w') as fd:
-                fd.write(result.stderr.encode('latin-1', 'ignore'))
+                # We don't want unicode characters in log files
+                fd.write(result.stderr.decode('UTF-8').encode('ASCII', 'replace'))
         elif os.path.exists(errfile):
             os.remove(errfile)