Zachary Turner | cba522d | 2018-11-19 16:41:31 +0000 | [diff] [blame] | 1 | import os |
Zachary Turner | ba968c0 | 2018-12-01 00:22:21 +0000 | [diff] [blame] | 2 | import itertools |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 3 | import platform |
| 4 | import subprocess |
| 5 | import sys |
| 6 | |
| 7 | import lit.util |
| 8 | from lit.llvm import llvm_config |
| 9 | from lit.llvm.subst import FindTool |
| 10 | from lit.llvm.subst import ToolSubst |
| 11 | |
| 12 | def use_lldb_substitutions(config): |
| 13 | # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir |
| 14 | # which is basically the build output directory. We do not want to find these in path or |
| 15 | # anywhere else, since they are specifically the programs which are actually being tested. |
| 16 | |
| 17 | dsname = 'debugserver' if platform.system() in ['Darwin'] else 'lldb-server' |
| 18 | dsargs = [] if platform.system() in ['Darwin'] else ['gdbserver'] |
| 19 | lldbmi = ToolSubst('%lldbmi', |
| 20 | command=FindTool('lldb-mi'), |
| 21 | extra_args=['--synchronous'], |
| 22 | unresolved='ignore') |
Zachary Turner | cb6788d | 2018-12-04 21:48:27 +0000 | [diff] [blame] | 23 | |
| 24 | |
Zachary Turner | ba968c0 | 2018-12-01 00:22:21 +0000 | [diff] [blame] | 25 | build_script = os.path.dirname(__file__) |
| 26 | build_script = os.path.join(build_script, 'build.py') |
| 27 | build_script_args = [build_script, |
| 28 | '--compiler=any', # Default to best compiler |
Zachary Turner | cb6788d | 2018-12-04 21:48:27 +0000 | [diff] [blame] | 29 | '--arch=' + str(config.lldb_bitness)] |
Zachary Turner | ba968c0 | 2018-12-01 00:22:21 +0000 | [diff] [blame] | 30 | if config.lldb_lit_tools_dir: |
| 31 | build_script_args.append('--tools-dir={0}'.format(config.lldb_lit_tools_dir)) |
| 32 | if config.lldb_tools_dir: |
| 33 | build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir)) |
Zachary Turner | cb6788d | 2018-12-04 21:48:27 +0000 | [diff] [blame] | 34 | |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 35 | primary_tools = [ |
| 36 | ToolSubst('%lldb', |
| 37 | command=FindTool('lldb'), |
| 38 | extra_args=['-S', |
| 39 | os.path.join(config.test_source_root, |
| 40 | 'lit-lldb-init')]), |
| 41 | lldbmi, |
| 42 | ToolSubst('%debugserver', |
| 43 | command=FindTool(dsname), |
| 44 | extra_args=dsargs, |
| 45 | unresolved='ignore'), |
Zachary Turner | ba968c0 | 2018-12-01 00:22:21 +0000 | [diff] [blame] | 46 | 'lldb-test', |
| 47 | ToolSubst('%build', |
| 48 | command="'" + sys.executable + "'", |
| 49 | extra_args=build_script_args) |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 50 | ] |
| 51 | |
| 52 | llvm_config.add_tool_substitutions(primary_tools, |
| 53 | [config.lldb_tools_dir]) |
| 54 | if lldbmi.was_resolved: |
| 55 | config.available_features.add('lldb-mi') |
| 56 | |
| 57 | def _use_msvc_substitutions(config): |
| 58 | # If running from a Visual Studio Command prompt (e.g. vcvars), this will |
| 59 | # detect the include and lib paths, and find cl.exe and link.exe and create |
| 60 | # substitutions for each of them that explicitly specify /I and /L paths |
Zachary Turner | 47066bd | 2018-11-19 16:47:06 +0000 | [diff] [blame] | 61 | cl = lit.util.which('cl') |
| 62 | link = lit.util.which('link') |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 63 | |
| 64 | if not cl or not link: |
| 65 | return |
| 66 | |
Zachary Turner | 47066bd | 2018-11-19 16:47:06 +0000 | [diff] [blame] | 67 | cl = '"' + cl + '"' |
| 68 | link = '"' + link + '"' |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 69 | includes = os.getenv('INCLUDE', '').split(';') |
| 70 | libs = os.getenv('LIB', '').split(';') |
| 71 | |
| 72 | config.available_features.add('msvc') |
| 73 | compiler_flags = ['"/I{}"'.format(x) for x in includes if os.path.exists(x)] |
| 74 | linker_flags = ['"/LIBPATH:{}"'.format(x) for x in libs if os.path.exists(x)] |
| 75 | |
| 76 | tools = [ |
| 77 | ToolSubst('%msvc_cl', command=cl, extra_args=compiler_flags), |
| 78 | ToolSubst('%msvc_link', command=link, extra_args=linker_flags)] |
| 79 | llvm_config.add_tool_substitutions(tools) |
| 80 | return |
| 81 | |
| 82 | def use_support_substitutions(config): |
| 83 | # Set up substitutions for support tools. These tools can be overridden at the CMake |
| 84 | # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use |
| 85 | # the just-built version. |
| 86 | flags = [] |
| 87 | if platform.system() in ['Darwin']: |
| 88 | try: |
| 89 | out = subprocess.check_output(['xcrun', '--show-sdk-path']).strip() |
| 90 | res = 0 |
| 91 | except OSError: |
| 92 | res = -1 |
| 93 | if res == 0 and out: |
| 94 | sdk_path = lit.util.to_string(out) |
Davide Italiano | ff81ffd | 2018-11-26 17:39:20 +0000 | [diff] [blame] | 95 | llvm_config.lit_config.note('using SDKROOT: %r' % sdk_path) |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 96 | flags = ['-isysroot', sdk_path] |
Stella Stamenova | 839a0cb | 2018-11-21 20:16:06 +0000 | [diff] [blame] | 97 | elif platform.system() in ['OpenBSD', 'Linux']: |
Zachary Turner | 58db03a | 2018-11-19 15:12:34 +0000 | [diff] [blame] | 98 | flags = ['-pthread'] |
| 99 | |
| 100 | |
| 101 | additional_tool_dirs=[] |
| 102 | if config.lldb_lit_tools_dir: |
| 103 | additional_tool_dirs.append(config.lldb_lit_tools_dir) |
| 104 | |
| 105 | llvm_config.use_clang(additional_flags=flags, |
| 106 | additional_tool_dirs=additional_tool_dirs, |
| 107 | required=True) |
| 108 | |
| 109 | if sys.platform == 'win32': |
| 110 | _use_msvc_substitutions(config) |
| 111 | |
| 112 | have_lld = llvm_config.use_lld(additional_tool_dirs=additional_tool_dirs, |
| 113 | required=False) |
| 114 | if have_lld: |
| 115 | config.available_features.add('lld') |
| 116 | |
| 117 | |
| 118 | support_tools = ['yaml2obj', 'obj2yaml', 'llvm-pdbutil', |
| 119 | 'llvm-mc', 'llvm-readobj', 'llvm-objdump', |
| 120 | 'llvm-objcopy'] |
| 121 | additional_tool_dirs += [config.lldb_tools_dir, config.llvm_tools_dir] |
| 122 | llvm_config.add_tool_substitutions(support_tools, additional_tool_dirs) |