[llvm] 8326823 - [lit] Add support for deleting symlinks to directories without -r
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 19 21:47:11 PDT 2025
Author: Aiden Grossman
Date: 2025-09-19T21:47:07-07:00
New Revision: 83268237baaff3c46956255370480ee2fdb570d4
URL: https://github.com/llvm/llvm-project/commit/83268237baaff3c46956255370480ee2fdb570d4
DIFF: https://github.com/llvm/llvm-project/commit/83268237baaff3c46956255370480ee2fdb570d4.diff
LOG: [lit] Add support for deleting symlinks to directories without -r
Before this change, rm would assume that a symlink to a directory was
actually a directory and require the recursive flag to be passed,
differing from other shells. Given the change in lit is about the same
length as the test change would be (minus tests), I think it makes sense
to just support this in the internal shell.
Reviewers: cmtice, petrhosek, ilovepi
Reviewed By: petrhosek, cmtice, ilovepi
Pull Request: https://github.com/llvm/llvm-project/pull/158464
Added:
llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg
llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt
llvm/utils/lit/tests/shtest-shell-symlinks.py
Modified:
llvm/utils/lit/lit/TestRunner.py
Removed:
################################################################################
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index f8e1c58d7671f..9ae8ac75bee08 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -516,7 +516,9 @@ def on_rm_error(func, path, exc_info):
if force and not os.path.exists(path):
continue
try:
- if os.path.isdir(path):
+ if os.path.islink(path):
+ os.remove(path)
+ elif os.path.isdir(path):
if not recursive:
stderr.write("Error: %s is a directory\n" % path)
exitCode = 1
diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg
new file mode 100644
index 0000000000000..eab06f08b688c
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg
@@ -0,0 +1,7 @@
+import lit.formats
+
+config.name = "shtest-shell"
+config.suffixes = [".txt"]
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt
new file mode 100644
index 0000000000000..a44a07c13e4ae
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt
@@ -0,0 +1,5 @@
+# Check that we can delete a symlink to a folder without -r
+#
+# RUN: mkdir %t.dir
+# RUN: ln -s %t.dir %t.symlink
+# RUN: rm %t.symlink
diff --git a/llvm/utils/lit/tests/shtest-shell-symlinks.py b/llvm/utils/lit/tests/shtest-shell-symlinks.py
new file mode 100644
index 0000000000000..cfd72a01b6d94
--- /dev/null
+++ b/llvm/utils/lit/tests/shtest-shell-symlinks.py
@@ -0,0 +1,9 @@
+# Check that the internal shell builtins correctly handle cases involving
+# symlinks.
+
+# REQUIRES: symlinks
+# RUN: echo test
+# RUN: %{lit} -v %{inputs}/shtest-shell-symlinks | FileCheck %s
+
+# CHECK: -- Testing: 1 test{{.*}}
+# CHECK: PASS: shtest-shell :: rm-symlink-dir.txt
More information about the llvm-commits
mailing list