From ba81816dc17b97f73c2b80e31e4f77795f1de2b3 Mon Sep 17 00:00:00 2001 From: alesapin Date: Wed, 20 Apr 2022 12:11:55 +0200 Subject: [PATCH] Better cmake --- CMakeLists.txt | 1 + docker/packager/binary/build.sh | 4 ++-- docker/packager/packager | 1 - .../runner/compose/docker_compose_keeper.yml | 6 +++--- programs/CMakeLists.txt | 8 ++++++-- tests/integration/helpers/cluster.py | 13 +++++++++++-- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f1a6c05730..c0f5e6b0268 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,6 +257,7 @@ endif() option(USE_DEBUG_HELPERS "Enable debug helpers" ${USE_DEBUG_HELPERS}) option(BUILD_STANDALONE_KEEPER "Build keeper as small standalone binary" OFF) +option(CREATE_KEEPER_SYMLINK "Create symlink for clickhouse-keeper to main server binary" ON) # Create BuildID when using lld. For other linkers it is created by default. if (LINKER_NAME MATCHES "lld$") diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index 56a9bd79d44..794904de16a 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -31,7 +31,7 @@ env # build keeper with musl separately if [ "$BUILD_MUSL_KEEPER" == "1" ] then - cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -DUSE_MUSL=1 -LA -DCMAKE_TOOLCHAIN_FILE=/build/cmake/linux/toolchain-x86_64-musl.cmake "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSANITIZE=$SANITIZER" -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. + cmake --debug-trycompile --verbose=1 -DBUILD_STANDALONE_KEEPER=1 -DCMAKE_VERBOSE_MAKEFILE=1 -DUSE_MUSL=1 -LA -DCMAKE_TOOLCHAIN_FILE=/build/cmake/linux/toolchain-x86_64-musl.cmake "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSANITIZE=$SANITIZER" -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. ninja $NINJA_FLAGS clickhouse-keeper @@ -49,7 +49,7 @@ fi rm -f CMakeCache.txt if [ "$BUILD_MUSL_KEEPER" == "1" ]; then - cmake --debug-trycompile --verbose=1 -DENABLE_CLICKHOUSE_KEEPER=0 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSANITIZE=$SANITIZER" -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. + cmake --debug-trycompile --verbose=1 -DBUILD_STANDALONE_KEEPER=0 -DCREATE_KEEPER_SYMLINK=0 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSANITIZE=$SANITIZER" -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. else cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" "-DSANITIZE=$SANITIZER" -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. fi diff --git a/docker/packager/packager b/docker/packager/packager index ee32a163c3b..51df261e988 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -163,7 +163,6 @@ def parse_env_variables( cmake_flags.append("-DCMAKE_INSTALL_PREFIX=/usr") cmake_flags.append("-DCMAKE_INSTALL_SYSCONFDIR=/etc") cmake_flags.append("-DCMAKE_INSTALL_LOCALSTATEDIR=/var") - cmake_flags.append("-DBUILD_STANDALONE_KEEPER=ON") if is_release_build(build_type, package_type, sanitizer, split_binary): cmake_flags.append("-DINSTALL_STRIPPED_BINARIES=ON") if not is_cross_arm: diff --git a/docker/test/integration/runner/compose/docker_compose_keeper.yml b/docker/test/integration/runner/compose/docker_compose_keeper.yml index 134ffbff1f7..a729a9c7734 100644 --- a/docker/test/integration/runner/compose/docker_compose_keeper.yml +++ b/docker/test/integration/runner/compose/docker_compose_keeper.yml @@ -17,7 +17,7 @@ services: - type: ${keeper_fs:-tmpfs} source: ${keeper_db_dir1:-} target: /var/lib/clickhouse-keeper - entrypoint: "clickhouse keeper --config=/etc/clickhouse-keeper/keeper_config1.xml --log-file=/var/log/clickhouse-keeper/clickhouse-keeper.log --errorlog-file=/var/log/clickhouse-keeper/clickhouse-keeper.err.log" + entrypoint: "${keeper_cmd_prefix:-} --config=/etc/clickhouse-keeper/keeper_config1.xml --log-file=/var/log/clickhouse-keeper/clickhouse-keeper.log --errorlog-file=/var/log/clickhouse-keeper/clickhouse-keeper.err.log" cap_add: - SYS_PTRACE - NET_ADMIN @@ -47,7 +47,7 @@ services: - type: ${keeper_fs:-tmpfs} source: ${keeper_db_dir2:-} target: /var/lib/clickhouse-keeper - entrypoint: "clickhouse keeper --config=/etc/clickhouse-keeper/keeper_config2.xml --log-file=/var/log/clickhouse-keeper/clickhouse-keeper.log --errorlog-file=/var/log/clickhouse-keeper/clickhouse-keeper.err.log" + entrypoint: "${keeper_cmd_prefix:-} --config=/etc/clickhouse-keeper/keeper_config2.xml --log-file=/var/log/clickhouse-keeper/clickhouse-keeper.log --errorlog-file=/var/log/clickhouse-keeper/clickhouse-keeper.err.log" cap_add: - SYS_PTRACE - NET_ADMIN @@ -77,7 +77,7 @@ services: - type: ${keeper_fs:-tmpfs} source: ${keeper_db_dir3:-} target: /var/lib/clickhouse-keeper - entrypoint: "clickhouse keeper --config=/etc/clickhouse-keeper/keeper_config3.xml --log-file=/var/log/clickhouse-keeper/clickhouse-keeper.log --errorlog-file=/var/log/clickhouse-keeper/clickhouse-keeper.err.log" + entrypoint: "${keeper_cmd_prefix:-} --config=/etc/clickhouse-keeper/keeper_config3.xml --log-file=/var/log/clickhouse-keeper/clickhouse-keeper.log --errorlog-file=/var/log/clickhouse-keeper/clickhouse-keeper.err.log" cap_add: - SYS_PTRACE - NET_ADMIN diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index b57d38969bb..d952fd2a5dd 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -448,13 +448,17 @@ else () install (FILES "${CMAKE_CURRENT_BINARY_DIR}/clickhouse-static-files-disk-uploader" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse) list(APPEND CLICKHOUSE_BUNDLE clickhouse-static-files-disk-uploader) endif () + if (ENABLE_CLICKHOUSE_KEEPER) - if (NOT BUILD_STANDALONE_KEEPER) + if (NOT BUILD_STANDALONE_KEEPER AND CREATE_KEEPER_SYMLINK) add_custom_target (clickhouse-keeper ALL COMMAND ${CMAKE_COMMAND} -E create_symlink clickhouse clickhouse-keeper DEPENDS clickhouse) install (FILES "${CMAKE_CURRENT_BINARY_DIR}/clickhouse-keeper" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse) endif() - list(APPEND CLICKHOUSE_BUNDLE clickhouse-keeper) + # otherwise we don't build keeper + if (BUILD_STANDALONE_KEEPER OR CREATE_KEEPER_SYMLINK) + list(APPEND CLICKHOUSE_BUNDLE clickhouse-keeper) + endif() endif () if (ENABLE_CLICKHOUSE_KEEPER_CONVERTER) add_custom_target (clickhouse-keeper-converter ALL COMMAND ${CMAKE_COMMAND} -E create_symlink clickhouse clickhouse-keeper-converter DEPENDS clickhouse) diff --git a/tests/integration/helpers/cluster.py b/tests/integration/helpers/cluster.py index 78274e0232e..16691bef084 100644 --- a/tests/integration/helpers/cluster.py +++ b/tests/integration/helpers/cluster.py @@ -694,10 +694,19 @@ class ClickHouseCluster: ) binary_path = self.server_bin_path - if binary_path.endswith("-server"): - binary_path = binary_path[: -len("-server")] + binary_dir = os.path.dirname(self.server_bin_path) + + # always prefer clickhouse-keeper standalone binary + if os.path.exists(os.path.join(binary_dir, "clickhouse-keeper")): + binary_path = os.path.join(binary_dir, "clickhouse-keeper") + keeper_cmd_prefix = "clickhouse-keeper" + else: + if binary_path.endswith("-server"): + binary_path = binary_path[: -len("-server")] + keeper_cmd_prefix = "clickhouse keeper" env_variables["keeper_binary"] = binary_path + env_variables["keeper_cmd_prefix"] = keeper_cmd_prefix env_variables["image"] = "clickhouse/integration-test:" + self.docker_base_tag env_variables["user"] = str(os.getuid()) env_variables["keeper_fs"] = "bind"