Skip to content

Commit

Permalink
[cmake] clean up on targets when using NO_TESTS=1
Browse files Browse the repository at this point in the history
This patch updates makefiles to remove unnecessary targets when
the build is configured using 'cmake -DNO_TESTS=1 ...'.  It reduces
CPU and disk consumption when building with NO_TESTS=1.

Also, the sanitizer_options static library is now built only in
ASAN/TSAN configurations.

This patch doesn't add any functional changes in the Kudu's code itself,
except that the kudu CLI tool no longer offer the 'kudu test' action
when built with NO_TESTS=1.  That also made the size of the kudu CLI
binary a bit smaller.  If comparing the sizes of the stripped binaries,
I got the following numbers when building on CentOS7.9 with NO_TESTS=1
in RELEASE configuration using devtoolset-8:

  before: 67883424 bytes
  after:  66891680 bytes

Change-Id: I6de4f9498bef9b2102ea6507a35ad78b08d4c27a
Reviewed-on: http://gerrit.cloudera.org:8080/20281
Tested-by: Kudu Jenkins
Reviewed-by: Yifan Zhang <chinazhangyifan@163.com>
Reviewed-by: Yingchun Lai <laiyingchun@apache.org>
(cherry picked from commit 7f9b74f)
Reviewed-on: http://gerrit.cloudera.org:8080/20283
Tested-by: Yingchun Lai <laiyingchun@apache.org>
  • Loading branch information
alexeyserbin authored and acelyc111 committed Aug 1, 2023
1 parent 54ab225 commit 1767397
Show file tree
Hide file tree
Showing 28 changed files with 380 additions and 263 deletions.
21 changes: 16 additions & 5 deletions CMakeLists.txt
Expand Up @@ -234,6 +234,13 @@ add_definitions(-DKUDU_HEADERS_USE_RICH_SLICE=1)
# exported client headers).
add_definitions(-DKUDU_HEADERS_NO_STUBS=1)

# If not building tests, add an extra macro to allow for omitting test-related
# provisions and functionality from the kudu CLI tool: that's based on the
# mini-cluster library, and the mini-cluster library is built only for testing.
if(NO_TESTS)
add_definitions(-DKUDU_CLI_TOOL_NO_TESTS)
endif()

# compiler flags for different build types (run 'cmake -DCMAKE_BUILD_TYPE=<type> .')
# For all builds:
# For CMAKE_BUILD_TYPE=Debug
Expand Down Expand Up @@ -1209,14 +1216,18 @@ if (NOT NO_TESTS)
find_package(KerberosPrograms)
endif()

# The tests as well as any binaries which are run as subprocesses by tests (eg tserver,
# master, and the 'kudu' CLI tool) need to link these in. We have to set them
# here so they are accessible by all targets.
# The tests as well as any binaries which are run as subprocesses by tests
# (e.g. tserver, master, and the 'kudu' CLI tool) need to link these in.
# We have to set them here so they are accessible by all targets.
if (NOT APPLE)
set(SANITIZER_OPTIONS_OVERRIDE -Wl,-u_sanitizer_options_link_helper sanitizer_options)
if ("${KUDU_USE_ASAN}" OR "${KUDU_USE_TSAN}" OR "${KUDU_USE_UBSAN}")
set(SANITIZER_OPTIONS_OVERRIDE -Wl,-u_sanitizer_options_link_helper sanitizer_options)
endif()
set(KRB5_REALM_OVERRIDE -Wl,--undefined=krb5_realm_override_loaded krb5_realm_override)
else()
set(SANITIZER_OPTIONS_OVERRIDE -Wl,-U,_sanitizer_options_link_helper sanitizer_options)
if ("${KUDU_USE_ASAN}" OR "${KUDU_USE_TSAN}" OR "${KUDU_USE_UBSAN}")
set(SANITIZER_OPTIONS_OVERRIDE -Wl,-U,_sanitizer_options_link_helper sanitizer_options)
endif()
set(KRB5_REALM_OVERRIDE -Wl,-U,krb5_realm_override_loaded krb5_realm_override)
endif()

