@@ -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,82 @@ 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 = {}
2250
2259
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' )
2252
2262
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 )
2257
2287
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 )
2261
2309
2262
2310
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 )
2311
+ for (libname , feature ) in features_to_check .items ():
2312
+ if libname in compiler_rt_libs :
2313
+ config .available_features .add (feature )
2267
2314
2268
2315
runtime_libs = {
2269
2316
'profile' : 'profile_runtime' ,
2270
2317
'asan' : 'asan_runtime' ,
2271
2318
'ubsan' : 'ubsan_runtime' ,
2272
2319
'scudo' : 'scudo_runtime' ,
2273
2320
'safestack' : 'safestack_runtime' ,
2274
- 'fuzzer' : 'fuzzer_runtime'
2321
+ 'fuzzer' : 'fuzzer_runtime' ,
2322
+ 'builtins' : 'c_runtime'
2275
2323
}
2276
2324
2277
2325
if run_ptrsize == '64' and 'libdispatch' in config .available_features :
2278
2326
runtime_libs ['tsan' ] = 'tsan_runtime'
2279
2327
2280
2328
check_runtime_libs (runtime_libs )
2281
2329
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
2330
config .substitutions .append (('%target-objc-interop' , run_objc_interop ))
2294
2331
2295
2332
# For testing the remote-run utility itself, see if we can find an sftp-server
0 commit comments