189 lines · python
1# -*- Python -*-2 3import os4import re5 6 7def get_required_attr(config, attr_name):8 attr_value = getattr(config, attr_name, None)9 if attr_value is None:10 lit_config.fatal(11 "No attribute %r in test configuration! You may need to run "12 "tests from your build directory or add this attribute "13 "to lit.site.cfg.py " % attr_name14 )15 return attr_value16 17 18# Setup config name.19config.name = "Profile-" + config.target_arch20 21# Setup source root.22config.test_source_root = os.path.dirname(__file__)23 24# Setup executable root.25if (26 hasattr(config, "profile_lit_binary_dir")27 and config.profile_lit_binary_dir is not None28):29 config.test_exec_root = os.path.join(config.profile_lit_binary_dir, config.name)30 31target_is_msvc = bool(re.match(r".*-windows-msvc$", config.target_triple))32 33if config.target_os in ["Linux"]:34 extra_link_flags = ["-ldl"]35elif target_is_msvc:36 # InstrProf is incompatible with incremental linking. Disable it as a37 # workaround.38 extra_link_flags = ["-Wl,-incremental:no"]39else:40 extra_link_flags = []41 42# Test suffixes.43config.suffixes = [".c", ".cpp", ".m", ".mm", ".ll", ".test"]44 45# What to exclude.46config.excludes = ["Inputs"]47 48# Clang flags.49target_cflags = [get_required_attr(config, "target_cflags")]50clang_cflags = target_cflags + extra_link_flags51clang_cxxflags = config.cxx_mode_flags + clang_cflags52 53# TODO: target_cflags can sometimes contain C++ only flags like -stdlib=<FOO>, which are54# ignored when compiling as C code. Passing this flag when compiling as C results in55# warnings that break tests that use -Werror.56# We remove -stdlib= from the cflags here to avoid problems, but the interaction between57# CMake and compiler-rt's tests should be reworked so that cflags don't contain C++ only58# flags.59clang_cflags = [60 flag.replace("-stdlib=libc++", "").replace("-stdlib=libstdc++", "")61 for flag in clang_cflags62]63 64 65def build_invocation(compile_flags, with_lto=False):66 lto_flags = []67 if with_lto and config.lto_supported:68 lto_flags += config.lto_flags69 return " " + " ".join([config.clang] + lto_flags + compile_flags) + " "70 71 72def exclude_unsupported_files_for_aix(dirname):73 for filename in os.listdir(dirname):74 source_path = os.path.join(dirname, filename)75 if os.path.isdir(source_path):76 continue77 f = open(source_path, "r")78 try:79 data = f.read()80 # rpath is not supported on AIX, exclude all tests with them.81 if ( "-rpath" in data ):82 config.excludes += [filename]83 finally:84 f.close()85 86 87# Add clang substitutions.88config.substitutions.append(("%clang ", build_invocation(clang_cflags)))89config.substitutions.append(("%clangxx ", build_invocation(clang_cxxflags)))90 91config.substitutions.append(92 ("%clang_profgen ", build_invocation(clang_cflags) + " -fprofile-instr-generate ")93)94config.substitutions.append(95 ("%clang_profgen=", build_invocation(clang_cflags) + " -fprofile-instr-generate=")96)97config.substitutions.append(98 (99 "%clangxx_profgen ",100 build_invocation(clang_cxxflags) + " -fprofile-instr-generate ",101 )102)103config.substitutions.append(104 (105 "%clangxx_profgen=",106 build_invocation(clang_cxxflags) + " -fprofile-instr-generate=",107 )108)109 110config.substitutions.append(111 ("%clang_pgogen ", build_invocation(clang_cflags) + " -fprofile-generate ")112)113config.substitutions.append(114 ("%clang_pgogen=", build_invocation(clang_cflags) + " -fprofile-generate=")115)116config.substitutions.append(117 ("%clangxx_pgogen ", build_invocation(clang_cxxflags) + " -fprofile-generate ")118)119config.substitutions.append(120 ("%clangxx_pgogen=", build_invocation(clang_cxxflags) + " -fprofile-generate=")121)122 123config.substitutions.append(124 ("%clang_cspgogen ", build_invocation(clang_cflags) + " -fcs-profile-generate ")125)126config.substitutions.append(127 ("%clang_cspgogen=", build_invocation(clang_cflags) + " -fcs-profile-generate=")128)129config.substitutions.append(130 ("%clangxx_cspgogen ", build_invocation(clang_cxxflags) + " -fcs-profile-generate ")131)132config.substitutions.append(133 ("%clangxx_cspgogen=", build_invocation(clang_cxxflags) + " -fcs-profile-generate=")134)135 136config.substitutions.append(137 ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=")138)139config.substitutions.append(140 ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=")141)142 143config.substitutions.append(144 ("%clang_pgouse=", build_invocation(clang_cflags) + " -fprofile-use=")145)146config.substitutions.append(147 ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=")148)149 150config.substitutions.append(151 (152 "%clang_lto_profgen=",153 build_invocation(clang_cflags, True) + " -fprofile-instr-generate=",154 )155)156 157if config.target_os not in [158 "Windows",159 "Darwin",160 "FreeBSD",161 "Linux",162 "NetBSD",163 "SunOS",164 "AIX",165 "Haiku",166]:167 config.unsupported = True168 169config.substitutions.append(170 ("%shared_lib_flag", "-dynamiclib" if (config.target_os == "Darwin") else "-shared")171)172 173if config.target_os in ["AIX"]:174 config.available_features.add("system-aix")175 exclude_unsupported_files_for_aix(config.test_source_root)176 exclude_unsupported_files_for_aix(config.test_source_root + "/Posix")177 178if config.target_arch in ["armv7l"]:179 config.unsupported = True180 181if config.android:182 config.unsupported = True183 184if config.have_curl:185 config.available_features.add("curl")186 187if config.target_os in ("AIX", "Darwin", "Linux"):188 config.available_features.add("continuous-mode")189