Skip to content

Conversation

hnrklssn
Copy link
Member

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2025

@llvm/pr-subscribers-testing-tools

Author: Henrik G. Olsson (hnrklssn)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/158160.diff

1 Files Affected:

  • (modified) llvm/utils/lit/lit/DiffUpdater.py (+3-4)
diff --git a/llvm/utils/lit/lit/DiffUpdater.py b/llvm/utils/lit/lit/DiffUpdater.py
index 5bba2d70991df..fefcdcc99f3f2 100644
--- a/llvm/utils/lit/lit/DiffUpdater.py
+++ b/llvm/utils/lit/lit/DiffUpdater.py
@@ -1,6 +1,7 @@
 import shutil
 import os
 import shlex
+import pathlib
 
 """
 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):
 
     @staticmethod
     def create(path, commands, test_path, target_dir):
-        filename = path.replace(target_dir, "")
-        if filename.startswith(os.sep):
-            filename = filename[len(os.sep) :]
+        path = pathlib.Path(path)
         with open(test_path, "r") as f:
             lines = f.readlines()
         for i, l in enumerate(lines):
             p = SplitFileTarget._get_split_line_path(l)
-            if p == filename:
+            if p and path.samefile(os.path.join(target_dir, p)):
                 idx = i
                 break
         else:

@hnrklssn hnrklssn merged commit b018151 into llvm:main Sep 11, 2025
12 checks passed
hnrklssn added a commit to hnrklssn/llvm-project that referenced this pull request Sep 11, 2025
)

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)
@dyung
Copy link
Collaborator

dyung commented Sep 12, 2025

Hi @hnrklssn, your fix does not seem to have fixed the Windows bot failures. Can you take a look?

https://lab.llvm.org/buildbot/#/builders/46/builds/23184

@hnrklssn
Copy link
Member Author

Hi @hnrklssn, your fix does not seem to have fixed the Windows bot failures. Can you take a look?

https://lab.llvm.org/buildbot/#/builders/46/builds/23184

On it! Thanks for letting me know.

@hnrklssn
Copy link
Member Author

Complete fix in #158235

hnrklssn added a commit to hnrklssn/llvm-project that referenced this pull request Sep 12, 2025
)

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)
kateinoigakukun pushed a commit to kateinoigakukun/llvm-project that referenced this pull request Sep 17, 2025
)

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants