[llvm] [LIT][Cygwin] Skip pre-check for existence in mkdir-p (PR #163948)

Tomohiro Kashiwada via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 09:35:22 PDT 2025


https://github.com/kikairoya updated https://github.com/llvm/llvm-project/pull/163948

>From 2efd1285dd2206a78e425bdc58310b15b75fe3a4 Mon Sep 17 00:00:00 2001
From: kikairoya <kikairoya at gmail.com>
Date: Fri, 17 Oct 2025 20:41:22 +0900
Subject: [PATCH 1/2] [LIT][Cygwin] Skip pre-check for existence in mkdir-p

On Cygwin, a file named `file_name.exe` can be accessed without the suffix,
simply as `file_name`, as shown below:

```
$ echo > file_name.exe

$ file file_name.exe
file_name.exe: very short file (no magic)

$ file file_name
file_name: very short file (no magic)
```

In this situation, while running `mkdir file_name` works as intended,
checking for the existence of the target before calling `mkdir`
incorrectly reports that it already exists and thus skips the directory creation.

```
$ test -e file && echo exists
exists

$ mkdir file_name && echo ok
ok

$ file file_name
file: directory
```

Therefore, the existence pre-check should be skipped on Cygwin.
If the target actually already exists, such an error will be ignored anyway.
---
 llvm/utils/lit/lit/util.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index ce4c3c2df3436..a5181ab20a7e1 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -164,7 +164,7 @@ def mkdir(path):
 def mkdir_p(path):
     """mkdir_p(path) - Make the "path" directory, if it does not exist; this
     will also make directories for any missing parent directories."""
-    if not path or os.path.exists(path):
+    if not path or (sys.platform != "cygwin" and os.path.exists(path)):
         return
 
     parent = os.path.dirname(path)

>From 665e97f6f892081fc22f6d29b15e02ee2d31c78e Mon Sep 17 00:00:00 2001
From: kikairoya <kikairoya at gmail.com>
Date: Sat, 18 Oct 2025 00:21:24 +0900
Subject: [PATCH 2/2] use makedirs with exist_ok=True

---
 llvm/utils/lit/lit/util.py | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index a5181ab20a7e1..6f5b1606a16cc 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -164,14 +164,7 @@ def mkdir(path):
 def mkdir_p(path):
     """mkdir_p(path) - Make the "path" directory, if it does not exist; this
     will also make directories for any missing parent directories."""
-    if not path or (sys.platform != "cygwin" and os.path.exists(path)):
-        return
-
-    parent = os.path.dirname(path)
-    if parent != path:
-        mkdir_p(parent)
-
-    mkdir(path)
+    os.makedirs(path, exist_ok=True)
 
 
 def listdir_files(dirname, suffixes=None, exclude_filenames=None, prefixes=None):



More information about the llvm-commits mailing list