@@ -375,6 +375,12 @@ if test_resource_dir:
375
375
config .resource_dir_opt = ("-resource-dir %s" % test_resource_dir )
376
376
else :
377
377
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
+
378
384
config .swift_system_overlay_opt = ""
379
385
config .clang_system_overlay_opt = ""
380
386
config .windows_vfs_overlay_opt = ""
@@ -396,9 +402,9 @@ config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_ove
396
402
stdlib_resource_dir_opt = config .resource_dir_opt
397
403
sourcekitd_framework_dir = config .swift_lib_dir
398
404
config .substitutions .append ( ('%test-resource-dir' , test_resource_dir ) )
399
- lit_config .note ('Using resource dir: ' + test_resource_dir )
400
405
401
406
# Parse the variant triple.
407
+ # FIXME: We ought to parse 'run_environment' separately from 'run_os'.
402
408
(run_cpu , run_vendor , run_os , run_vers ) = re .match ('([^-]+)-([^-]+)-([^0-9]+)(.*)' , config .variant_triple ).groups ()
403
409
if run_os == 'ios' and run_vers .endswith ('-macabi' ):
404
410
run_vers = run_vers [0 :- len ('-macabi' )]
@@ -2235,8 +2241,7 @@ if config.target_sdk_name in simulator_sdks:
2235
2241
else :
2236
2242
config .substitutions .append (('%target-is-simulator' , 'false' ))
2237
2243
2238
- config .compiler_rt_libs = []
2239
- config .compiler_rt_platform = {
2244
+ config .compiler_rt_darwin_platform = {
2240
2245
'iphoneos' : 'ios' ,
2241
2246
'appletvos' : 'tvos' ,
2242
2247
'watchos' : 'watchos' ,
@@ -2246,50 +2251,86 @@ config.compiler_rt_platform = {
2246
2251
'appletvsimulator' : 'tvossim' ,
2247
2252
'xrsimulator' : 'xrossim' ,
2248
2253
'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 = {}
2259
+
2260
+ lit_config .note ("clang_rt directories: {}" .format (os .listdir (base )))
2250
2261
2251
- def source_compiler_rt_libs (path ):
2262
+ # First check to see if this is 'clang/lib/darwin', it has its own custom filename pattern.
2263
+ path = make_path (base , 'darwin' )
2252
2264
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 ])
2265
+ for lib in os .listdir (path ):
2266
+ # Include any libraries with the platform name.
2267
+ match = re .match (r'libclang_rt\.(?:(\w+)_)?' + config .compiler_rt_darwin_platform , lib )
2268
+ if not match :
2269
+ continue
2270
+ component = match [1 ]
2271
+ # An empty component corresponds to the 'builtins' library.
2272
+ if not component :
2273
+ component = 'builtins'
2274
+ libs [component ] = lib
2275
+
2276
+ return (path , libs )
2277
+
2278
+ # Next check for the old scheme 'clang/lib/<os-name>', ignoring
2279
+ # any target environment which is currently part of 'run_os'.
2280
+ path = make_path (base , run_os .split ('-' )[0 ])
2281
+ lit_config .note ("Trying clang_rt directory: {}" .format (path ))
2282
+ if os .path .exists (path ):
2283
+ # We should then have the architecture in the name.
2284
+ for lib in os .listdir (path ):
2285
+ match = re .match (r'(?:lib)?clang_rt\.(\w+)-' + run_cpu , lib )
2286
+ if match :
2287
+ libs [match [1 ]] = lib
2288
+
2289
+ return (path , libs )
2257
2290
2258
- compiler_rt_dir = make_path (test_resource_dir , 'clang' , 'lib' ,
2259
- platform .system ().lower ())
2260
- source_compiler_rt_libs (compiler_rt_dir )
2291
+ # Finally, check the new scheme 'clang/lib/<target>'
2292
+ path = make_path (base , config .variant_triple )
2293
+ lit_config .note ("Trying clang_rt directory: {}" .format (path ))
2294
+ if os .path .exists (path ):
2295
+ # We can include all the libraries here that match the base pattern.
2296
+ for lib in os .listdir (path ):
2297
+ match = re .match (r'(?:lib)?clang_rt\.(\w+)\.' , lib )
2298
+ if match :
2299
+ libs [match [1 ]] = lib
2300
+
2301
+ return (path , libs )
2302
+
2303
+ lit_config .warning ("Couldn't find clang_rt directory" )
2304
+ return (None , {})
2305
+
2306
+ (compiler_rt_path , compiler_rt_libs ) = find_compiler_rt_libs ()
2307
+ if compiler_rt_path :
2308
+ lit_config .note ("Using clang_rt directory: " + compiler_rt_path )
2309
+ if compiler_rt_libs :
2310
+ lit_config .note ("Found clang_rt libs: {}" .format (compiler_rt_libs ))
2311
+ else :
2312
+ lit_config .warning ("Couldn't find any clang_rt libs for %s" % config .variant_triple )
2261
2313
2262
2314
def 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 )
2315
+ for (libname , feature ) in features_to_check .items ():
2316
+ if libname in compiler_rt_libs :
2317
+ config .available_features .add (feature )
2267
2318
2268
2319
runtime_libs = {
2269
2320
'profile' : 'profile_runtime' ,
2270
2321
'asan' : 'asan_runtime' ,
2271
2322
'ubsan' : 'ubsan_runtime' ,
2272
2323
'scudo' : 'scudo_runtime' ,
2273
2324
'safestack' : 'safestack_runtime' ,
2274
- 'fuzzer' : 'fuzzer_runtime'
2325
+ 'fuzzer' : 'fuzzer_runtime' ,
2326
+ 'builtins' : 'c_runtime'
2275
2327
}
2276
2328
2277
2329
if run_ptrsize == '64' and 'libdispatch' in config .available_features :
2278
2330
runtime_libs ['tsan' ] = 'tsan_runtime'
2279
2331
2280
2332
check_runtime_libs (runtime_libs )
2281
2333
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
-
2293
2334
config .substitutions .append (('%target-objc-interop' , run_objc_interop ))
2294
2335
2295
2336
# For testing the remote-run utility itself, see if we can find an sftp-server
0 commit comments