Skip to content

Commit f744e7e

Browse files
committedJan 18, 2017
[LIT] Make util.executeCommand python3 friendly
Summary: The parameter `input` to `subprocess.Popen.communicate(...)` must be an object of type `bytes` . This is strictly enforced in python3. This patch (1) allows `to_bytes` to be safely called redundantly. (2) Explicitly convert `input` within `executeCommand`. This allows for usages like `executeCommand(['clang++', '-'], input='int main() {}\n')`. Reviewers: ddunbar, BinaryKhaos, modocache, dim, EricWF Reviewed By: EricWF Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28736 llvm-svn: 292308
1 parent 9c46450 commit f744e7e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed
 

‎llvm/utils/lit/lit/util.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
def to_bytes(str):
1212
# Encode to UTF-8 to get binary data.
13+
if isinstance(str, bytes):
14+
return str
1315
return str.encode('utf-8')
1416

1517
def to_string(bytes):
@@ -200,6 +202,8 @@ def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
200202
If the timeout is hit an ``ExecuteCommandTimeoutException``
201203
is raised.
202204
"""
205+
if input is not None:
206+
input = to_bytes(input)
203207
p = subprocess.Popen(command, cwd=cwd,
204208
stdin=subprocess.PIPE,
205209
stdout=subprocess.PIPE,

0 commit comments

Comments
 (0)
Please sign in to comment.