Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | # -*- 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. |
| 6 | import os |
| 7 | import platform |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 8 | import subprocess |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | |
| 10 | import lit.formats |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 11 | import lit.util |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 12 | |
| 13 | # Setup test format |
| 14 | execute_external = (platform.system() != 'Windows' |
| 15 | or lit_config.getBashPath() not in [None, ""]) |
| 16 | config.test_format = lit.formats.ShTest(execute_external) |
| 17 | |
| 18 | # Setup clang binary. |
| 19 | compiler_path = getattr(config, 'clang', None) |
| 20 | if (not compiler_path) or (not os.path.exists(compiler_path)): |
| 21 | lit_config.fatal("Can't find compiler on path %r" % compiler_path) |
| 22 | |
| 23 | compiler_id = getattr(config, 'compiler_id', None) |
| 24 | if compiler_id == "Clang": |
| 25 | if platform.system() != 'Windows': |
| 26 | config.cxx_mode_flags = ["--driver-mode=g++"] |
| 27 | else: |
| 28 | config.cxx_mode_flags = [] |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 29 | # 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 Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 32 | elif compiler_id == 'GNU': |
| 33 | config.cxx_mode_flags = ["-x c++"] |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 34 | config.debug_info_flags = ["-g"] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 35 | else: |
| 36 | lit_config.fatal("Unsupported compiler id: %r" % compiler_id) |
| 37 | # Add compiler ID to the list of available features. |
| 38 | config.available_features.add(compiler_id) |
| 39 | |
| 40 | # Clear some environment variables that might affect Clang. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 41 | possibly_dangerous_env_vars = ['ASAN_OPTIONS', 'DFSAN_OPTIONS', 'LSAN_OPTIONS', |
| 42 | 'MSAN_OPTIONS', 'UBSAN_OPTIONS', |
| 43 | 'COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 44 | '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. |
| 53 | if platform.system() != 'Windows': |
| 54 | possibly_dangerous_env_vars.append('INCLUDE') |
| 55 | for 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. |
| 60 | llvm_tools_dir = getattr(config, 'llvm_tools_dir', None) |
| 61 | if (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) |
| 63 | path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH'])) |
| 64 | config.environment['PATH'] = path |
| 65 | |
| 66 | # Help MSVS link.exe find the standard libraries. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 67 | # Make sure we only try to use it when targetting Windows. |
| 68 | if platform.system() == 'Windows' and '-win' in config.target_triple: |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 69 | config.environment['LIB'] = os.environ['LIB'] |
| 70 | |
| 71 | # Use ugly construction to explicitly prohibit "clang", "clang++" etc. |
| 72 | # in RUN lines. |
| 73 | config.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. |
| 78 | config.substitutions.append( ('%run', config.emulator) ) |
| 79 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 80 | # Define CHECK-%os to check for OS-dependent output. |
| 81 | config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) |
| 82 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 83 | # Add supported compiler_rt architectures to a list of available features. |
| 84 | compiler_rt_arch = getattr(config, 'compiler_rt_arch', None) |
| 85 | if compiler_rt_arch: |
| 86 | for arch in compiler_rt_arch.split(";"): |
| 87 | config.available_features.add(arch + "-supported-target") |
| 88 | |
| 89 | compiler_rt_debug = getattr(config, 'compiler_rt_debug', False) |
| 90 | if not compiler_rt_debug: |
| 91 | config.available_features.add('compiler-rt-optimized') |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 92 | |
| 93 | lit.util.usePlatformSdkOnDarwin(config, lit_config) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 94 | |
| 95 | def is_darwin_lto_supported(): |
| 96 | return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib')) |
| 97 | |
| 98 | def 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 | |
| 111 | if 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 = [] |
| 115 | elif 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"] |
| 119 | else: |
| 120 | config.lto_supported = False |