Expand Down
5 changes: 4 additions & 1 deletion src/kudu/benchmarks/CMakeLists.txt
Expand Up @@ -55,6 +55,9 @@ if(NOT APPLE)
kudu_util)
endif()

# Tests
#######################################
# Unit tests
#######################################

SET_KUDU_TEST_LINK_LIBS(tpch)
ADD_KUDU_TEST(tpch/rpc_line_item_dao-test)
18 changes: 12 additions & 6 deletions src/kudu/cfile/CMakeLists.txt
Expand Up @@ -57,19 +57,25 @@ set(CFILE_LIBS

target_link_libraries(cfile ${CFILE_LIBS})

add_library(cfile_test_util
bloomfile-test-base.cc)
if(NOT NO_TESTS)
add_library(cfile_test_util
bloomfile-test-base.cc)

target_link_libraries(cfile_test_util
cfile
kudu_test_util)
target_link_libraries(cfile_test_util
cfile
kudu_test_util)
endif()

#######################################
# Unit tests
#######################################

# Tests
SET_KUDU_TEST_LINK_LIBS(cfile)
ADD_KUDU_TEST(index-test)
ADD_KUDU_TEST(cfile-test NUM_SHARDS 4)
ADD_KUDU_TEST(encoding-test LABELS no_tsan)
ADD_KUDU_TEST(block_cache-test)

SET_KUDU_TEST_LINK_LIBS(cfile cfile_test_util)
ADD_KUDU_TEST(bloomfile-test)
ADD_KUDU_TEST(mt-bloomfile-test RUN_SERIAL true)
27 changes: 16 additions & 11 deletions src/kudu/client/CMakeLists.txt
Expand Up @@ -244,19 +244,24 @@ install(FILES
# script to forcefully change the kudu_client_exported target to kudu_client.
install(SCRIPT MungeExportedInstallTargets.cmake)

#######################################
# Test utility library
#######################################
if(NOT NO_TESTS)
# This code is useful for other tests which use the client, but isn't
# part of the client itself (ie we don't want to ship it to customers,
# and therefore don't need to worry about export strictness)
add_library(kudu_client_test_util
client-test-util.cc)
target_link_libraries(kudu_client_test_util
gmock
gtest
kudu_client)
endif()

# This code is useful for other tests which use the client, but isn't
# part of the client itself (ie we don't want to ship it to customers,
# and therefore don't need to worry about export strictness)
add_library(kudu_client_test_util
client-test-util.cc)
target_link_libraries(kudu_client_test_util
gmock
gtest
kudu_client)

# Tests
#######################################
# Unit tests
#######################################

# The OS X system compiler does not support source symbol maps, so the client
# leaks internal symbols globally.
Expand Down
6 changes: 6 additions & 0 deletions src/kudu/clock/CMakeLists.txt
Expand Up @@ -41,6 +41,12 @@ target_link_libraries(clock
# mini_chronyd
##############################

# The mini_chronyd is used only for tests, and corresponding tests for this
# module below are skipped if NO_TEST=1.
if(NO_TESTS)
return()
endif()

if (NOT NO_CHRONY)
# Link the chrony binaries so that they can be found via
# MiniChronyd::GetPath in MiniChronyd::Start.
Expand Down
4 changes: 4 additions & 0 deletions src/kudu/common/CMakeLists.txt
Expand Up @@ -94,6 +94,10 @@ ADD_EXPORTABLE_LIBRARY(kudu_common
SRCS ${COMMON_SRCS}
DEPS ${COMMON_LIBS})

#######################################
# Unit tests
#######################################

SET_KUDU_TEST_LINK_LIBS(kudu_common)
ADD_KUDU_TEST(columnar_serialization-test)
ADD_KUDU_TEST(columnblock-test)
Expand Down
4 changes: 4 additions & 0 deletions src/kudu/consensus/CMakeLists.txt
Expand Up @@ -117,6 +117,10 @@ target_link_libraries(consensus
log
protobuf)

#######################################
# Unit tests
#######################################

SET_KUDU_TEST_LINK_LIBS(
log
consensus
Expand Down
23 changes: 14 additions & 9 deletions src/kudu/fs/CMakeLists.txt
Expand Up @@ -45,16 +45,21 @@ target_link_libraries(kudu_fs
gutil
ranger_kms_client)

add_library(kudu_fs_test_util
log_block_manager-test-util.cc)
if(NOT NO_TESTS)
add_library(kudu_fs_test_util
log_block_manager-test-util.cc)

target_link_libraries(kudu_fs_test_util
fs_proto
kudu_fs
kudu_util
gutil)
target_link_libraries(kudu_fs_test_util
fs_proto
kudu_fs
kudu_util
gutil)
endif()

#######################################
# Unit tests
#######################################

# Tests
SET_KUDU_TEST_LINK_LIBS(kudu_fs kudu_fs_test_util)
ADD_KUDU_TEST(block_manager-test)
ADD_KUDU_TEST(block_manager-stress-test RUN_SERIAL true)
Expand All @@ -64,6 +69,6 @@ ADD_KUDU_TEST(dir_util-test)
ADD_KUDU_TEST(error_manager-test)
ADD_KUDU_TEST(fs_manager-test)
if (NOT APPLE)
# Will only pass on Linux.
# The log block manager is available only on Linux.
ADD_KUDU_TEST(log_block_manager-test)
endif()
10 changes: 7 additions & 3 deletions src/kudu/gutil/CMakeLists.txt
Expand Up @@ -72,10 +72,14 @@ ADD_EXPORTABLE_LIBRARY(gutil
# Disable warnings which trigger a lot in the Google code:
COMPILE_FLAGS "-funsigned-char -Wno-char-subscripts")

add_kudu_test(strings/string_util-test)
add_kudu_test(strings/numbers-test)
#######################################
# Unit tests
#######################################

ADD_KUDU_TEST(strings/string_util-test)
ADD_KUDU_TEST(strings/numbers-test)
if (NOT APPLE)
# The sysinfo-test consists of scenarios for Linux-specific function
# ParseMaxCpuIndex(): that doesn't exist on macOS.
add_kudu_test(sysinfo-test)
ADD_KUDU_TEST(sysinfo-test)
endif()
43 changes: 22 additions & 21 deletions src/kudu/hms/CMakeLists.txt
Expand Up @@ -74,28 +74,29 @@ add_custom_command(OUTPUT ${HMS_PLUGIN_JAR}
DEPENDS proto_jar)
add_custom_target(hms_plugin_jar DEPENDS ${HMS_PLUGIN_JAR})

set(MINI_HMS_SRCS
mini_hms.cc)
if (NOT NO_TESTS)
# The mini_hms library is used only for tests.
set(MINI_HMS_SRCS
mini_hms.cc)

add_library(mini_hms ${MINI_HMS_SRCS})
target_link_libraries(mini_hms
gutil
krpc
kudu_test_util
kudu_util)
add_dependencies(mini_hms hms_plugin_jar)
add_library(mini_hms ${MINI_HMS_SRCS})
target_link_libraries(mini_hms
gutil
krpc
kudu_test_util
kudu_util)
add_dependencies(mini_hms hms_plugin_jar)
endif()

##############################
# hms tests
##############################
#########################################
# Unit tests
#########################################

if (NOT NO_TESTS)
SET_KUDU_TEST_LINK_LIBS(
kudu_hms
mini_hms
mini_kdc)
SET_KUDU_TEST_LINK_LIBS(
kudu_hms
mini_hms
mini_kdc)

# These tests must run serially, otherwise starting the HMS can take a very long time.
ADD_KUDU_TEST(hms_catalog-test RUN_SERIAL true NUM_SHARDS 4)
ADD_KUDU_TEST(hms_client-test RUN_SERIAL true NUM_SHARDS 4)
endif()
# These tests must run serially, otherwise starting the HMS can take a very long time.
ADD_KUDU_TEST(hms_catalog-test RUN_SERIAL true NUM_SHARDS 4)
ADD_KUDU_TEST(hms_client-test RUN_SERIAL true NUM_SHARDS 4)
46 changes: 26 additions & 20 deletions src/kudu/master/CMakeLists.txt
Expand Up @@ -61,7 +61,6 @@ set(MASTER_SRCS
master_path_handlers.cc
master_runner.cc
master_service.cc
mini_master.cc
placement_policy.cc
ranger_authz_provider.cc
sys_catalog.cc
Expand All @@ -73,6 +72,10 @@ set(MASTER_SRCS
txn_manager.cc
txn_manager_service.cc)

if(NOT NO_TESTS)
set(MASTER_SRCS ${MASTER_SRCS} mini_master.cc)
endif()

add_library(master ${MASTER_SRCS})
target_link_libraries(master
clock
Expand All @@ -96,7 +99,28 @@ target_link_libraries(master
transactions
tserver)

# Tests
#########################################
# kudu-master
#########################################

add_executable(kudu-master master_main.cc)
target_link_libraries(kudu-master
${SANITIZER_OPTIONS_OVERRIDE}
${KRB5_REALM_OVERRIDE}
master
${KUDU_BASE_LIBS})

option(KUDU_MASTER_INSTALL "Whether to install the Kudu Master executable" ON)
if(KUDU_MASTER_INSTALL)
install(TARGETS kudu-master RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
else()
message(STATUS "Skipping install rule for the Kudu Master executable")
endif()

#######################################
# Unit tests
#######################################

SET_KUDU_TEST_LINK_LIBS(
kudu_client
kudu_curl_util
Expand All @@ -122,21 +146,3 @@ ADD_KUDU_TEST(sys_catalog-test RESOURCE_LOCK "master-web-port")
ADD_KUDU_TEST(ts_descriptor-test DATA_FILES ../scripts/first_argument.sh)
ADD_KUDU_TEST(ts_state-test)
ADD_KUDU_TEST(txn_manager-test RESOURCE_LOCK "master-web-port")

#########################################
# kudu-master
#########################################

add_executable(kudu-master master_main.cc)
target_link_libraries(kudu-master
${SANITIZER_OPTIONS_OVERRIDE}
${KRB5_REALM_OVERRIDE}
master
${KUDU_BASE_LIBS})

option(KUDU_MASTER_INSTALL "Whether to install the Kudu Master executable" ON)
if(KUDU_MASTER_INSTALL)
install(TARGETS kudu-master RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
else()
message(STATUS "Skipping install rule for the Kudu Master executable")
endif()
12 changes: 10 additions & 2 deletions src/kudu/mini-cluster/CMakeLists.txt
Expand Up @@ -15,6 +15,11 @@
# specific language governing permissions and limitations
# under the License.

# The mini-cluster is used only for testing.
if(NO_TESTS)
return()
endif()

set(MINI_CLUSTER_SRCS
external_mini_cluster.cc
internal_mini_cluster.cc
Expand Down Expand Up @@ -47,7 +52,7 @@ set(MINI_CLUSTER_LIBS
tserver_service_proto
wire_protocol_proto)

if (NOT NO_CHRONY)
if(NOT NO_CHRONY)
set(MINI_CLUSTER_LIBS ${MINI_CLUSTER_LIBS} mini_chronyd)
endif()

Expand All @@ -57,6 +62,9 @@ add_dependencies(mini_cluster
kudu-tserver
kudu-master)

# Tests
#######################################
# Unit tests
#######################################

SET_KUDU_TEST_LINK_LIBS(mini_cluster kudu_hms)
ADD_KUDU_TEST(external_mini_cluster-test PROCESSORS 3)
8 changes: 7 additions & 1 deletion src/kudu/postgres/CMakeLists.txt
Expand Up @@ -15,6 +15,12 @@
# specific language governing permissions and limitations
# under the License.

# The mini_postgres is used only for tests, and its tests are disabled
# if NO_TESTS=1 is set.
if(NO_TESTS)
return()
endif()

#######################################
# mini_postgres
#######################################
Expand All @@ -41,7 +47,7 @@ target_link_libraries(mini_postgres
)

#######################################
# unit tests
# Unit tests
#######################################

SET_KUDU_TEST_LINK_LIBS(mini_postgres)
Expand Down

0 comments on commit 1767397

Please sign in to comment.