Skip to content

Commit 2e04d65

Browse files
committed
[test] Generalize runtime library searching
Allow detecting the compiler runtime libraries for non-Darwin platforms.
1 parent 37fe4da commit 2e04d65

File tree

1 file changed

+69
-28
lines changed

1 file changed

+69
-28
lines changed

test/lit.cfg

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ if test_resource_dir:
375375
config.resource_dir_opt = ("-resource-dir %s" % test_resource_dir)
376376
else:
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+
378384
config.swift_system_overlay_opt = ""
379385
config.clang_system_overlay_opt = ""
380386
config.windows_vfs_overlay_opt = ""
@@ -396,9 +402,9 @@ config.substitutions.append( ('%windows_vfs_overlay_opt', config.windows_vfs_ove
396402
stdlib_resource_dir_opt = config.resource_dir_opt
397403
sourcekitd_framework_dir = config.swift_lib_dir
398404
config.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()
403409
if 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:
22352241
else:
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,86 @@ 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 = {}
2259+
2260+
lit_config.note("clang_rt directories: {}".format(os.listdir(base)))
22502261

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')
22522264
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)
22572290

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)
22612313

22622314
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)
22672318

22682319
runtime_libs = {
22692320
'profile': 'profile_runtime',
22702321
'asan': 'asan_runtime',
22712322
'ubsan': 'ubsan_runtime',
22722323
'scudo': 'scudo_runtime',
22732324
'safestack': 'safestack_runtime',
2274-
'fuzzer': 'fuzzer_runtime'
2325+
'fuzzer': 'fuzzer_runtime',
2326+
'builtins': 'c_runtime'
22752327
}
22762328

22772329
if run_ptrsize == '64' and 'libdispatch' in config.available_features:
22782330
runtime_libs['tsan'] = 'tsan_runtime'
22792331

22802332
check_runtime_libs(runtime_libs)
22812333

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-
22932334
config.substitutions.append(('%target-objc-interop', run_objc_interop))
22942335

22952336
# For testing the remote-run utility itself, see if we can find an sftp-server

0 commit comments

Comments
 (0)