[llvm] fa1019f - [lit] add lit_config.substitute to interpolate lit_config.params
Sam McCall via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 15 14:09:50 PDT 2022
Author: Sam McCall
Date: 2022-03-15T22:09:43+01:00
New Revision: fa1019fa184344a9ba57e56c8ae6c52e65b5f05c
URL: https://github.com/llvm/llvm-project/commit/fa1019fa184344a9ba57e56c8ae6c52e65b5f05c
DIFF: https://github.com/llvm/llvm-project/commit/fa1019fa184344a9ba57e56c8ae6c52e65b5f05c.diff
LOG: [lit] add lit_config.substitute to interpolate lit_config.params
A version of this logic appears in ~every lit.site.cfg.in (28 copies total).
This patch just removes two, but I'll update the rest of llvm-project next.
Differential Revision: https://reviews.llvm.org/D121427
Added:
Modified:
clang-tools-extra/clangd/test/lit.site.cfg.py.in
clang-tools-extra/test/lit.site.cfg.py.in
llvm/utils/lit/lit/LitConfig.py
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/test/lit.site.cfg.py.in b/clang-tools-extra/clangd/test/lit.site.cfg.py.in
index 2b294eaa5ae5a..9adc1c9792c1e 100644
--- a/clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ b/clang-tools-extra/clangd/test/lit.site.cfg.py.in
@@ -2,24 +2,15 @@
# Variables needed for common clang config.
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
-config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
-config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
config.clang_libs_dir = "@CLANG_LIBS_DIR@"
-config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.host_triple = "@LLVM_HOST_TRIPLE@"
config.python_executable = "@Python3_EXECUTABLE@"
-
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
-try:
- config.clang_tools_dir = config.clang_tools_dir % lit_config.params
- config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
- config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
-except KeyError:
- e = sys.exc_info()[1]
- key, = e.args
- lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
+config.clang_tools_dir = lit_config.substitute("@CLANG_TOOLS_DIR@")
+config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
+config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
config.clangd_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.."
config.clangd_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.."
diff --git a/clang-tools-extra/test/lit.site.cfg.py.in b/clang-tools-extra/test/lit.site.cfg.py.in
index 59357f6cad06b..26bd50dd3ca4d 100644
--- a/clang-tools-extra/test/lit.site.cfg.py.in
+++ b/clang-tools-extra/test/lit.site.cfg.py.in
@@ -2,28 +2,19 @@
import sys
-config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
-config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
config.clang_tools_binary_dir = "@CLANG_TOOLS_BINARY_DIR@"
-config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
config.clang_libs_dir = "@SHLIBDIR@"
config.python_executable = "@Python3_EXECUTABLE@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@
config.has_plugins = @CLANG_PLUGIN_SUPPORT@ & ~@LLVM_INSTALL_TOOLCHAIN_ONLY@
-
# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
-try:
- config.clang_tools_dir = config.clang_tools_dir % lit_config.params
- config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
- config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
-except KeyError:
- e = sys.exc_info()[1]
- key, = e.args
- lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
+config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
+config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@")
+config.clang_tools_dir = lit_config.substitute("@CLANG_TOOLS_DIR@")
import lit.llvm
lit.llvm.initialize(lit_config, config)
diff --git a/llvm/utils/lit/lit/LitConfig.py b/llvm/utils/lit/lit/LitConfig.py
index 38b7a18c6a583..34d0e90149af1 100644
--- a/llvm/utils/lit/lit/LitConfig.py
+++ b/llvm/utils/lit/lit/LitConfig.py
@@ -175,6 +175,15 @@ def _write_message(self, kind, message):
# output.
sys.stderr.flush()
+ def substitute(self, string):
+ """substitute - Interpolate params into a string"""
+ try:
+ return string % self.params
+ except KeyError as e:
+ key, = e.args
+ self.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (
+ key,key))
+
def note(self, message):
if not self.quiet:
self._write_message('note', message)
More information about the llvm-commits
mailing list