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

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 10 15:32:13 PST 2022


sammccall created this revision.
sammccall added reviewers: aaron.ballman, hokein.
Herald added subscribers: usaxena95, kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang-tools-extra.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121422

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


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
@@ -8,9 +8,10 @@
 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.llvm_shlib_dir = "@SHLIBDIR@"
 config.python_executable = "@Python3_EXECUTABLE@"
 config.target_triple = "@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@
 
Index: clang-tools-extra/test/lit.cfg.py
===================================================================
--- clang-tools-extra/test/lit.cfg.py
+++ 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')


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121422.414514.patch
Type: text/x-patch
Size: 3796 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220310/9b5ec334/attachment.bin>


More information about the cfe-commits mailing list