forked from OSchip/llvm-project
[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 llvm-svn: 225681
This commit is contained in:
parent
0c87d77175
commit
30045e6148
|
@ -16,6 +16,12 @@ def to_string(bytes):
|
||||||
return bytes
|
return bytes
|
||||||
return to_bytes(bytes)
|
return to_bytes(bytes)
|
||||||
|
|
||||||
|
def convert_string(bytes):
|
||||||
|
try:
|
||||||
|
return to_string(bytes.decode('utf-8'))
|
||||||
|
except UnicodeError:
|
||||||
|
return str(bytes)
|
||||||
|
|
||||||
def detectCPUs():
|
def detectCPUs():
|
||||||
"""
|
"""
|
||||||
Detects the number of CPUs on a system. Cribbed from pp.
|
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,
|
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
env=env)
|
env=env)
|
||||||
out,_ = p.communicate()
|
out,_ = p.communicate()
|
||||||
return out
|
return convert_string(out)
|
||||||
|
|
||||||
def which(command, paths = None):
|
def which(command, paths = None):
|
||||||
"""which(command, [paths]) - Look up the given command in the paths string
|
"""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
|
raise KeyboardInterrupt
|
||||||
|
|
||||||
# Ensure the resulting output is always of string type.
|
# Ensure the resulting output is always of string type.
|
||||||
try:
|
out = convert_string(out)
|
||||||
out = to_string(out.decode('utf-8'))
|
err = convert_string(err)
|
||||||
except:
|
|
||||||
out = str(out)
|
|
||||||
try:
|
|
||||||
err = to_string(err.decode('utf-8'))
|
|
||||||
except:
|
|
||||||
err = str(err)
|
|
||||||
|
|
||||||
return out, err, exitCode
|
return out, err, exitCode
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue