[PATCH] D28736: [LIT] Make util.executeCommand python3 friendly

Eric Fiselier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 14 16:34:53 PST 2017


EricWF created this revision.
EricWF added reviewers: ddunbar, dim, BinaryKhaos.
EricWF added a subscriber: llvm-commits.
Herald added a reviewer: modocache.

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')`.


https://reviews.llvm.org/D28736

Files:
  utils/lit/lit/util.py


Index: utils/lit/lit/util.py
===================================================================
--- utils/lit/lit/util.py
+++ utils/lit/lit/util.py
@@ -10,6 +10,8 @@
 
 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 @@
         If the timeout is hit an ``ExecuteCommandTimeoutException``
         is raised.
     """
+    if input is not None:
+        input = to_bytes(input)
     p = subprocess.Popen(command, cwd=cwd,
                          stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28736.84466.patch
Type: text/x-patch
Size: 662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170115/7e13a734/attachment.bin>


More information about the llvm-commits mailing list