[lit] Improve tool substitution in lit.

This addresses two sources of inconsistency in test configuration
files.

1. Substitution boundaries.  Previously you would specify a
   substitution, such as 'lli', and then additionally a set
   of characters that should fail to match before and after
   the tool.  This was used, for example, so that matches that
   are parts of full paths would not be replaced.  But not all
   tools did this, and those that did would often re-invent
   the set of characters themselves, leading to inconsistency.
   Now, every tool substitution defaults to using a sane set
   of reasonable defaults and you have to explicitly opt out
   of it.  This actually fixed a few latent bugs that were
   never being surfaced, but only on accident.

2. There was no standard way for the system to decide how to
   locate a tool.  Sometimes you have an explicit path, sometimes
   we would search for it and build up a path ourselves, and
   sometimes we would build up a full command line.  Furthermore,
   there was no standardized way to handle missing tools.  Do we
   warn, fail, ignore, etc?  All of this is now encapsulated in
   the ToolSubst class.  You either specify an exact command to
   run, or an instance of FindTool('<tool-name>') and everything
   else just works.  Furthermore, you can specify an action to
   take if the tool cannot be resolved.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315085 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Zachary Turner 2017-10-06 17:54:46 +00:00
parent e3f5d7aac0
commit 36bd96f989
2 changed files with 46 additions and 57 deletions

View File

@ -1,4 +1,4 @@
// RUN: not %clang-cc1 -fsyntax-only %s 2>&1 | FileCheck %s // RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s
// IMPORTANT: This test case intentionally DOES NOT use --disable-free. It // IMPORTANT: This test case intentionally DOES NOT use --disable-free. It
// tests that we are properly reclaiming the ASTs and we do not have a double free. // tests that we are properly reclaiming the ASTs and we do not have a double free.

View File

