[llvm] r292308 - [LIT] Make util.executeCommand python3 friendly

Eric Fiselier via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 16:12:41 PST 2017

Author: ericwf
Date: Tue Jan 17 18:12:41 2017
New Revision: 292308

URL: http://llvm.org/viewvc/llvm-project?rev=292308&view=rev
[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


Modified: llvm/trunk/utils/lit/lit/util.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/util.py?rev=292308&r1=292307&r2=292308&view=diff
--- llvm/trunk/utils/lit/lit/util.py (original)
+++ llvm/trunk/utils/lit/lit/util.py Tue Jan 17 18:12:41 2017
@@ -10,6 +10,8 @@ import threading
 def to_bytes(str):
     # Encode to UTF-8 to get binary data.
+    if isinstance(str, bytes):
+        return str
     return str.encode('utf-8')
 def to_string(bytes):
@@ -200,6 +202,8 @@ def executeCommand(command, cwd=None, en
         If the timeout is hit an ``ExecuteCommandTimeoutException``
         is raised.
+    if input is not None:
+        input = to_bytes(input)
     p = subprocess.Popen(command, cwd=cwd,

More information about the llvm-commits mailing list