From 1d362796df62794dbd120a939ad9a8268b4cacee Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 16 Mar 2022 12:53:15 +0100 Subject: [PATCH] Fix strip bug --- cmake/strip.sh | 11 ++++------- programs/CMakeLists.txt | 12 ++++++++---- programs/library-bridge/CMakeLists.txt | 4 +--- programs/odbc-bridge/CMakeLists.txt | 4 +--- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cmake/strip.sh b/cmake/strip.sh index de596887159..0b9ee667ba0 100755 --- a/cmake/strip.sh +++ b/cmake/strip.sh @@ -1,15 +1,14 @@ #!/usr/bin/env bash BINARY_PATH=$1 -BINARY_NAME=$(basename $BINARY_PATH) +BINARY_NAME=$(basename "$BINARY_PATH") DESTINATION_STRIPPED_DIR=$2 OBJCOPY_PATH=${3:objcopy} READELF_PATH=${4:readelf} -BUILD_ID=$($READELF_PATH -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }') +BUILD_ID=$($READELF_PATH -n "$1" | sed -n '/Build ID/ { s/.*: //p; q; }') BUILD_ID_PREFIX=${BUILD_ID:0:2} BUILD_ID_SUFFIX=${BUILD_ID:2} -TEMP_BINARY_PATH="${BINARY_PATH}_temp" DESTINATION_DEBUG_INFO_DIR="$DESTINATION_STRIPPED_DIR/lib/debug/.build-id" DESTINATION_STRIP_BINARY_DIR="$DESTINATION_STRIPPED_DIR/bin" @@ -19,7 +18,5 @@ mkdir -p "$DESTINATION_STRIP_BINARY_DIR" $OBJCOPY_PATH --only-keep-debug "$BINARY_PATH" "$DESTINATION_DEBUG_INFO_DIR/$BUILD_ID_PREFIX/$BUILD_ID_SUFFIX.debug" -touch "$TEMP_BINARY_PATH" -$OBJCOPY_PATH --add-gnu-debuglink "$DESTINATION_DEBUG_INFO_DIR/$BUILD_ID_PREFIX/$BUILD_ID_SUFFIX.debug" "$BINARY_PATH" "$TEMP_BINARY_PATH" -$OBJCOPY_PATH --strip-all "$TEMP_BINARY_PATH" "$DESTINATION_STRIP_BINARY_DIR/$BINARY_NAME" -rm -f "$TEMP_BINARY_PATH" +$OBJCOPY_PATH --strip-debug "$BINARY_PATH" "$DESTINATION_STRIP_BINARY_DIR/$BINARY_NAME" +$OBJCOPY_PATH --add-gnu-debuglink "$DESTINATION_DEBUG_INFO_DIR/$BUILD_ID_PREFIX/$BUILD_ID_SUFFIX.debug" "$DESTINATION_STRIP_BINARY_DIR/$BINARY_NAME" diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 059857b1bb1..1e2420021b6 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -460,10 +460,6 @@ else () list(APPEND CLICKHOUSE_BUNDLE clickhouse-keeper-converter) endif () - if (NOT INSTALL_STRIPPED_BINARIES) - install (TARGETS clickhouse RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse) - endif() - add_custom_target (clickhouse-bundle ALL DEPENDS ${CLICKHOUSE_BUNDLE}) if (USE_GDB_ADD_INDEX) @@ -476,9 +472,17 @@ else () if (INSTALL_STRIPPED_BINARIES) clickhouse_strip_binary(TARGET clickhouse DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR}/${STRIPPED_BINARIES_OUTPUT} BINARY_PATH clickhouse) + else() + install (TARGETS clickhouse RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse) endif() endif() +if (NOT INSTALL_STRIPPED_BINARIES) + # Install dunny debug directory + # TODO: move logic to every place where clickhouse_strip_binary is used + add_custom_command(TARGET clickhouse POST_BUILD COMMAND echo > .empty ) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/.empty" DESTINATION ${CMAKE_INSTALL_LIBDIR}/debug/.empty) +endif() if (ENABLE_TESTS) diff --git a/programs/library-bridge/CMakeLists.txt b/programs/library-bridge/CMakeLists.txt index dd95433854f..aded9664b35 100644 --- a/programs/library-bridge/CMakeLists.txt +++ b/programs/library-bridge/CMakeLists.txt @@ -26,8 +26,6 @@ set_target_properties(clickhouse-library-bridge PROPERTIES RUNTIME_OUTPUT_DIRECT if (INSTALL_STRIPPED_BINARIES) clickhouse_strip_binary(TARGET clickhouse-library-bridge DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR}/../${STRIPPED_BINARIES_OUTPUT} BINARY_PATH ../clickhouse-library-bridge) -endif() - -if (NOT INSTALL_STRIPPED_BINARIES) +else() install(TARGETS clickhouse-library-bridge RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse) endif() diff --git a/programs/odbc-bridge/CMakeLists.txt b/programs/odbc-bridge/CMakeLists.txt index 2d123757dd8..50a8bb629c8 100644 --- a/programs/odbc-bridge/CMakeLists.txt +++ b/programs/odbc-bridge/CMakeLists.txt @@ -41,9 +41,7 @@ endif() if (INSTALL_STRIPPED_BINARIES) clickhouse_strip_binary(TARGET clickhouse-odbc-bridge DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR}/../${STRIPPED_BINARIES_OUTPUT} BINARY_PATH ../clickhouse-odbc-bridge) -endif() - -if (NOT INSTALL_STRIPPED_BINARIES) +else() install(TARGETS clickhouse-odbc-bridge RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT clickhouse) endif()