1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
import argparse
import os
import platform
import shutil
import subprocess
import sys
from typing import Tuple
from colorama import Fore, Back, Style
from util import *
sys.stdout.reconfigure(encoding='utf-8') # for windows gh runner
def get_c_compiler_counterpart(compiler: str) -> str:
return compiler.replace("clang++", "clang").replace("g++", "gcc")
def build(runner: MatrixRunner):
if platform.system() == "Linux":
matrix = runner.current_config()
if "stdlib" in matrix and matrix["stdlib"] == "libc++":
gtest_path = "/tmp/gtest_install_libcxx"
else:
gtest_path = "/tmp/gtest_install"
args = [
"cmake",
"..",
"-GNinja",
f"-DCMAKE_CXX_COMPILER={matrix['compiler']}",
f"-DCMAKE_C_COMPILER={get_c_compiler_counterpart(matrix['compiler'])}",
f"-DCMAKE_BUILD_TYPE={matrix['build_type']}",
f"-DCPPTRACE_BUILD_SHARED={matrix['shared']}",
"-DCPPTRACE_DISABLE_CXX_20_MODULES=ON",
f"-DHAS_DL_FIND_OBJECT={matrix['has_dl_find_object']}",
"-DCPPTRACE_WERROR_BUILD=On",
"-DCPPTRACE_STD_FORMAT=Off",
"-DCPPTRACE_BUILD_TESTING=On",
f"-DCPPTRACE_SANITIZER_BUILD={matrix['sanitizers']}",
f"-DCPPTRACE_BUILD_NO_SYMBOLS={matrix['no_symbols']}",
f"-DCPPTRACE_BUILD_TESTING_SPLIT_DWARF={matrix['split_dwarf']}",
f"-DCPPTRACE_BUILD_TESTING_DWARF_VERSION={matrix['dwarf_version']}",
f"-DCPPTRACE_USE_EXTERNAL_LIBDWARF=On",
f"-DCPPTRACE_USE_EXTERNAL_ZSTD=On",
f"-DCPPTRACE_USE_EXTERNAL_GTEST=On",
f"-DCMAKE_PREFIX_PATH={gtest_path}",
*(["-DCMAKE_CXX_FLAGS=-stdlib=libc++"] if "stdlib" in matrix and matrix["stdlib"] == "libc++" else [])
]
return runner.run_command(*args) and runner.run_command("ninja")
elif platform.system() == "Darwin":
matrix = runner.current_config()
if "clang++" in matrix["compiler"]:
gtest_path = "/tmp/gtest_asan_install" if matrix['sanitizers'] == "ON" else "/tmp/gtest_install"
else:
gtest_path = "/tmp/gtest_install_gcc"
args = [
"cmake",
"..",
"-GNinja",
f"-DCMAKE_CXX_COMPILER={matrix['compiler']}",
f"-DCMAKE_C_COMPILER={get_c_compiler_counterpart(matrix['compiler'])}",
f"-DCMAKE_BUILD_TYPE={matrix['build_type']}",
f"-DCPPTRACE_BUILD_SHARED={matrix['shared']}",
"-DCPPTRACE_DISABLE_CXX_20_MODULES=ON",
"-DCPPTRACE_WERROR_BUILD=On",
"-DCPPTRACE_STD_FORMAT=Off",
"-DCPPTRACE_BUILD_TESTING=On",
f"-DCPPTRACE_SANITIZER_BUILD={matrix['sanitizers']}",
f"-DCPPTRACE_BUILD_NO_SYMBOLS={matrix['no_symbols']}",
# f"-DCPPTRACE_BUILD_TESTING_SPLIT_DWARF={matrix['split_dwarf']}",
# f"-DCPPTRACE_BUILD_TESTING_SPLIT_DWARF={matrix['dwarf_version']}",
f"-DCPPTRACE_USE_EXTERNAL_LIBDWARF=On",
f"-DCPPTRACE_USE_EXTERNAL_ZSTD=On",
f"-DCPPTRACE_USE_EXTERNAL_GTEST=On",
f"-DCMAKE_PREFIX_PATH={gtest_path}",
]
return runner.run_command(*args) and runner.run_command("ninja")
else:
raise ValueError()
def test(runner: MatrixRunner):
if platform.system() == "Linux":
return runner.run_command("./unittest") and runner.run_command("bash", "-c", "exec -a u ./unittest")
elif platform.system() == "Darwin":
if runner.current_config()["dSYM"]:
if not runner.run_command("dsymutil", "unittest"):
return False
good = runner.run_command("./unittest") and runner.run_command("bash", "-c", "exec -a u ./unittest")
if runner.current_config()["dSYM"]:
shutil.rmtree("unittest.dSYM")
return good
else:
raise ValueError()
def build_and_test(runner: MatrixRunner):
# the build directory has to be purged on compiler or shared change
last = runner.last_config()
current = runner.current_config()
if (
last is None
or last["compiler"] != current["compiler"]
or ("stdlib" in current and last["stdlib"] != current["stdlib"])
or (platform.system() == "Darwin" and last["sanitizers"] != current["sanitizers"])
) and os.path.exists("build"):
shutil.rmtree("build", ignore_errors=True)
if not os.path.exists("build"):
os.mkdir("build")
os.chdir("build")
good = False
if build(runner):
good = test(runner)
os.chdir("..")
print(flush=True)
return good
def run_linux_matrix():
MatrixRunner(
matrix = {
"compiler": ["g++-10", "clang++-18"],
"stdlib": ["libstdc++", "libc++"],
"sanitizers": ["OFF", "ON"],
"build_type": ["Debug", "RelWithDebInfo"],
"shared": ["OFF", "ON"],
"has_dl_find_object": ["OFF", "ON"],
"split_dwarf": ["OFF", "ON"],
"dwarf_version": ["4", "5"],
"no_symbols": ["On", "Off"],
},
exclude = [
{
"compiler": "g++-10",
"stdlib": "libc++",
},
{
# need to workaround https://github.com/llvm/llvm-project/issues/59432 later
"stdlib": "libc++",
"sanitizers": "ON",
},
]
).run(build_and_test)
def run_macos_matrix():
MatrixRunner(
matrix = {
"compiler": ["g++-12", "clang++"],
"sanitizers": ["OFF", "ON"],
"build_type": ["Debug", "RelWithDebInfo"],
"shared": ["OFF", "ON"],
"dSYM": [True, False],
"no_symbols": ["On", "Off"],
},
exclude = [
{
"compiler": "g++-12",
"sanitizers": "ON",
},
]
).run(build_and_test)
def main():
if platform.system() == "Linux":
run_linux_matrix()
if platform.system() == "Darwin":
run_macos_matrix()
if platform.system() == "Windows":
raise ValueError() # run_windows_matrix()
main()
|