blob: 2a5d01cccce2b344b9f9297afb5d22b7efdf46f6 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001# -*- Python -*-
2
3# Configuration file for 'lit' test runner.
4# This file contains common rules for various compiler-rt testsuites.
5# It is mostly copied from lit.cfg used by Clang.
6import os
7import platform
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07008import subprocess
Stephen Hines2d1fdb22014-05-28 23:58:16 -07009
10import lit.formats
Stephen Hines6a211c52014-07-21 00:49:56 -070011import lit.util
Stephen Hines2d1fdb22014-05-28 23:58:16 -070012
13# Setup test format
14execute_external = (platform.system() != 'Windows'
15 or lit_config.getBashPath() not in [None, ""])
16config.test_format = lit.formats.ShTest(execute_external)
17
18# Setup clang binary.
19compiler_path = getattr(config, 'clang', None)
20if (not compiler_path) or (not os.path.exists(compiler_path)):
21 lit_config.fatal("Can't find compiler on path %r" % compiler_path)
22
23compiler_id = getattr(config, 'compiler_id', None)
24if compiler_id == "Clang":
25 if platform.system() != 'Windows':
26 config.cxx_mode_flags = ["--driver-mode=g++"]
27 else:
28 config.cxx_mode_flags = []
Stephen Hines6d186232014-11-26 17:56:19 -080029 # We assume that sanitizers should provide good enough error
30 # reports and stack traces even with minimal debug info.
31 config.debug_info_flags = ["-gline-tables-only"]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070032elif compiler_id == 'GNU':
33 config.cxx_mode_flags = ["-x c++"]
Stephen Hines6d186232014-11-26 17:56:19 -080034 config.debug_info_flags = ["-g"]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070035else:
36 lit_config.fatal("Unsupported compiler id: %r" % compiler_id)
37# Add compiler ID to the list of available features.
38config.available_features.add(compiler_id)
39
40# Clear some environment variables that might affect Clang.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070041possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS',
42 'MSAN_OPTIONS', 'UBSAN_OPTIONS',
43 'COMPILER_PATH', 'RC_DEBUG_OPTIONS',
Stephen Hines2d1fdb22014-05-28 23:58:16 -070044 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
45 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
46 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
47 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
48 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
49 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
50 'LIBCLANG_RESOURCE_USAGE',
51 'LIBCLANG_CODE_COMPLETION_LOGGING']
52# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
53if platform.system() != 'Windows':
54 possibly_dangerous_env_vars.append('INCLUDE')
55for name in possibly_dangerous_env_vars:
56 if name in config.environment:
57 del config.environment[name]
58
59# Tweak PATH to include llvm tools dir.
60llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
61if (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)):
62 lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
63path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
64config.environment['PATH'] = path
65
66# Help MSVS link.exe find the standard libraries.
Stephen Hines86277eb2015-03-23 12:06:32 -070067# Make sure we only try to use it when targetting Windows.
68if platform.system() == 'Windows' and '-win' in config.target_triple:
Stephen Hines2d1fdb22014-05-28 23:58:16 -070069 config.environment['LIB'] = os.environ['LIB']
70
71# Use ugly construction to explicitly prohibit "clang", "clang++" etc.
72# in RUN lines.
73config.substitutions.append(
74 (' clang', """\n\n*** Do not use 'clangXXX' in tests,
75 instead define '%clangXXX' substitution in lit config. ***\n\n""") )
76
77# Allow tests to be executed on a simulator or remotely.
78config.substitutions.append( ('%run', config.emulator) )
79
Stephen Hines6d186232014-11-26 17:56:19 -080080# Define CHECK-%os to check for OS-dependent output.
81config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
82
Stephen Hines2d1fdb22014-05-28 23:58:16 -070083# Add supported compiler_rt architectures to a list of available features.
84compiler_rt_arch = getattr(config, 'compiler_rt_arch', None)
85if compiler_rt_arch:
86 for arch in compiler_rt_arch.split(";"):
87 config.available_features.add(arch + "-supported-target")
88
89compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
90if not compiler_rt_debug:
91 config.available_features.add('compiler-rt-optimized')
Stephen Hines6a211c52014-07-21 00:49:56 -070092
93lit.util.usePlatformSdkOnDarwin(config, lit_config)
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -070094
95def is_darwin_lto_supported():
96 return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
97
98def is_linux_lto_supported():
99 if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
100 return False
101
102 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE)
103 ld_out = ld_cmd.stdout.read().decode()
104 ld_cmd.wait()
105
106 if not '-plugin' in ld_out:
107 return False
108
109 return True
110
111if sys.platform == 'darwin' and is_darwin_lto_supported():
112 config.lto_supported = True
113 config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
114 config.lto_flags = []
115elif sys.platform.startswith('linux') and is_linux_lto_supported():
116 config.lto_supported = True
117 config.lto_launch = []
118 config.lto_flags = ["-fuse-ld=gold"]
119else:
120 config.lto_supported = False