150
|
1 # -*- Python -*-
|
|
2
|
|
3 import os
|
|
4 import platform
|
|
5 import re
|
|
6 import subprocess
|
|
7
|
|
8 import lit.formats
|
|
9 import lit.util
|
|
10
|
|
11 # Configuration file for the 'lit' test runner.
|
|
12
|
|
13 # name: The name of this test suite.
|
|
14 config.name = 'Clang Tools'
|
|
15
|
|
16 # Tweak PATH for Win32
|
|
17 if platform.system() == 'Windows':
|
|
18 # Seek sane tools in directories and set to $PATH.
|
|
19 path = getattr(config, 'lit_tools_dir', None)
|
|
20 path = lit_config.getToolsPath(path,
|
|
21 config.environment['PATH'],
|
|
22 ['cmp.exe', 'grep.exe', 'sed.exe'])
|
|
23 if path is not None:
|
|
24 path = os.path.pathsep.join((path,
|
|
25 config.environment['PATH']))
|
|
26 config.environment['PATH'] = path
|
|
27
|
|
28 # Choose between lit's internal shell pipeline runner and a real shell. If
|
|
29 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
|
|
30 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
|
|
31 if use_lit_shell:
|
|
32 # 0 is external, "" is default, and everything else is internal.
|
|
33 execute_external = (use_lit_shell == "0")
|
|
34 else:
|
|
35 # Otherwise we default to internal on Windows and external elsewhere, as
|
|
36 # bash on Windows is usually very slow.
|
|
37 execute_external = (not sys.platform in ['win32'])
|
|
38
|
|
39 # testFormat: The test format to use to interpret tests.
|
|
40 #
|
|
41 # For now we require '&&' between commands, until they get globally killed and
|
|
42 # the test runner updated.
|
|
43 config.test_format = lit.formats.ShTest(execute_external)
|
|
44
|
|
45 # suffixes: A list of file extensions to treat as test files.
|
|
46 config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s',
|
|
47 '.modularize', '.module-map-checker', '.test']
|
|
48
|
|
49 # Test-time dependencies located in directories called 'Inputs' are excluded
|
|
50 # from test suites; there won't be any lit tests within them.
|
|
51 config.excludes = ['Inputs']
|
|
52
|
|
53 # test_source_root: The root path where tests are located.
|
|
54 config.test_source_root = os.path.dirname(__file__)
|
|
55
|
|
56 # test_exec_root: The root path where tests should be run.
|
|
57 config.test_exec_root = os.path.join(config.clang_tools_binary_dir, 'test')
|
|
58
|
|
59 # Clear some environment variables that might affect Clang.
|
|
60 #
|
|
61 # This first set of vars are read by Clang, but shouldn't affect tests
|
|
62 # that aren't specifically looking for these features, or are required
|
|
63 # simply to run the tests at all.
|
|
64 #
|
|
65 # FIXME: Should we have a tool that enforces this?
|
|
66
|
|
67 # safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
|
|
68 # 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
|
|
69 # 'IOS_SIMULATOR_DEPLOYMENT_TARGET',
|
|
70 # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
|
|
71 # 'VC80COMNTOOLS')
|
|
72 possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
|
|
73 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
|
|
74 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
|
|
75 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
|
|
76 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
|
|
77 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
|
|
78 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
|
|
79 'LIBCLANG_RESOURCE_USAGE',
|
|
80 'LIBCLANG_CODE_COMPLETION_LOGGING']
|
|
81 # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
|
|
82 if platform.system() != 'Windows':
|
|
83 possibly_dangerous_env_vars.append('INCLUDE')
|
|
84 for name in possibly_dangerous_env_vars:
|
|
85 if name in config.environment:
|
|
86 del config.environment[name]
|
|
87
|
|
88 # Tweak the PATH to include the tools dir and the scripts dir.
|
|
89 path = os.path.pathsep.join((
|
|
90 config.clang_tools_dir, config.llvm_tools_dir, config.environment['PATH']))
|
|
91 config.environment['PATH'] = path
|
|
92
|
|
93 path = os.path.pathsep.join((config.clang_libs_dir, config.llvm_libs_dir,
|
|
94 config.environment.get('LD_LIBRARY_PATH','')))
|
|
95 config.environment['LD_LIBRARY_PATH'] = path
|
|
96
|
|
97 # When running under valgrind, we mangle '-vg' onto the end of the triple so we
|
|
98 # can check it with XFAIL and XTARGET.
|
|
99 if lit_config.useValgrind:
|
|
100 config.target_triple += '-vg'
|
|
101
|
|
102 config.available_features.add('crash-recovery')
|
|
103 # Set available features we allow tests to conditionalize on.
|
|
104 #
|
|
105
|
|
106 # Shell execution
|
|
107 if execute_external:
|
|
108 config.available_features.add('shell')
|
|
109
|
|
110 # Exclude MSYS due to transforming '/' to 'X:/mingwroot/'.
|
|
111 if not platform.system() in ['Windows'] or not execute_external:
|
|
112 config.available_features.add('shell-preserves-root')
|
|
113
|
|
114 # ANSI escape sequences in non-dumb terminal
|
|
115 if platform.system() not in ['Windows']:
|
|
116 config.available_features.add('ansi-escape-sequences')
|
|
117
|
207
|
118 if config.clang_tidy_staticanalyzer:
|
150
|
119 config.available_features.add('static-analyzer')
|
|
120
|
|
121 # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
|
|
122 # it's not available.
|
|
123 try:
|
|
124 import shlex
|
|
125 sh_quote = shlex.quote
|
|
126 except:
|
|
127 import pipes
|
|
128 sh_quote = pipes.quote
|
|
129 python_exec = sh_quote(config.python_executable)
|
|
130
|
|
131 check_clang_tidy = os.path.join(
|
|
132 config.test_source_root, "clang-tidy", "check_clang_tidy.py")
|
|
133 config.substitutions.append(
|
|
134 ('%check_clang_tidy',
|
|
135 '%s %s' % (python_exec, check_clang_tidy)) )
|
|
136 clang_tidy_diff = os.path.join(
|
|
137 config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py")
|
|
138 config.substitutions.append(
|
|
139 ('%clang_tidy_diff',
|
|
140 '%s %s' % (python_exec, clang_tidy_diff)) )
|
|
141 run_clang_tidy = os.path.join(
|
|
142 config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py")
|
|
143 config.substitutions.append(
|
|
144 ('%run_clang_tidy',
|
|
145 '%s %s' % (python_exec, run_clang_tidy)) )
|
|
146
|
|
147 clangd_benchmarks_dir = os.path.join(os.path.dirname(config.clang_tools_dir),
|
|
148 "tools", "clang", "tools", "extra",
|
|
149 "clangd", "benchmarks")
|
|
150 config.substitutions.append(('%clangd-benchmark-dir',
|
|
151 '%s' % (clangd_benchmarks_dir)))
|