[llvm] 6f20c30 - [LIT] Add support for `%basename_s` to get base name of source file (#110993)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 3 12:29:15 PDT 2024


Author: Rahul Joshi
Date: 2024-10-03T12:29:11-07:00
New Revision: 6f20c3099e733afb56e1d2fb9b45bbd1802a4864

URL: https://github.com/llvm/llvm-project/commit/6f20c3099e733afb56e1d2fb9b45bbd1802a4864
DIFF: https://github.com/llvm/llvm-project/commit/6f20c3099e733afb56e1d2fb9b45bbd1802a4864.diff

LOG: [LIT] Add support for `%basename_s` to get base name of source file (#110993)

Add support for `%basename_s` pattern in the RUN commands to get the
base name of the source file, and adopt it in a TableGen LIT test.

Added: 
    llvm/utils/lit/tests/substitutions.py

Modified: 
    llvm/docs/CommandGuide/lit.rst
    llvm/test/TableGen/anonymous-location.td
    llvm/utils/lit/lit/TestRunner.py

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/lit.rst b/llvm/docs/CommandGuide/lit.rst
index c9d5baba3e2f49..9216eb223d1491 100644
--- a/llvm/docs/CommandGuide/lit.rst
+++ b/llvm/docs/CommandGuide/lit.rst
@@ -535,6 +535,7 @@ TestRunner.py:
  %{fs-tmp-root}          root component of file system paths pointing to the test's temporary directory
  %{fs-sep}               file system path separator
  %t                      temporary file name unique to the test
+ %basename_s             The last path component of %s
  %basename_t             The last path component of %t but without the ``.tmp`` extension
  %T                      parent directory of %t (not unique, deprecated, do not use)
  %%                      %

diff  --git a/llvm/test/TableGen/anonymous-location.td b/llvm/test/TableGen/anonymous-location.td
index ffeba6ebcb686f..5485d2027b9fd0 100644
--- a/llvm/test/TableGen/anonymous-location.td
+++ b/llvm/test/TableGen/anonymous-location.td
@@ -1,4 +1,4 @@
-// RUN: llvm-tblgen --print-detailed-records %s | FileCheck %s -DFILE=anonymous-location.td
+// RUN: llvm-tblgen --print-detailed-records %s | FileCheck %s -DFILE=%basename_s
 
 class A<int a> {
   int Num = a;

diff  --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index a1785073547ad0..080a618572645d 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1394,10 +1394,12 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
     substitutions = []
     substitutions.extend(test.config.substitutions)
     tmpName = tmpBase + ".tmp"
-    baseName = os.path.basename(tmpBase)
+    tmpBaseName = os.path.basename(tmpBase)
+    sourceBaseName = os.path.basename(sourcepath)
 
     substitutions.append(("%{pathsep}", os.pathsep))
-    substitutions.append(("%basename_t", baseName))
+    substitutions.append(("%basename_t", tmpBaseName))
+    substitutions.append(("%basename_s", sourceBaseName))
 
     substitutions.extend(
         [

diff  --git a/llvm/utils/lit/tests/substitutions.py b/llvm/utils/lit/tests/substitutions.py
new file mode 100644
index 00000000000000..8b5b72a612cdc9
--- /dev/null
+++ b/llvm/utils/lit/tests/substitutions.py
@@ -0,0 +1,5 @@
+# Basic test for substitutions.
+#
+# RUN: echo %basename_s  | FileCheck %s
+#
+# CHECK: substitutions.py


        


More information about the llvm-commits mailing list