Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | import re |
Sam McCall | 7f0df31 | 2022-03-10 22:57:05 | [diff] [blame^] | 6 | import shlex |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 7 | import subprocess |
| 8 | |
Daniel Dunbar | 4d0a3ef | 2013-08-09 18:49:22 | [diff] [blame] | 9 | import lit.formats |
| 10 | import lit.util |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 11 | |
Sam McCall | 69924cc | 2022-03-10 22:09:46 | [diff] [blame] | 12 | from lit.llvm import llvm_config |
| 13 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 14 | # Configuration file for the 'lit' test runner. |
| 15 | |
Chandler Carruth | 074a356 | 2013-03-07 10:09:47 | [diff] [blame] | 16 | # name: The name of this test suite. |
| 17 | config.name = 'Clang Tools' |
| 18 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 19 | # testFormat: The test format to use to interpret tests. |
Sam McCall | 69924cc | 2022-03-10 22:09:46 | [diff] [blame] | 20 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 21 | |
| 22 | # suffixes: A list of file extensions to treat as test files. |
Alexander Kornienko | b816ba0 | 2016-01-08 16:37:11 | [diff] [blame] | 23 | config.suffixes = ['.c', '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', |
Benjamin Kramer | 03016b8 | 2016-05-31 12:12:19 | [diff] [blame] | 24 | '.modularize', '.module-map-checker', '.test'] |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 25 | |
Edwin Vane | 9f7a1c1 | 2013-08-22 19:44:07 | [diff] [blame] | 26 | # Test-time dependencies located in directories called 'Inputs' are excluded |
| 27 | # from test suites; there won't be any lit tests within them. |
| 28 | config.excludes = ['Inputs'] |
| 29 | |
Chandler Carruth | 074a356 | 2013-03-07 10:09:47 | [diff] [blame] | 30 | # test_source_root: The root path where tests are located. |
| 31 | config.test_source_root = os.path.dirname(__file__) |
| 32 | |
| 33 | # test_exec_root: The root path where tests should be run. |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 | [diff] [blame] | 34 | config.test_exec_root = os.path.join(config.clang_tools_binary_dir, 'test') |
Chandler Carruth | 074a356 | 2013-03-07 10:09:47 | [diff] [blame] | 35 | |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 36 | # Clear some environment variables that might affect Clang. |
| 37 | # |
| 38 | # This first set of vars are read by Clang, but shouldn't affect tests |
| 39 | # that aren't specifically looking for these features, or are required |
| 40 | # simply to run the tests at all. |
| 41 | # |
| 42 | # FIXME: Should we have a tool that enforces this? |
| 43 | |
| 44 | # safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD', |
| 45 | # 'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET', |
| 46 | # 'IOS_SIMULATOR_DEPLOYMENT_TARGET', |
| 47 | # 'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS', |
| 48 | # 'VC80COMNTOOLS') |
| 49 | possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
| 50 | 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 51 | 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 52 | 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 53 | 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 54 | 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 55 | 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 56 | 'LIBCLANG_RESOURCE_USAGE', |
| 57 | 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 58 | # Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 59 | if platform.system() != 'Windows': |
| 60 | possibly_dangerous_env_vars.append('INCLUDE') |
| 61 | for name in possibly_dangerous_env_vars: |
| 62 | if name in config.environment: |
| 63 | del config.environment[name] |
| 64 | |
| 65 | # Tweak the PATH to include the tools dir and the scripts dir. |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 | [diff] [blame] | 66 | path = os.path.pathsep.join(( |
| 67 | config.clang_tools_dir, config.llvm_tools_dir, config.environment['PATH'])) |
| 68 | config.environment['PATH'] = path |
Chandler Carruth | c5062dc | 2012-08-07 07:09:14 | [diff] [blame] | 69 | |
Zachary Turner | ce92db1 | 2017-09-15 22:10:46 | [diff] [blame] | 70 | path = os.path.pathsep.join((config.clang_libs_dir, config.llvm_libs_dir, |
| 71 | config.environment.get('LD_LIBRARY_PATH',''))) |
| 72 | config.environment['LD_LIBRARY_PATH'] = path |
David Blaikie | d7086fb | 2012-09-04 22:23:37 | [diff] [blame] | 73 | |
Nico Weber | 33c9dbb | 2020-09-03 23:37:29 | [diff] [blame] | 74 | if config.clang_tidy_staticanalyzer: |
Michal Gorny | a81de44 | 2017-08-29 05:58:08 | [diff] [blame] | 75 | config.available_features.add('static-analyzer') |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 76 | |
Sam McCall | 7f0df31 | 2022-03-10 22:57:05 | [diff] [blame^] | 77 | python_exec = shlex.quote(config.python_executable) |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 78 | check_clang_tidy = os.path.join( |
| 79 | config.test_source_root, "clang-tidy", "check_clang_tidy.py") |
| 80 | config.substitutions.append( |
| 81 | ('%check_clang_tidy', |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 82 | '%s %s' % (python_exec, check_clang_tidy)) ) |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 83 | clang_tidy_diff = os.path.join( |
| 84 | config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py") |
| 85 | config.substitutions.append( |
| 86 | ('%clang_tidy_diff', |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 87 | '%s %s' % (python_exec, clang_tidy_diff)) ) |
Stephen Kelly | a3c4206 | 2018-10-01 20:24:22 | [diff] [blame] | 88 | run_clang_tidy = os.path.join( |
| 89 | config.test_source_root, "..", "clang-tidy", "tool", "run-clang-tidy.py") |
| 90 | config.substitutions.append( |
| 91 | ('%run_clang_tidy', |
Reid Kleckner | b250a62 | 2019-06-21 18:17:04 | [diff] [blame] | 92 | '%s %s' % (python_exec, run_clang_tidy)) ) |
Kirill Bobyrev | 73c201d | 2018-09-12 07:49:44 | [diff] [blame] | 93 | |
Jameson Nash | 84f137a | 2022-02-01 17:05:20 | [diff] [blame] | 94 | config.substitutions.append(('%llvmshlibdir', config.clang_libs_dir)) |
| 95 | config.substitutions.append(('%pluginext', config.llvm_plugin_ext)) |
| 96 | |
| 97 | # Plugins (loadable modules) |
| 98 | if config.has_plugins and config.llvm_plugin_ext: |
| 99 | config.available_features.add('plugins') |