Skip to content

Commit 096ad6a

Browse files
committed
[Utils] Compare true file locations instead of string paths (llvm#158160)
Previously we compared paths by string manipulation, however Windows paths can use both '\' and '/' as path separators, which made this fragile. This uses the pathlib.Path.samefile API instead. (cherry picked from commit b018151)
1 parent 6933689 commit 096ad6a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

llvm/utils/lit/lit/DiffUpdater.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import shutil
22
import os
33
import shlex
4+
import pathlib
45

56
"""
67
This file provides the `diff_test_updater` function, which is invoked on failed RUN lines when lit is executed with --update-tests.
@@ -76,14 +77,12 @@ def get_target_dir(commands, test_path):
7677

7778
@staticmethod
7879
def create(path, commands, test_path, target_dir):
79-
filename = path.replace(target_dir, "")
80-
if filename.startswith(os.sep):
81-
filename = filename[len(os.sep) :]
80+
path = pathlib.Path(path)
8281
with open(test_path, "r") as f:
8382
lines = f.readlines()
8483
for i, l in enumerate(lines):
8584
p = SplitFileTarget._get_split_line_path(l)
86-
if p == filename:
85+
if p and path.samefile(os.path.join(target_dir, p)):
8786
idx = i
8887
break
8988
else:

0 commit comments

Comments
 (0)