blob: e2de6cc4a659a778c5b8e91d73b0e6c6897eeaed [file] [log] [blame]
Stefanff693f72022-01-10 15:08:50 +01001import os
2import sys
3
4_os = sys.argv[1]
5assert _os in ["Linux", "macOS", "Windows"]
6
7_arch = sys.argv[2]
8assert _arch in ["x86", "x64"]
9
10_compiler = sys.argv[3]
11assert _compiler in ["cl", "clang-cl", "clang", "gcc", "xcode"]
12
13_version = sys.argv[4] if len(sys.argv) >= 5 else ""
14
15print("Env: " + "; ".join([_os, _arch, _compiler, _version]))
16
17if _compiler == "gcc":
18 used_cxx = "g++"
19elif _compiler == "clang" or _compiler == "xcode":
20 used_cxx = "clang++"
21else:
22 used_cxx = _compiler
23
24if _os == "Linux":
25 used_cxx += "-" + _version
26
27
28def log_and_call(command):
29 print(command)
30 return os.system(command)
31
32
33def run_test(build_type, test_mode, flags, test = True):
34 print("Running: " + "; ".join([build_type, test_mode, flags, str(test)]))
35 if log_and_call("cmake -E remove_directory build"):
36 exit(1)
37 if log_and_call(
38 f"cmake -S . "
39 f"-B build "
40 f"-D CMAKE_BUILD_TYPE={build_type} "
41 f"-D DOCTEST_TEST_MODE={test_mode} "
42 + (flags and f'-D CMAKE_CXX_FLAGS="{flags}" ') +
43 f"-D CMAKE_CXX_COMPILER={used_cxx}"
44 ):
45 exit(2)
46 if log_and_call("cmake --build build"):
47 exit(3)
48 if test and log_and_call("ctest --test-dir build --no-tests=error"):
49 exit(4)
50
51
52def version_tuple(v):
53 return tuple(map(int, (v.split("."))))
54
55
56flags = "-fsanitize=address,undefined -fno-omit-frame-pointer"
57if _os == "Windows":
58 flags = ""
59elif _os == "Linux":
60 if _compiler == "clang":
61 if version_tuple(_version) <= version_tuple("6.0"):
62 flags = ""
63 elif _compiler == "gcc":
64 if version_tuple(_version) <= version_tuple("5.0"):
65 flags = ""
66
67if _os == "Linux" and _compiler == "gcc":
68 flags += " -static-libasan"
69
70tsan_flags = "-fsanitize=thread -pie -fPIE"
71if _os == "Windows":
72 tsan_flags = ""
73elif _os == "Linux":
74 if _compiler == "clang":
75 if version_tuple(_version) <= version_tuple("3.9"):
76 tsan_flags = ""
77 elif _compiler == "gcc":
78 if version_tuple(_version) <= version_tuple("6.0"):
79 tsan_flags = ""
80
81if _os == "Linux" and _compiler == "gcc":
82 tsan_flags += " -static-libtsan"
83
84x86_flag = " -m32" if _arch == "x86" and _compiler != "cl" else ""
85
86for configuration in ["Debug", "Release"]:
87 run_test(configuration, "COMPARE", flags + x86_flag)
88 if tsan_flags != "":
89 run_test(configuration, "COMPARE", tsan_flags)
90 if _os != "Windows":
91 run_test(
92 configuration,
93 "COMPARE",
94 "-fno-exceptions -D DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS",
95 test = False,
96 )
97 run_test(configuration, "COMPARE", "-fno-rtti")
98 if _os == "Linux":
99 run_test(configuration, "VALGRIND", x86_flag)