[llvm] r329037 - [lit] Prefer opening files with open (Python 2) rather than io.open which requires io.
Aaron Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 2 17:22:12 PDT 2018
Author: asmith
Date: Mon Apr 2 17:22:12 2018
New Revision: 329037
URL: http://llvm.org/viewvc/llvm-project?rev=329037&view=rev
Log:
[lit] Prefer opening files with open (Python 2) rather than io.open which requires io.
Only rely on Python 3 (io.open) when necessary. This puts TestRunnyer.py closer to how it behaved
before the changes introduced in D43165 and silences a few Windows build bot failures.
Thanks to Stella Stamenova for the patch!
Modified:
llvm/trunk/utils/lit/lit/TestRunner.py
Modified: llvm/trunk/utils/lit/lit/TestRunner.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestRunner.py?rev=329037&r1=329036&r2=329037&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestRunner.py (original)
+++ llvm/trunk/utils/lit/lit/TestRunner.py Mon Apr 2 17:22:12 2018
@@ -392,14 +392,12 @@ def executeBuiltinDiff(cmd, cmd_shenv):
encoding = None
filelines = []
for file in filepaths:
- compare_bytes = False
- encoding = None
try:
with open(file, 'r') as f:
filelines.append(f.readlines())
except UnicodeDecodeError:
try:
- with open(file, 'r', encoding="utf-8") as f:
+ with io.open(file, 'r', encoding="utf-8") as f:
filelines.append(f.readlines())
encoding = "utf-8"
except:
@@ -416,7 +414,7 @@ def executeBuiltinDiff(cmd, cmd_shenv):
with open(file, 'rb') as f:
filelines.append(f.readlines())
- exitCode = 0
+ exitCode = 0
if hasattr(difflib, 'diff_bytes'):
# python 3.5 or newer
diffs = difflib.diff_bytes(difflib.unified_diff, filelines[0], filelines[1], filepaths[0].encode(), filepaths[1].encode())
@@ -434,10 +432,14 @@ def executeBuiltinDiff(cmd, cmd_shenv):
def compareTwoTextFiles(filepaths, encoding):
filelines = []
for file in filepaths:
- with io.open(file, 'r', encoding=encoding) as f:
- filelines.append(f.readlines())
+ if encoding is None:
+ with open(file, 'r') as f:
+ filelines.append(f.readlines())
+ else:
+ with io.open(file, 'r', encoding=encoding) as f:
+ filelines.append(f.readlines())
- exitCode = 0
+ exitCode = 0
def compose2(f, g):
return lambda x: f(g(x))
More information about the llvm-commits
mailing list