@ -10,7 +10,8 @@ import lit.formats
import lit.util import lit.util
from lit.llvm import llvm_config from lit.llvm import llvm_config
from lit.llvm import ToolFilter from lit.llvm.subst import ToolSubst
from lit.llvm.subst import FindTool
# Configuration file for the 'lit' test runner. # Configuration file for the 'lit' test runner.
@ -76,6 +77,8 @@ llvm_config.with_environment('LD_LIBRARY_PATH', [
llvm_config.with_system_environment( llvm_config.with_system_environment(
['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']) ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
llvm_config.use_default_substitutions()
# Discover the 'clang' and 'clangcc' to use. # Discover the 'clang' and 'clangcc' to use.
@ -120,44 +123,37 @@ if config.clang_examples:
config.available_features.add('examples') config.available_features.add('examples')
builtin_include_dir = llvm_config.get_clang_builtin_include_dir(config.clang) builtin_include_dir = llvm_config.get_clang_builtin_include_dir(config.clang)
config.substitutions.append(('%clang_analyze_cc1',
'%clang_cc1 -analyze %analyze'))
config.substitutions.append(('%clang_cc1',
'%s -cc1 -internal-isystem %s -nostdsysteminc'
% (config.clang, builtin_include_dir)))
config.substitutions.append(('%clang_cpp', ' ' + config.clang +
' --driver-mode=cpp '))
config.substitutions.append(('%clang_cl', ' ' + config.clang +
' --driver-mode=cl '))
config.substitutions.append(('%clangxx', ' ' + config.clang +
' --driver-mode=g++ '))
clang_func_map = lit.util.which( tools = [
'clang-func-mapping', config.environment['PATH']) # By specifying %clang_cc1 as part of the substitution, this substitution
if clang_func_map: # relies on repeated substitution, so must come before %clang_cc1.
config.substitutions.append( ToolSubst('%clang_analyze_cc1', command='%clang_cc1',
('%clang_func_map', ' ' + clang_func_map + ' ')) extra_args=['-analyze', '%analyze']),
ToolSubst('%clang_cc1', command=config.clang, extra_args=[
'-cc1', '-internal-isystem', builtin_include_dir, '-nostdsysteminc']),
ToolSubst('%clang_cpp', command=config.clang,
extra_args=['--driver-mode=cpp']),
ToolSubst('%clang_cl', command=config.clang,
extra_args=['--driver-mode=cl']),
ToolSubst('%clangxx', command=config.clang,
extra_args=['--driver-mode=g++']),
ToolSubst('%clang_func_map', command=FindTool(
'clang-func-mapping'), unresolved='ignore'),
ToolSubst('%clang', command=config.clang),
ToolSubst('%test_debuginfo', command=os.path.join(
config.llvm_src_root, 'utils', 'test_debuginfo.pl')),
'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt']
config.substitutions.append(('%clang', ' ' + config.clang + ' ')) if config.clang_examples:
config.substitutions.append(('%test_debuginfo', tools.append('clang-interpreter')
' ' + config.llvm_src_root + '/utils/test_debuginfo.pl '))
config.substitutions.append(('%itanium_abi_triple',
llvm_config.make_itanium_abi_triple(config.target_triple)))
config.substitutions.append(('%ms_abi_triple',
llvm_config.make_msabi_triple(config.target_triple)))
config.substitutions.append(('%resource_dir', builtin_include_dir))
config.substitutions.append(('%python', config.python_executable))
# The host triple might not be set, at least if we're compiling clang from # For each occurrence of a clang tool name, replace it with the full path to
# an already installed llvm. # the build directory holding that tool. We explicitly specify the directories
if config.host_triple and config.host_triple != '@LLVM_HOST_TRIPLE@': # to search to ensure that we get the tools just built and not some random
config.substitutions.append(('%target_itanium_abi_host_triple', # tools that might happen to be in the user's PATH.
'--target=%s' % llvm_config.make_itanium_abi_triple(config.host_triple))) tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
else:
config.substitutions.append(('%target_itanium_abi_host_triple', ''))
config.substitutions.append( llvm_config.add_tool_substitutions(tools, tool_dirs)
('%src_include_dir', config.clang_src_dir + '/include'))
# FIXME: Find nicer way to prohibit this. # FIXME: Find nicer way to prohibit this.
config.substitutions.append( config.substitutions.append(
@ -183,27 +179,22 @@ config.substitutions.append(
(' %clang-cl ', (' %clang-cl ',
"""*** invalid substitution, use '%clang_cl'. ***""")) """*** invalid substitution, use '%clang_cl'. ***"""))
# For each occurrence of a clang tool name, replace it with the full path to config.substitutions.append(('%itanium_abi_triple',
# the build directory holding that tool. We explicitly specify the directories llvm_config.make_itanium_abi_triple(config.target_triple)))
# to search to ensure that we get the tools just built and not some random config.substitutions.append(('%ms_abi_triple',
# tools that might happen to be in the user's PATH. llvm_config.make_msabi_triple(config.target_triple)))
tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir] config.substitutions.append(('%resource_dir', builtin_include_dir))
tool_patterns = [ # The host triple might not be set, at least if we're compiling clang from
'FileCheck', 'c-index-test', # an already installed llvm.
ToolFilter('clang-check', pre='-.', post='-.'), if config.host_triple and config.host_triple != '@LLVM_HOST_TRIPLE@':
ToolFilter('clang-diff', pre='-.', post='-.'), config.substitutions.append(('%target_itanium_abi_host_triple',
ToolFilter('clang-format', pre='-.', post='-.'), '--target=%s' % llvm_config.make_itanium_abi_triple(config.host_triple)))
# FIXME: Some clang test uses opt? else:
ToolFilter('opt', pre='-.', post=r'/\-.'), config.substitutions.append(('%target_itanium_abi_host_triple', ''))
# Handle these specially as they are strings searched for during testing.
ToolFilter(r'\| \bcount\b', verbatim=True),
ToolFilter(r'\| \bnot\b', verbatim=True)]
if config.clang_examples: config.substitutions.append(
tool_patterns.append(ToolFilter('clang-interpreter', '-.', '-.')) ('%src_include_dir', config.clang_src_dir + '/include'))
llvm_config.add_tool_substitutions(tool_patterns, tool_dirs)
# Set available features we allow tests to conditionalize on. # Set available features we allow tests to conditionalize on.
# #
@ -236,8 +227,6 @@ if platform.system() not in ['Darwin', 'Fuchsia']:
config.available_features.add('libgcc') config.available_features.add('libgcc')
# Case-insensitive file system # Case-insensitive file system
def is_filesystem_case_insensitive(): def is_filesystem_case_insensitive():
handle, path = tempfile.mkstemp( handle, path = tempfile.mkstemp(
prefix='case-test', dir=config.test_exec_root) prefix='case-test', dir=config.test_exec_root)