1# -*- Python -*- 2 3import os 4import subprocess 5 6# Setup config name. 7config.name = 'CRT' + config.name_suffix 8 9# Setup source root. 10config.test_source_root = os.path.dirname(__file__) 11 12 13# Choose between lit's internal shell pipeline runner and a real shell. If 14# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. 15use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") 16if use_lit_shell: 17 # 0 is external, "" is default, and everything else is internal. 18 execute_external = (use_lit_shell == "0") 19else: 20 # Otherwise we default to internal on Windows and external elsewhere, as 21 # bash on Windows is usually very slow. 22 execute_external = (not sys.platform in ['win32']) 23 24def get_library_path(file): 25 cmd = subprocess.Popen([config.clang.strip(), 26 config.target_cflags.strip(), 27 '-print-file-name=%s' % file], 28 stdout=subprocess.PIPE, 29 env=config.environment, 30 universal_newlines=True) 31 if not cmd.stdout: 32 lit_config.fatal("Couldn't find the library path for '%s'" % file) 33 dir = cmd.stdout.read().strip() 34 if sys.platform in ['win32'] and execute_external: 35 # Don't pass dosish path separator to msys bash.exe. 36 dir = dir.replace('\\', '/') 37 return dir 38 39 40def get_libgcc_file_name(): 41 cmd = subprocess.Popen([config.clang.strip(), 42 config.target_cflags.strip(), 43 '-print-libgcc-file-name'], 44 stdout=subprocess.PIPE, 45 env=config.environment, 46 universal_newlines=True) 47 if not cmd.stdout: 48 lit_config.fatal("Couldn't find the library path for '%s'" % file) 49 dir = cmd.stdout.read().strip() 50 if sys.platform in ['win32'] and execute_external: 51 # Don't pass dosish path separator to msys bash.exe. 52 dir = dir.replace('\\', '/') 53 return dir 54 55 56def build_invocation(compile_flags): 57 return ' ' + ' '.join([config.clang] + compile_flags) + ' ' 58 59 60# Setup substitutions. 61config.substitutions.append( 62 ('%clang ', build_invocation([config.target_cflags]))) 63config.substitutions.append( 64 ('%clangxx ', 65 build_invocation(config.cxx_mode_flags + [config.target_cflags]))) 66 67base_lib = os.path.join( 68 config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix) 69 70if sys.platform in ['win32'] and execute_external: 71 # Don't pass dosish path separator to msys bash.exe. 72 base_lib = base_lib.replace('\\', '/') 73 74config.substitutions.append(('%crtbegin', base_lib % "crtbegin")) 75config.substitutions.append(('%crtend', base_lib % "crtend")) 76 77config.substitutions.append( 78 ('%crt1', get_library_path('crt1.o'))) 79config.substitutions.append( 80 ('%crti', get_library_path('crti.o'))) 81config.substitutions.append( 82 ('%crtn', get_library_path('crtn.o'))) 83 84config.substitutions.append( 85 ('%libgcc', get_libgcc_file_name())) 86 87config.substitutions.append( 88 ('%libstdcxx', '-l' + config.sanitizer_cxx_lib.lstrip('lib'))) 89 90# Default test suffixes. 91config.suffixes = ['.c', '.cpp'] 92 93if config.host_os not in ['Linux']: 94 config.unsupported = True 95