xref: /llvm-project/compiler-rt/test/xray/lit.cfg.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
1# -*- Python -*-
2
3import os
4
5# Setup config name.
6config.name = "XRay" + config.name_suffix
7
8# Setup source root.
9config.test_source_root = os.path.dirname(__file__)
10
11# Setup default compiler flags use with -fxray-instrument option.
12clang_xray_cflags = ["-fxray-instrument", config.target_cflags]
13
14# If libc++ was used to build XRAY libraries, libc++ is needed. Fix applied
15# to Linux only since -rpath may not be portable. This can be extended to
16# other platforms.
17if config.libcxx_used == "1" and config.host_os == "Linux":
18    clang_xray_cflags = clang_xray_cflags + (
19        ["-L%s -lc++ -Wl,-rpath=%s" % (config.llvm_shlib_dir, config.llvm_shlib_dir)]
20    )
21
22clang_xray_cxxflags = config.cxx_mode_flags + clang_xray_cflags
23
24
25def build_invocation(compile_flags):
26    return " " + " ".join([config.clang] + compile_flags) + " "
27
28
29# Assume that llvm-xray is in the config.llvm_tools_dir.
30llvm_xray = os.path.join(config.llvm_tools_dir, "llvm-xray")
31
32# Setup substitutions.
33if config.host_os == "Linux":
34    libdl_flag = "-ldl"
35else:
36    libdl_flag = ""
37
38config.substitutions.append(("%clang ", build_invocation([config.target_cflags])))
39config.substitutions.append(
40    ("%clangxx ", build_invocation(config.cxx_mode_flags + [config.target_cflags]))
41)
42config.substitutions.append(("%clang_xray ", build_invocation(clang_xray_cflags)))
43config.substitutions.append(("%clangxx_xray", build_invocation(clang_xray_cxxflags)))
44config.substitutions.append(("%llvm_xray", llvm_xray))
45config.substitutions.append(
46    (
47        "%xraylib",
48        (
49            "-lm -lpthread %s -lrt -L%s "
50            "-Wl,-whole-archive -lclang_rt.xray%s -Wl,-no-whole-archive"
51        )
52        % (libdl_flag, config.compiler_rt_libdir, config.target_suffix),
53    )
54)
55
56# Default test suffixes.
57config.suffixes = [".c", ".cpp"]
58
59if config.host_os not in ["FreeBSD", "Linux", "NetBSD", "OpenBSD"]:
60    config.unsupported = True
61elif "64" not in config.host_arch:
62    if "arm" in config.host_arch:
63        if "-mthumb" in config.target_cflags:
64            config.unsupported = True
65    else:
66        config.unsupported = True
67
68if config.host_os == "NetBSD":
69    config.substitutions.insert(0, ("%run", config.netbsd_nomprotect_prefix))
70