Skip to content

Commit 6f20c30

Browse files
authored
[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.
1 parent 000e790 commit 6f20c30

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

llvm/docs/CommandGuide/lit.rst

+1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ TestRunner.py:
535535
%{fs-tmp-root} root component of file system paths pointing to the test's temporary directory
536536
%{fs-sep} file system path separator
537537
%t temporary file name unique to the test
538+
%basename_s The last path component of %s
538539
%basename_t The last path component of %t but without the ``.tmp`` extension
539540
%T parent directory of %t (not unique, deprecated, do not use)
540541
%% %

llvm/test/TableGen/anonymous-location.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: llvm-tblgen --print-detailed-records %s | FileCheck %s -DFILE=anonymous-location.td
1+
// RUN: llvm-tblgen --print-detailed-records %s | FileCheck %s -DFILE=%basename_s
22

33
class A<int a> {
44
int Num = a;

llvm/utils/lit/lit/TestRunner.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1394,10 +1394,12 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
13941394
substitutions = []
13951395
substitutions.extend(test.config.substitutions)
13961396
tmpName = tmpBase + ".tmp"
1397-
baseName = os.path.basename(tmpBase)
1397+
tmpBaseName = os.path.basename(tmpBase)
1398+
sourceBaseName = os.path.basename(sourcepath)
13981399

13991400
substitutions.append(("%{pathsep}", os.pathsep))
1400-
substitutions.append(("%basename_t", baseName))
1401+
substitutions.append(("%basename_t", tmpBaseName))
1402+
substitutions.append(("%basename_s", sourceBaseName))
14011403

14021404
substitutions.extend(
14031405
[

llvm/utils/lit/tests/substitutions.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Basic test for substitutions.
2+
#
3+
# RUN: echo %basename_s | FileCheck %s
4+
#
5+
# CHECK: substitutions.py

0 commit comments

Comments
 (0)