[PATCH] D121427: [lit] add lit_config.substitute to interpolate lit_config.params

2022-03-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa1019fa1843: [lit] add lit_config.substitute to interpolate 
lit_config.params (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D121427?vs=414522=415576#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121427/new/

https://reviews.llvm.org/D121427

Files:
  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


Index: llvm/utils/lit/lit/LitConfig.py
===
--- llvm/utils/lit/lit/LitConfig.py
+++ llvm/utils/lit/lit/LitConfig.py
@@ -175,6 +175,15 @@
 # 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)
Index: clang-tools-extra/test/lit.site.cfg.py.in
===
--- clang-tools-extra/test/lit.site.cfg.py.in
+++ 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)
Index: clang-tools-extra/clangd/test/lit.site.cfg.py.in
===
--- clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ 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@/.."


Index: llvm/utils/lit/lit/LitConfig.py
===
--- llvm/utils/lit/lit/LitConfig.py
+++ llvm/utils/lit/lit/LitConfig.py
@@ -175,6 +175,15 @@
 # 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):
 

[PATCH] D121427: [lit] add lit_config.substitute to interpolate lit_config.params

2022-03-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

This patch is definitely an improvement.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121427/new/

https://reviews.llvm.org/D121427

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121427: [lit] add lit_config.substitute to interpolate lit_config.params

2022-03-10 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: aaron.ballman, hokein.
Herald added subscribers: usaxena95, kadircet, arphaman, delcypher.
Herald added a project: All.
sammccall requested review of this revision.
Herald added projects: LLVM, clang-tools-extra.
Herald added subscribers: cfe-commits, llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121427

Files:
  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


Index: llvm/utils/lit/lit/LitConfig.py
===
--- llvm/utils/lit/lit/LitConfig.py
+++ llvm/utils/lit/lit/LitConfig.py
@@ -175,6 +175,15 @@
 # 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)
Index: clang-tools-extra/test/lit.site.cfg.py.in
===
--- clang-tools-extra/test/lit.site.cfg.py.in
+++ 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 = "@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)
Index: clang-tools-extra/clangd/test/lit.site.cfg.py.in
===
--- clang-tools-extra/clangd/test/lit.site.cfg.py.in
+++ 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 = "@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@/.."


Index: llvm/utils/lit/lit/LitConfig.py
===
--- llvm/utils/lit/lit/LitConfig.py
+++ llvm/utils/lit/lit/LitConfig.py
@@ -175,6 +175,15 @@
 # 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