@@ -375,6 +375,12 @@ if test_resource_dir:
375375 config .resource_dir_opt = ("-resource-dir %s" % test_resource_dir )
376376else :
377377 test_resource_dir = make_path (config .swift_lib_dir , 'swift' )
378+
379+ lit_config .note ('Using resource dir: ' + test_resource_dir )
380+
381+ test_clang_resource_dir = lit .util .executeCommand ([config .clang , '-print-resource-dir' ])[0 ].rstrip ()
382+ lit_config .note ('Using Clang resource dir: ' + test_clang_resource_dir )
383+
378384config .swift_system_overlay_opt = ""
379385config .clang_system_overlay_opt = ""
380386config .windows_vfs_overlay_opt = ""
@@ -396,9 +402,9 @@ config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_ove
396402stdlib_resource_dir_opt = config .resource_dir_opt
397403sourcekitd_framework_dir = config .swift_lib_dir
398404config .substitutions .append ( ('%test-resource-dir' , test_resource_dir ) )
399- lit_config .note ('Using resource dir: ' + test_resource_dir )
400405
401406# Parse the variant triple.
407+ # FIXME: We ought to parse 'run_environment' separately from 'run_os'.
402408(run_cpu , run_vendor , run_os , run_vers ) = re .match ('([^-]+)-([^-]+)-([^0-9]+)(.*)' , config .variant_triple ).groups ()
403409if run_os == 'ios' and run_vers .endswith ('-macabi' ):
404410 run_vers = run_vers [0 :- len ('-macabi' )]
@@ -2235,8 +2241,7 @@ if config.target_sdk_name in simulator_sdks:
22352241else :
22362242 config .substitutions .append (('%target-is-simulator' , 'false' ))
22372243
2238- config .compiler_rt_libs = []
2239- config .compiler_rt_platform = {
2244+ config .compiler_rt_darwin_platform = {
22402245 'iphoneos' : 'ios' ,
22412246 'appletvos' : 'tvos' ,
22422247 'watchos' : 'watchos' ,
@@ -2246,50 +2251,82 @@ config.compiler_rt_platform = {
22462251 'appletvsimulator' : 'tvossim' ,
22472252 'xrsimulator' : 'xrossim' ,
22482253 'macosx' : 'osx'
2249- }.get (config .target_sdk_name , run_cpu )
2254+ }.get (config .target_sdk_name , run_os )
2255+
2256+ def find_compiler_rt_libs ():
2257+ base = make_path (test_clang_resource_dir , 'lib' )
2258+ libs = {}
22502259
2251- def source_compiler_rt_libs (path ):
2260+ # First check to see if this is 'clang/lib/darwin', it has its own custom filename pattern.
2261+ path = make_path (base , 'darwin' )
22522262 if os .path .exists (path ):
2253- config .compiler_rt_libs .extend ([lib for lib in
2254- os .listdir (path )
2255- if lib .startswith ('libclang_rt.' )
2256- and config .compiler_rt_platform in lib ])
2263+ for lib in os .listdir (path ):
2264+ # Include any libraries with the platform name.
2265+ match = re .match (r'libclang_rt\.(?:(\w+)_)?' + config .compiler_rt_darwin_platform , lib )
2266+ if not match :
2267+ continue
2268+ component = match [1 ]
2269+ # An empty component corresponds to the 'builtins' library.
2270+ if not component :
2271+ component = 'builtins'
2272+ libs [component ] = lib
2273+
2274+ return (path , libs )
2275+
2276+ # Next check for the old scheme 'clang/lib/<os-name>', ignoring
2277+ # any target environment which is currently part of 'run_os'.
2278+ path = make_path (base , run_os .split ('-' )[0 ])
2279+ if os .path .exists (path ):
2280+ # We should then have the architecture in the name.
2281+ for lib in os .listdir (path ):
2282+ match = re .match (r'(?:lib)?clang_rt\.(\w+)-' + run_cpu , lib )
2283+ if match :
2284+ libs [match [1 ]] = lib
2285+
2286+ return (path , libs )
22572287
2258- compiler_rt_dir = make_path (test_resource_dir , 'clang' , 'lib' ,
2259- platform .system ().lower ())
2260- source_compiler_rt_libs (compiler_rt_dir )
2288+ # Finally, check the new scheme 'clang/lib/<target>'
2289+ path = make_path (base , config .variant_triple )
2290+ if os .path .exists (path ):
2291+ # We can include all the libraries here that match the base pattern.
2292+ for lib in os .listdir (path ):
2293+ match = re .match (r'(?:lib)?clang_rt\.(\w+)\.' , lib )
2294+ if match :
2295+ libs [match [1 ]] = lib
2296+
2297+ return (path , libs )
2298+
2299+ lit_config .warning ("Couldn't find clang_rt directory" )
2300+ return (None , {})
2301+
2302+ (compiler_rt_path , compiler_rt_libs ) = find_compiler_rt_libs ()
2303+ if compiler_rt_path :
2304+ lit_config .note ("Using clang_rt directory: " + compiler_rt_path )
2305+ if compiler_rt_libs :
2306+ lit_config .note ("Found clang_rt libs: {}" .format (compiler_rt_libs ))
2307+ else :
2308+ lit_config .warning ("Couldn't find any clang_rt libs for %s" % config .variant_triple )
22612309
22622310def check_runtime_libs (features_to_check ):
2263- for lib in config .compiler_rt_libs :
2264- for (libname , feature ) in features_to_check .items ():
2265- if lib .startswith ("libclang_rt." + libname + "_" ):
2266- config .available_features .add (feature )
2311+ for (libname , feature ) in features_to_check .items ():
2312+ if libname in compiler_rt_libs :
2313+ config .available_features .add (feature )
22672314
22682315runtime_libs = {
22692316 'profile' : 'profile_runtime' ,
22702317 'asan' : 'asan_runtime' ,
22712318 'ubsan' : 'ubsan_runtime' ,
22722319 'scudo' : 'scudo_runtime' ,
22732320 'safestack' : 'safestack_runtime' ,
2274- 'fuzzer' : 'fuzzer_runtime'
2321+ 'fuzzer' : 'fuzzer_runtime' ,
2322+ 'builtins' : 'c_runtime'
22752323}
22762324
22772325if run_ptrsize == '64' and 'libdispatch' in config .available_features :
22782326 runtime_libs ['tsan' ] = 'tsan_runtime'
22792327
22802328check_runtime_libs (runtime_libs )
22812329
2282- # From https://stackoverflow.com/a/2393022
2283- def strip_right (text , suffix ):
2284- if not text .endswith (suffix ):
2285- return text
2286- return text [:len (text )- len (suffix )]
2287-
2288- base_runtime_lib_name = (
2289- 'libclang_rt.' + strip_right (config .compiler_rt_platform , 'sim' ) + '.a' )
2290- if os .path .exists (make_path (compiler_rt_dir , base_runtime_lib_name )):
2291- config .available_features .add ('c_runtime' )
2292-
22932330config .substitutions .append (('%target-objc-interop' , run_objc_interop ))
22942331
22952332# For testing the remote-run utility itself, see if we can find an sftp-server
0 commit comments