|
| 1 | +import argparse |
| 2 | + |
| 3 | +from praktika.result import Result |
| 4 | +from praktika.settings import Settings |
| 5 | +from praktika.utils import MetaClasses, Shell, Utils |
| 6 | + |
| 7 | + |
| 8 | +class JobStages(metaclass=MetaClasses.WithIter): |
| 9 | + CHECKOUT_SUBMODULES = "checkout" |
| 10 | + CMAKE = "cmake" |
| 11 | + BUILD = "build" |
| 12 | + |
| 13 | + |
| 14 | +def parse_args(): |
| 15 | + parser = argparse.ArgumentParser(description="ClickHouse Build Job") |
| 16 | + parser.add_argument("BUILD_TYPE", help="Type: <amd|arm_debug|release_sanitizer>") |
| 17 | + parser.add_argument("--param", help="Optional custom job start stage", default=None) |
| 18 | + return parser.parse_args() |
| 19 | + |
| 20 | + |
| 21 | +def main(): |
| 22 | + |
| 23 | + args = parse_args() |
| 24 | + |
| 25 | + stop_watch = Utils.Stopwatch() |
| 26 | + |
| 27 | + stages = list(JobStages) |
| 28 | + stage = args.param or JobStages.CHECKOUT_SUBMODULES |
| 29 | + if stage: |
| 30 | + assert stage in JobStages, f"--param must be one of [{list(JobStages)}]" |
| 31 | + print(f"Job will start from stage [{stage}]") |
| 32 | + while stage in stages: |
| 33 | + stages.pop(0) |
| 34 | + stages.insert(0, stage) |
| 35 | + |
| 36 | + cmake_build_type = "Release" |
| 37 | + sanitizer = "" |
| 38 | + |
| 39 | + if "debug" in args.BUILD_TYPE.lower(): |
| 40 | + print("Build type set: debug") |
| 41 | + cmake_build_type = "Debug" |
| 42 | + |
| 43 | + if "asan" in args.BUILD_TYPE.lower(): |
| 44 | + print("Sanitizer set: address") |
| 45 | + sanitizer = "address" |
| 46 | + |
| 47 | + # if Environment.is_local_run(): |
| 48 | + # build_cache_type = "disabled" |
| 49 | + # else: |
| 50 | + build_cache_type = "sccache" |
| 51 | + |
| 52 | + current_directory = Utils.cwd() |
| 53 | + build_dir = f"{Settings.TEMP_DIR}/build" |
| 54 | + |
| 55 | + res = True |
| 56 | + results = [] |
| 57 | + |
| 58 | + if res and JobStages.CHECKOUT_SUBMODULES in stages: |
| 59 | + Shell.check(f"rm -rf {build_dir} && mkdir -p {build_dir}") |
| 60 | + results.append( |
| 61 | + Result.create_from_command_execution( |
| 62 | + name="Checkout Submodules", |
| 63 | + command=f"git submodule sync --recursive && git submodule init && git submodule update --depth 1 --recursive --jobs {min([Utils.cpu_count(), 20])}", |
| 64 | + ) |
| 65 | + ) |
| 66 | + res = results[-1].is_ok() |
| 67 | + |
| 68 | + if res and JobStages.CMAKE in stages: |
| 69 | + results.append( |
| 70 | + Result.create_from_command_execution( |
| 71 | + name="Cmake configuration", |
| 72 | + command=f"cmake --debug-trycompile -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_BUILD_TYPE={cmake_build_type} \ |
| 73 | + -DSANITIZE={sanitizer} -DENABLE_CHECK_HEAVY_BUILDS=1 -DENABLE_CLICKHOUSE_SELF_EXTRACTING=1 -DENABLE_TESTS=0 \ |
| 74 | + -DENABLE_UTILS=0 -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_PREFIX=/usr \ |
| 75 | + -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LOCALSTATEDIR=/var -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON \ |
| 76 | + -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCOMPILER_CACHE={build_cache_type} -DENABLE_TESTS=1 \ |
| 77 | + -DENABLE_BUILD_PROFILING=1 {current_directory}", |
| 78 | + workdir=build_dir, |
| 79 | + with_log=True, |
| 80 | + ) |
| 81 | + ) |
| 82 | + res = results[-1].is_ok() |
| 83 | + |
| 84 | + if res and JobStages.BUILD in stages: |
| 85 | + Shell.check("sccache --show-stats") |
| 86 | + results.append( |
| 87 | + Result.create_from_command_execution( |
| 88 | + name="Build ClickHouse", |
| 89 | + command="ninja clickhouse-bundle clickhouse-odbc-bridge clickhouse-library-bridge", |
| 90 | + workdir=build_dir, |
| 91 | + with_log=True, |
| 92 | + ) |
| 93 | + ) |
| 94 | + Shell.check("sccache --show-stats") |
| 95 | + Shell.check(f"ls -l {build_dir}/programs/") |
| 96 | + res = results[-1].is_ok() |
| 97 | + |
| 98 | + Result.create_from(results=results, stopwatch=stop_watch).finish_job_accordingly() |
| 99 | + |
| 100 | + |
| 101 | +if __name__ == "__main__": |
| 102 | + main() |
0 commit comments