From 2d88dc293bd5209ceb4ccb61a41d53a23cc09f20 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 12 Jan 2015 20:09:34 +0000 Subject: [PATCH] [LIT] Decode string result in lit.util.capture Summary: I think this is probably a bug, but I'm putting this up for review just to be sure. I think that `lit.util.capture` should decode the resulting string in the same way `lit.util.executeCommand` does. Reviewers: ddunbar, EricWF Reviewed By: EricWF Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6769 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225681 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lit/lit/util.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/utils/lit/lit/util.py b/utils/lit/lit/util.py index ca1aeb6d45c..08f7b71ae21 100644 --- a/utils/lit/lit/util.py +++ b/utils/lit/lit/util.py @@ -16,6 +16,12 @@ def to_string(bytes): return bytes return to_bytes(bytes) +def convert_string(bytes): + try: + return to_string(bytes.decode('utf-8')) + except UnicodeError: + return str(bytes) + def detectCPUs(): """ Detects the number of CPUs on a system. Cribbed from pp. @@ -60,7 +66,7 @@ def capture(args, env=None): p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) out,_ = p.communicate() - return out + return convert_string(out) def which(command, paths = None): """which(command, [paths]) - Look up the given command in the paths string @@ -166,14 +172,8 @@ def executeCommand(command, cwd=None, env=None): raise KeyboardInterrupt # Ensure the resulting output is always of string type. - try: - out = to_string(out.decode('utf-8')) - except: - out = str(out) - try: - err = to_string(err.decode('utf-8')) - except: - err = str(err) + out = convert_string(out) + err = convert_string(err) return out, err, exitCode