[clang-tools-extra] 2b69eb4 - [clang-tools-extra] Reuse llvm_config.use_clang() to set up test environment

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 15 14:15:42 PDT 2022


Author: Sam McCall
Date: 2022-03-15T22:14:24+01:00
New Revision: 2b69eb4a7d1d1e6829081aa677cd52ad8eef2d5b

URL: https://github.com/llvm/llvm-project/commit/2b69eb4a7d1d1e6829081aa677cd52ad8eef2d5b
DIFF: https://github.com/llvm/llvm-project/commit/2b69eb4a7d1d1e6829081aa677cd52ad8eef2d5b.diff

LOG: [clang-tools-extra] Reuse llvm_config.use_clang() to set up test environment

This replaces a bunch of duplicate logic to set up environment variables
and a few substitutions.

It does a little more than we were doing previously:
 - searching for clang and setting up substitutions for it
 - setting up some substitutions for target triples, which are
   potentially useful but not actually used

clangd has been happily using this for its tests for a while.

Differential Revision: https://reviews.llvm.org/D121422

Added: 
    

Modified: 
    clang-tools-extra/test/lit.cfg.py
    clang-tools-extra/test/lit.site.cfg.py.in

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/test/lit.cfg.py b/clang-tools-extra/test/lit.cfg.py
index 1c16cc73c7446..f8fdfbd0a9205 100644
--- a/clang-tools-extra/test/lit.cfg.py
+++ b/clang-tools-extra/test/lit.cfg.py
@@ -1,13 +1,9 @@
 # -*- Python -*-
 
 import os
-import platform
-import re
 import shlex
-import subprocess
 
 import lit.formats
-import lit.util
 
 from lit.llvm import llvm_config
 
@@ -33,43 +29,8 @@
 # test_exec_root: The root path where tests should be run.
 config.test_exec_root = os.path.join(config.clang_tools_binary_dir, 'test')
 
-# Clear some environment variables that might affect Clang.
-#
-# This first set of vars are read by Clang, but shouldn't affect tests
-# that aren't specifically looking for these features, or are required
-# simply to run the tests at all.
-#
-# FIXME: Should we have a tool that enforces this?
-
-# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
-#                  'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
-#                  'IOS_SIMULATOR_DEPLOYMENT_TARGET',
-#                  'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
-#                  'VC80COMNTOOLS')
-possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
-                               'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
-                               'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
-                               'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
-                               'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
-                               'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
-                               'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
-                               'LIBCLANG_RESOURCE_USAGE',
-                               'LIBCLANG_CODE_COMPLETION_LOGGING']
-# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
-if platform.system() != 'Windows':
-    possibly_dangerous_env_vars.append('INCLUDE')
-for name in possibly_dangerous_env_vars:
-  if name in config.environment:
-    del config.environment[name]
-
-# Tweak the PATH to include the tools dir and the scripts dir.
-path = os.path.pathsep.join((
-        config.clang_tools_dir, config.llvm_tools_dir, config.environment['PATH']))
-config.environment['PATH'] = path
-
-path = os.path.pathsep.join((config.clang_libs_dir, config.llvm_libs_dir,
-                              config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+# Tools need the same environment setup as clang (we don't need clang itself).
+llvm_config.use_clang(required = False)
 
 if config.clang_tidy_staticanalyzer:
     config.available_features.add('static-analyzer')
@@ -91,9 +52,6 @@
     ('%run_clang_tidy',
      '%s %s' % (python_exec, run_clang_tidy)) )
 
-config.substitutions.append(('%llvmshlibdir', config.clang_libs_dir))
-config.substitutions.append(('%pluginext', config.llvm_plugin_ext))
-
 # Plugins (loadable modules)
 if config.has_plugins and config.llvm_plugin_ext:
     config.available_features.add('plugins')

diff  --git a/clang-tools-extra/test/lit.site.cfg.py.in b/clang-tools-extra/test/lit.site.cfg.py.in
index 26bd50dd3ca4d..a784e12efe819 100644
--- a/clang-tools-extra/test/lit.site.cfg.py.in
+++ b/clang-tools-extra/test/lit.site.cfg.py.in
@@ -5,9 +5,11 @@ import sys
 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_libs_dir = "@SHLIBDIR@"
+config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
+config.llvm_shlib_dir = "@SHLIBDIR@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
+config.host_triple = "@LLVM_HOST_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


        


More information about the cfe-commits mailing list