diff options
author | Aaron Smith <aaron.smith@microsoft.com> | 2018-04-03 00:22:12 +0000 |
---|---|---|
committer | Aaron Smith <aaron.smith@microsoft.com> | 2018-04-03 00:22:12 +0000 |
commit | ad2e39fd2ef8a465f8c19e69e8498b6b14faa45a (patch) | |
tree | 313ca0a8e58deb74759b18280a2129a9f02f747c /utils/lit | |
parent | 2784c35c0ffbfc67e3e48d35ee8cfe9a1f06cfa2 (diff) |
[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!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/lit')
-rw-r--r-- | utils/lit/lit/TestRunner.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py index f0049526cce..5eecb80e2f3 100644 --- a/utils/lit/lit/TestRunner.py +++ b/utils/lit/lit/TestRunner.py @@ -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)) |