ClickHouse/ci/jobs/build_clickhouse.py

144 lines
4.3 KiB
Python
Raw Normal View History

2024-10-24 11:17:00 +00:00
import argparse
2024-10-29 21:09:03 +00:00
from praktika.param import get_param
2024-10-24 11:17:00 +00:00
from praktika.result import Result
from praktika.settings import Settings
from praktika.utils import MetaClasses, Shell, Utils
class JobStages(metaclass=MetaClasses.WithIter):
CHECKOUT_SUBMODULES = "checkout"
CMAKE = "cmake"
BUILD = "build"
def parse_args():
parser = argparse.ArgumentParser(description="ClickHouse Build Job")
2024-10-26 17:35:33 +00:00
parser.add_argument(
2024-10-29 21:09:03 +00:00
"--build-type",
help="Type: <amd|arm>_<debug|release>_<asan|msan|..>",
default=None,
2024-10-26 17:35:33 +00:00
)
parser.add_argument(
"--param",
help="Optional user-defined job start stage (for local run)",
default=None,
)
2024-10-24 11:17:00 +00:00
return parser.parse_args()
2024-10-29 21:09:03 +00:00
CMAKE_CMD = """cmake --debug-trycompile -DCMAKE_VERBOSE_MAKEFILE=1 -LA \
-DCMAKE_BUILD_TYPE={BUILD_TYPE} \
-DSANITIZE={SANITIZER} \
-DENABLE_CHECK_HEAVY_BUILDS=1 -DENABLE_CLICKHOUSE_SELF_EXTRACTING=1 -DENABLE_TESTS=0 \
-DENABLE_UTILS=0 -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LOCALSTATEDIR=/var -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON \
{AUX_DEFS} \
-DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 \
-DCOMPILER_CACHE={CACHE_TYPE} \
-DENABLE_BUILD_PROFILING=1 {DIR}"""
2024-10-24 11:17:00 +00:00
def main():
args = parse_args()
stop_watch = Utils.Stopwatch()
stages = list(JobStages)
stage = args.param or JobStages.CHECKOUT_SUBMODULES
if stage:
assert stage in JobStages, f"--param must be one of [{list(JobStages)}]"
print(f"Job will start from stage [{stage}]")
while stage in stages:
stages.pop(0)
stages.insert(0, stage)
cmake_build_type = "Release"
sanitizer = ""
2024-10-29 21:09:03 +00:00
if args.build_type and get_param():
assert (
False
), "Build type must provided via job parameter (CI case) or via --build-type input argument not both"
2024-10-24 11:17:00 +00:00
2024-10-29 21:09:03 +00:00
build_type = args.build_type or get_param()
assert (
build_type
), "build_type must be provided either as input argument or as a parameter of parametrized job in CI"
build_type = build_type.lower()
2024-10-24 11:17:00 +00:00
# if Environment.is_local_run():
# build_cache_type = "disabled"
# else:
2024-10-29 21:09:03 +00:00
CACHE_TYPE = "sccache"
if "debug" in build_type:
print("Build type set: debug")
BUILD_TYPE = "Debug"
AUX_DEFS = " -DSPLIT_DEBUG_SYMBOLS=ON -DBUILD_STANDALONE_KEEPER=1 "
elif "release" in build_type:
print("Build type set: release")
BUILD_TYPE = "None"
AUX_DEFS = " -DENABLE_TESTS=1 "
if "asan" in build_type:
print("Sanitizer set: address")
SANITIZER = "address"
else:
SANITIZER = ""
cmake_cmd = CMAKE_CMD.format(
BUILD_TYPE=BUILD_TYPE,
CACHE_TYPE=CACHE_TYPE,
SANITIZER=SANITIZER,
AUX_DEFS=AUX_DEFS,
DIR=Utils.cwd(),
)
2024-10-24 11:17:00 +00:00
build_dir = f"{Settings.TEMP_DIR}/build"
res = True
results = []
if res and JobStages.CHECKOUT_SUBMODULES in stages:
Shell.check(f"rm -rf {build_dir} && mkdir -p {build_dir}")
results.append(
Result.create_from_command_execution(
name="Checkout Submodules",
command=f"git submodule sync --recursive && git submodule init && git submodule update --depth 1 --recursive --jobs {min([Utils.cpu_count(), 20])}",
)
)
res = results[-1].is_ok()
if res and JobStages.CMAKE in stages:
results.append(
Result.create_from_command_execution(
name="Cmake configuration",
2024-10-29 21:09:03 +00:00
command=cmake_cmd,
2024-10-24 11:17:00 +00:00
workdir=build_dir,
with_log=True,
)
)
res = results[-1].is_ok()
if res and JobStages.BUILD in stages:
Shell.check("sccache --show-stats")
results.append(
Result.create_from_command_execution(
name="Build ClickHouse",
command="ninja clickhouse-bundle clickhouse-odbc-bridge clickhouse-library-bridge",
workdir=build_dir,
with_log=True,
)
)
Shell.check("sccache --show-stats")
Shell.check(f"ls -l {build_dir}/programs/")
res = results[-1].is_ok()
2024-10-26 17:35:33 +00:00
Result.create_from(results=results, stopwatch=stop_watch).complete_job()
2024-10-24 11:17:00 +00:00
if __name__ == "__main__":
main()