11import os
22import itertools
33import platform
4+ import re
45import subprocess
56import sys
67
78import lit .util
9+ from lit .formats import ShTest
810from lit .llvm import llvm_config
911from lit .llvm .subst import FindTool
1012from lit .llvm .subst import ToolSubst
1113
14+ import posixpath
1215
1316def _get_lldb_init_path (config ):
1417 return os .path .join (config .test_exec_root , "lit-lldb-init-quiet" )
@@ -22,6 +25,68 @@ def _disallow(config, execName):
2225 config .substitutions .append ((" {0} " .format (execName ), warning .format (execName )))
2326
2427
28+ def get_lldb_args (config , suffix = "" ):
29+ lldb_args = []
30+ if "remote-linux" in config .available_features :
31+ lldb_args += [
32+ "-O" ,
33+ '"platform select remote-linux"' ,
34+ "-O" ,
35+ f'"platform connect { config .lldb_platform_url } "' ,
36+ ]
37+ if config .lldb_platform_working_dir :
38+ dir = posixpath .join (f"{ config .lldb_platform_working_dir } " , "shell" )
39+ if suffix :
40+ dir += posixpath .join (dir , f"{ suffix } " )
41+ lldb_args += [
42+ "-O" ,
43+ f'"platform shell mkdir -p { dir } "' ,
44+ "-O" ,
45+ f'"platform settings -w { dir } "' ,
46+ ]
47+ lldb_args += ["--no-lldbinit" , "-S" , _get_lldb_init_path (config )]
48+ return lldb_args
49+
50+
51+ class ShTestLldb (ShTest ):
52+ def __init__ (
53+ self , execute_external = False , extra_substitutions = [], preamble_commands = []
54+ ):
55+ super ().__init__ (execute_external , extra_substitutions , preamble_commands )
56+
57+ def execute (self , test , litConfig ):
58+ # Run each Shell test in a separate directory (on remote).
59+
60+ # Find directory change command in %lldb substitution.
61+ for i , t in enumerate (test .config .substitutions ):
62+ if re .match (t [0 ], "%lldb" ):
63+ cmd = t [1 ]
64+ if '-O "platform settings -w ' in cmd :
65+ # If command is present, it is added by get_lldb_args.
66+ # Replace the path with the tests' path in suite.
67+ # Example:
68+ # bin/lldb
69+ # -O "platform shell mkdir -p /home/user/shell"
70+ # -O "platform settings -w /home/user/shell" ...
71+ # =>
72+ # bin/lldb
73+ # -O "platform shell mkdir -p /home/user/shell/SymbolFile/Breakpad/inline-record.test"
74+ # -O "platform settings -w /home/user/shell/SymbolFile/Breakpad/inline-record.test" ...
75+ args_def = " " .join (get_lldb_args (test .config ))
76+ args_unique = " " .join (
77+ get_lldb_args (
78+ test .config ,
79+ posixpath .join (* test .path_in_suite ),
80+ )
81+ )
82+ test .config .substitutions [i ] = (
83+ t [0 ],
84+ cmd .replace (args_def , args_unique ),
85+ )
86+ break
87+ return super ().execute (test , litConfig )
88+
89+
2590def use_lldb_substitutions (config ):
2691 # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
2792 # which is basically the build output directory. We do not want to find these in path or
@@ -34,7 +99,9 @@ def use_lldb_substitutions(config):
3499 build_script = os .path .join (build_script , "build.py" )
35100 build_script_args = [
36101 build_script ,
37- "--compiler=any" , # Default to best compiler
102+ (
103+ "--compiler=clang" if config .enable_remote else "--compiler=any"
104+ ), # Default to best compiler
38105 "--arch=" + str (config .lldb_bitness ),
39106 ]
40107 if config .lldb_lit_tools_dir :
@@ -56,7 +123,7 @@ def use_lldb_substitutions(config):
56123 ToolSubst (
57124 "%lldb" ,
58125 command = FindTool ("lldb" ),
59- extra_args = [ "--no-lldbinit" , "-S" , lldb_init ] ,
126+ extra_args = get_lldb_args ( config ) ,
60127 unresolved = "fatal" ,
61128 ),
62129 ToolSubst (
@@ -138,7 +205,10 @@ def use_support_substitutions(config):
138205 # Set up substitutions for support tools. These tools can be overridden at the CMake
139206 # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
140207 # the just-built version.
141- host_flags = ["--target=" + config .host_triple ]
208+ if config .enable_remote :
209+ host_flags = ["--target=" + config .target_triple ]
210+ else :
211+ host_flags = ["--target=" + config .host_triple ]
142212 if platform .system () in ["Darwin" ]:
143213 try :
144214 out = subprocess .check_output (["xcrun" , "--show-sdk-path" ]).strip ()
@@ -165,6 +235,12 @@ def use_support_substitutions(config):
165235 if config .cmake_sysroot :
166236 host_flags += ["--sysroot={}" .format (config .cmake_sysroot )]
167237
238+ if config .enable_remote and config .has_libcxx :
239+ host_flags += [
240+ "-L{}" .format (config .libcxx_libs_dir ),
241+ "-lc++" ,
242+ ]
243+
168244 host_flags = " " .join (host_flags )
169245 config .substitutions .append (("%clang_host" , "%clang " + host_flags ))
170246 config .substitutions .append (("%clangxx_host" , "%clangxx " + host_flags ))
0 commit comments