aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/lit
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/utils/lit')
-rw-r--r--llvm/utils/lit/lit/TestRunner.py15
-rw-r--r--llvm/utils/lit/lit/util.py40
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-glob/example_dir1.input/empty0
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-glob/example_dir2.input/empty0
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt5
-rw-r--r--llvm/utils/lit/tests/shtest-glob.py9
-rw-r--r--llvm/utils/lit/tests/shtest-ulimit-nondarwin.py2
7 files changed, 23 insertions, 48 deletions
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 3176b1a..64148c6 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -462,16 +462,15 @@ def executeBuiltinMkdir(cmd, cmd_shenv):
stderr = StringIO()
exitCode = 0
for dir in args:
- cwd = cmd_shenv.cwd
- dir = to_unicode(dir) if kIsWindows else to_bytes(dir)
- cwd = to_unicode(cwd) if kIsWindows else to_bytes(cwd)
- if not os.path.isabs(dir):
- dir = lit.util.abs_path_preserve_drive(os.path.join(cwd, dir))
+ dir = pathlib.Path(dir)
+ cwd = pathlib.Path(to_unicode(cmd_shenv.cwd))
+ if not dir.is_absolute():
+ dir = lit.util.abs_path_preserve_drive(cwd / dir)
if parent:
- lit.util.mkdir_p(dir)
+ dir.mkdir(parents=True, exist_ok=True)
else:
try:
- lit.util.mkdir(dir)
+ dir.mkdir(exist_ok=True)
except OSError as err:
stderr.write("Error: 'mkdir' command failed, %s\n" % str(err))
exitCode = 1
@@ -2411,7 +2410,7 @@ def _runShTest(test, litConfig, useExternalSh, script, tmpBase) -> lit.Test.Resu
return out, err, exitCode, timeoutInfo, status
# Create the output directory if it does not already exist.
- lit.util.mkdir_p(os.path.dirname(tmpBase))
+ pathlib.Path(tmpBase).parent.mkdir(parents=True, exist_ok=True)
# Re-run failed tests up to test.allowed_retries times.
execdir = os.path.dirname(test.getExecPath())
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index ce4c3c2..e4e031b 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -5,6 +5,7 @@ import itertools
import math
import numbers
import os
+import pathlib
import platform
import re
import signal
@@ -131,48 +132,17 @@ def abs_path_preserve_drive(path):
# Since Python 3.8, os.path.realpath resolves sustitute drives,
# so we should not use it. In Python 3.7, os.path.realpath
# was implemented as os.path.abspath.
+ if isinstance(path, pathlib.Path):
+ return path.absolute()
return os.path.abspath(path)
else:
# On UNIX, the current directory always has symbolic links resolved,
# so any program accepting relative paths cannot preserve symbolic
# links in paths and we should always use os.path.realpath.
+ if isinstance(path, pathlib.Path):
+ return path.resolve()
return os.path.realpath(path)
-def mkdir(path):
- try:
- if platform.system() == "Windows":
- from ctypes import windll
- from ctypes import GetLastError, WinError
-
- path = os.path.abspath(path)
- # Make sure that the path uses backslashes here, in case
- # python would have happened to use forward slashes, as the
- # NT path format only supports backslashes.
- path = path.replace("/", "\\")
- NTPath = to_unicode(r"\\?\%s" % path)
- if not windll.kernel32.CreateDirectoryW(NTPath, None):
- raise WinError(GetLastError())
- else:
- os.mkdir(path)
- except OSError:
- e = sys.exc_info()[1]
- # ignore EEXIST, which may occur during a race condition
- if e.errno != errno.EEXIST:
- raise
-
-
-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):
- return
-
- parent = os.path.dirname(path)
- if parent != path:
- mkdir_p(parent)
-
- mkdir(path)
-
def listdir_files(dirname, suffixes=None, exclude_filenames=None, prefixes=None):
"""Yields files in a directory.
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/example_dir1.input/empty b/llvm/utils/lit/tests/Inputs/shtest-glob/example_dir1.input/empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/example_dir1.input/empty
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/example_dir2.input/empty b/llvm/utils/lit/tests/Inputs/shtest-glob/example_dir2.input/empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/example_dir2.input/empty
diff --git a/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt
index d1329f5..7197241 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-glob/glob-mkdir.txt
@@ -1,2 +1,7 @@
## Tests glob pattern handling in the mkdir command.
+
+## This mkdir should fail because the `example_file*.input`s are regular files.
# RUN: not mkdir %S/example_file*.input
+
+## This mkdir should succeed (so RUN should fail) because the `example_dir*.input`s that already exist are directories.
+# RUN: not mkdir %S/example_dir*.input
diff --git a/llvm/utils/lit/tests/shtest-glob.py b/llvm/utils/lit/tests/shtest-glob.py
index ae90f31..aa4705b 100644
--- a/llvm/utils/lit/tests/shtest-glob.py
+++ b/llvm/utils/lit/tests/shtest-glob.py
@@ -1,12 +1,13 @@
## Tests glob pattern handling in echo command.
# RUN: not %{lit} -a -v %{inputs}/shtest-glob \
-# RUN: | FileCheck -dump-input=fail -match-full-lines %s
-#
+# RUN: | FileCheck -dump-input=fail -match-full-lines --implicit-check-not=Error: %s
# END.
# CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}})
# CHECK: TypeError: string argument expected, got 'GlobItem'
-# CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}})
-# CHECK: # error: command failed with exit status: 1
+# CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}})
+# CHECK: # | Error: 'mkdir' command failed, {{.*}}example_file1.input'
+# CHECK-NEXT: # | Error: 'mkdir' command failed, {{.*}}example_file2.input'
+# CHECK: # error: command failed with exit status: 1
diff --git a/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py b/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py
index 286fd3d..d81cde0 100644
--- a/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py
+++ b/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py
@@ -2,7 +2,7 @@
# ulimit does not work on non-POSIX platforms.
# These tests are specific to options that Darwin does not support.
-# UNSUPPORTED: system-windows, system-darwin, system-aix, system-solaris
+# UNSUPPORTED: system-windows, system-cygwin, system-darwin, system-aix, system-solaris
# RUN: not %{lit} -a -v %{inputs}/shtest-ulimit-nondarwin | FileCheck %s