[llvm] [lit] Add support for %{s:stem} substitution. (PR #202885)
Joachim Meyer via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 01:16:41 PDT 2026
https://github.com/fodinabor created https://github.com/llvm/llvm-project/pull/202885
It provides the source file name with the (last) extension removed.
This is to align with what is available for %t and actually needed downstream.
>From 54636d13298763b5034f4ccff5dda2e8dffe3e69 Mon Sep 17 00:00:00 2001
From: Joachim Meyer <jmeyer at cs.uni-saarland.de>
Date: Wed, 10 Jun 2026 10:13:05 +0200
Subject: [PATCH] [lit] Add support for %{s:stem} substitution.
It provides the source file name with the (last) extension removed.
---
llvm/docs/CommandGuide/lit.rst | 1 +
llvm/utils/lit/lit/TestRunner.py | 2 ++
llvm/utils/lit/tests/substitutions.py | 2 ++
3 files changed, 5 insertions(+)
diff --git a/llvm/docs/CommandGuide/lit.rst b/llvm/docs/CommandGuide/lit.rst
index 016e33d06b636..8b58011f8ec37 100644
--- a/llvm/docs/CommandGuide/lit.rst
+++ b/llvm/docs/CommandGuide/lit.rst
@@ -667,6 +667,7 @@ TestRunner.py:
%/p %p but ``\`` is replaced by ``/``
%/t %t but ``\`` is replaced by ``/``
%{s:basename} The last path component of %s
+ %{s:stem} The last path component of %s but with the last extension removed.
%{t:stem} The last path component of %t but without the ``.tmp`` extension (alias for %basename_t)
%{s:real} %s after expanding all symbolic links and substitute drives
%{S:real} %S after expanding all symbolic links and substitute drives
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index b6eb8b2e6af20..48fa86febc2f3 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -992,11 +992,13 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
tmpName = tmpBase + ".tmp"
tmpBaseName = os.path.basename(tmpBase)
sourceBaseName = os.path.basename(sourcepath)
+ sourceStem = os.path.splitext(sourceBaseName)[0]
substitutions.append(("%{pathsep}", os.pathsep))
substitutions.append(("%basename_t", tmpBaseName))
substitutions.append(("%{s:basename}", sourceBaseName))
+ substitutions.append(("%{s:stem}", sourceStem))
substitutions.append(("%{t:stem}", tmpBaseName))
fs_sep = os.path.sep
diff --git a/llvm/utils/lit/tests/substitutions.py b/llvm/utils/lit/tests/substitutions.py
index aa461531628e9..63eacac1216f4 100644
--- a/llvm/utils/lit/tests/substitutions.py
+++ b/llvm/utils/lit/tests/substitutions.py
@@ -1,7 +1,9 @@
# Basic test for substitutions.
#
# RUN: echo %{s:basename} | FileCheck %s --check-prefix=BASENAME
+# RUN: echo %{s:stem} | FileCheck %s --check-prefix=STEM
# RUN: echo %{t:stem} %basename_t | FileCheck %s --check-prefix=TMPBASENAME
# BASENAME: substitutions.py
+# STEM: substitutions
# TMPBASENAME: [[FIRST:[^[:space:]]+]] [[FIRST]]
More information about the llvm-commits
mailing list