From d4cfd9a059da6f3c0214a04b1b26e8cdce720812 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Tue, 14 Feb 2023 12:22:57 -0600 Subject: [PATCH 1/3] update cmake for rpc and swoc --- CMakeLists.txt | 17 +++- cmake/subproject_version.cmake | 20 ++++ include/tscore/ink_config.h.cmake.in | 2 +- iocore/eventsystem/CMakeLists.txt | 1 + lib/CMakeLists.txt | 3 + lib/swoc/CMakeLists.txt | 132 +++++++++++++++++++++++++++ mgmt/config/CMakeLists.txt | 32 +++++++ mgmt/config/Makefile.am | 2 +- mgmt/rpc/CMakeLists.txt | 54 +++++++++++ src/records/CMakeLists.txt | 6 ++ src/traffic_server/CMakeLists.txt | 7 +- src/tscpp/util/CMakeLists.txt | 3 +- 12 files changed, 272 insertions(+), 7 deletions(-) create mode 100644 cmake/subproject_version.cmake create mode 100644 lib/swoc/CMakeLists.txt create mode 100644 mgmt/config/CMakeLists.txt create mode 100644 mgmt/rpc/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 86abec54b24..0f9fd05c82b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,9 +108,6 @@ include(CTest) message("Configuring for ${HOST_OS}") -configure_file(include/tscore/ink_config.h.cmake.in include/tscore/ink_config.h) -configure_file(include/ts/apidefs.h.in include/ts/apidefs.h) - add_compile_definitions(${HOST_OS} PACKAGE_NAME="ats" PACKAGE_VERSION="${TS_VERSION_STRING}") add_compile_options(-Wno-invalid-offsetof) @@ -125,10 +122,24 @@ if (OPENSSL_FOUND) endif(OPENSSL_FOUND) add_subdirectory(lib) +include_directories( + ${CMAKE_SOURCE_DIR}/lib/swoc/include + ${YAML_CPP_SOURCE_DIR}/include +) + +include(subproject_version) + +subproject_version(YAML_CPP YAMLCPP_LIB_VERSION) + +configure_file(include/tscore/ink_config.h.cmake.in include/tscore/ink_config.h) +configure_file(include/ts/apidefs.h.in include/ts/apidefs.h) + add_subdirectory(src/tscpp/util) add_subdirectory(src/tscore) add_subdirectory(src/records) add_subdirectory(iocore) add_subdirectory(proxy) add_subdirectory(mgmt/utils) +add_subdirectory(mgmt/config) +add_subdirectory(mgmt/rpc) add_subdirectory(src/traffic_server) diff --git a/cmake/subproject_version.cmake b/cmake/subproject_version.cmake new file mode 100644 index 00000000000..aa0f369d61f --- /dev/null +++ b/cmake/subproject_version.cmake @@ -0,0 +1,20 @@ +# subproject_version( ) +# +# Extract version of a sub-project, which was previously included with add_subdirectory(). +function(subproject_version subproject_name VERSION_VAR) + # Read CMakeLists.txt for subproject and extract project() call(s) from it. + file(STRINGS "${${subproject_name}_SOURCE_DIR}/CMakeLists.txt" project_calls REGEX "[ \t]*project\\(") + # For every project() call try to extract its VERSION option + foreach(project_call ${project_calls}) + string(REGEX MATCH "VERSION[ ]+([^ )]+)" version_param "${project_call}") + if(version_param) + set(version_value "${CMAKE_MATCH_1}") + endif() + endforeach() + if(version_value) + set(${VERSION_VAR} "${version_value}" PARENT_SCOPE) + message("INFO: ${subproject_name} version ${version_value}") + else() + message("WARNING: Cannot extract version for subproject '${subproject_name}'") + endif() +endfunction(subproject_version) \ No newline at end of file diff --git a/include/tscore/ink_config.h.cmake.in b/include/tscore/ink_config.h.cmake.in index ec38aeb3aac..a34c471c7a9 100644 --- a/include/tscore/ink_config.h.cmake.in +++ b/include/tscore/ink_config.h.cmake.in @@ -93,5 +93,5 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@; #define TS_BUILD_CANONICAL_HOST "@CMAKE_HOST@" - +#cmakedefine YAMLCPP_LIB_VERSION "@YAMLCPP_LIB_VERSION@" diff --git a/iocore/eventsystem/CMakeLists.txt b/iocore/eventsystem/CMakeLists.txt index 9fe971a45b7..acea3ffba3b 100644 --- a/iocore/eventsystem/CMakeLists.txt +++ b/iocore/eventsystem/CMakeLists.txt @@ -33,5 +33,6 @@ target_sources(inkevent PRIVATE UnixEThread.cc UnixEvent.cc UnixEventProcessor.cc + ConfigProcessor.cc ) target_include_directories(inkevent PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1a8de4b701d..ab9040d3a9f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -19,7 +19,10 @@ # yamlcpp shadows a bunch of variables but we don't want to hear bout it add_compile_options(-Wno-shadow) +message("before yaml ${PROJECT_VERSION}") add_subdirectory(yamlcpp) set(YAML_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/lib/yamlcpp/include PARENT_SCOPE) +message("after yaml ${PROJECT_VERSION} - ${YAML_CPP_PROJECT_VERSION}") add_subdirectory(fastlz) +add_subdirectory(swoc) set(SWOC_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lib/swoc/include PARENT_SCOPE) diff --git a/lib/swoc/CMakeLists.txt b/lib/swoc/CMakeLists.txt new file mode 100644 index 00000000000..ee2f1ee4a0c --- /dev/null +++ b/lib/swoc/CMakeLists.txt @@ -0,0 +1,132 @@ +cmake_minimum_required(VERSION 3.11) + +project(Lib-SWOC CXX) +set(LIBSWOC_VERSION "1.4.2") +set(CMAKE_CXX_STANDARD 17) +cmake_policy(SET CMP0087 NEW) +# override "lib64" to be "lib" unless the user explicitly sets it. +set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "directory for libraries" FORCE) +include(GNUInstallDirs) + +cmake_dependent_option(LIBSWOC_INSTALL + "Enable generation of libswoc install targets" ON + "NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT" OFF) + +set(HEADER_FILES + include/swoc/swoc_version.h + include/swoc/ArenaWriter.h + include/swoc/BufferWriter.h + include/swoc/bwf_base.h + include/swoc/bwf_ex.h + include/swoc/bwf_ip.h + include/swoc/bwf_std.h + include/swoc/DiscreteRange.h + include/swoc/Errata.h + include/swoc/IntrusiveDList.h + include/swoc/IntrusiveHashMap.h + include/swoc/swoc_ip.h + include/swoc/IPEndpoint.h + include/swoc/IPAddr.h + include/swoc/IPSrv.h + include/swoc/IPRange.h + include/swoc/Lexicon.h + include/swoc/MemArena.h + include/swoc/MemSpan.h + include/swoc/Scalar.h + include/swoc/TextView.h + include/swoc/swoc_file.h + include/swoc/swoc_meta.h + include/swoc/string_view.h + include/swoc/Vectray.h + ) + +# These are external but required. +set(EXTERNAL_HEADER_FILES + include/swoc/ext/HashFNV.h + ) + +set(CC_FILES + src/bw_format.cc + src/bw_ip_format.cc + src/ArenaWriter.cc + src/Errata.cc + src/swoc_ip.cc + src/MemArena.cc + src/RBTree.cc + src/swoc_file.cc + src/TextView.cc + src/string_view_util.cc + ) + +add_library(libswoc SHARED ${CC_FILES}) +set_target_properties(libswoc PROPERTIES OUTPUT_NAME swoc-${LIBSWOC_VERSION}) +if (CMAKE_COMPILER_IS_GNUCXX) + target_compile_options(libswoc PRIVATE -fPIC -Wall -Wextra -Werror -Wnon-virtual-dtor -Wpedantic) +endif() + +add_library(libswoc-static STATIC ${CC_FILES}) +set_target_properties(libswoc-static PROPERTIES OUTPUT_NAME swoc-static-${LIBSWOC_VERSION}) +if (CMAKE_COMPILER_IS_GNUCXX) + target_compile_options(libswoc-static PRIVATE -fPIC -Wall -Wextra -Werror -Wnon-virtual-dtor -Wpedantic) +endif() + +# Not quite sure how this works, but I think it generates one of two paths depending on the context. +# That is, the generator functions return non-empty strings only in the corresponding context. +target_include_directories(libswoc-static + PUBLIC + $ + $ + ) + +target_include_directories(libswoc + PUBLIC + $ + $ + ) + +if (LIBSWOC_INSTALL) + # These install target variables are created by GNUInstallDirs. + install(TARGETS libswoc-static + EXPORT libswoc-static-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # seems to have no effect. + ) + install(TARGETS libswoc + EXPORT libswoc-config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # seems to have no effect. + ) + install(DIRECTORY include/swoc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + + set(link-target libswoc.so) + set(link-src $) + install(CODE + "execute_process(COMMAND bash -c \"echo Linking ${link-src} to ${link-target};cd ${CMAKE_INSTALL_FULL_LIBDIR} && (rm -f ${link-target};ln -s ${link-src} ${link-target}) + \")" + ) + + install(EXPORT libswoc-static-config + NAMESPACE libswoc:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libswoc + ) + + install(EXPORT libswoc-config + NAMESPACE libswoc:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libswoc + ) + + # set(PKG_CONFIG_FILE libswoc.pc) + # set(PKG_STATIC_CONFIG_FILE libswoc-static.pc) + # configure_file("libswoc.pc.cmake" ${PKG_CONFIG_FILE} @ONLY) + # + # configure_file("libswoc.pc.cmake" libswoc.pc @ONLY) + # configure_file("libswoc-static.pc.cmake" libswoc-static.pc @ONLY) + # install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libswoc.pc ${CMAKE_CURRENT_BINARY_DIR}/libswoc-static.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + # install(FILES ${PKG_STATIC_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endif() + +# Alledgedly this makes the targets "importable from the build directory" but I see no evidence of that. +# AFAICT the file isn't created at all even with this enabled. +#export(TARGETS libswoc FILE libswoc-config.cmake) + +set(CLANG_DIRS ) + +set_target_properties(libswoc-static PROPERTIES CLANG_FORMAT_DIRS "${PROJECT_SOURCE_DIR}/src;${PROJECT_SOURCE_DIR}/include") \ No newline at end of file diff --git a/mgmt/config/CMakeLists.txt b/mgmt/config/CMakeLists.txt new file mode 100644 index 00000000000..7f8c298ca7b --- /dev/null +++ b/mgmt/config/CMakeLists.txt @@ -0,0 +1,32 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + +add_library(configmanager STATIC + FileManager.cc + AddConfigFilesHere.cc +) +include_directories( + ${CMAKE_SOURCE_DIR}/mgmt + ${CMAKE_SOURCE_DIR}/proxy + ${CMAKE_SOURCE_DIR}/proxy/hdrs + ${CMAKE_SOURCE_DIR}/proxy/http + ${CMAKE_SOURCE_DIR}/iocore/eventsystem + ${CMAKE_SOURCE_DIR}/iocore/net + ${CMAKE_SOURCE_DIR}/iocore/cache + ${CMAKE_SOURCE_DIR}/iocore/aio + ${CMAKE_SOURCE_DIR}/iocore/dns +) \ No newline at end of file diff --git a/mgmt/config/Makefile.am b/mgmt/config/Makefile.am index 81d8ec623c7..689b5ce4c9c 100644 --- a/mgmt/config/Makefile.am +++ b/mgmt/config/Makefile.am @@ -33,7 +33,7 @@ AM_CPPFLAGS += \ $(TS_INCLUDES) @SWOC_INCLUDES@ \ @YAMLCPP_INCLUDES@ -# ^^ all the proxy/* is to include the PluginCallbacks. +# ^^ all the proxy is to include the PluginCallbacks. noinst_LTLIBRARIES = libconfigmanager.la #check_PROGRAMS = test_configfiles diff --git a/mgmt/rpc/CMakeLists.txt b/mgmt/rpc/CMakeLists.txt new file mode 100644 index 00000000000..feb8cb9ecc9 --- /dev/null +++ b/mgmt/rpc/CMakeLists.txt @@ -0,0 +1,54 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + +include_directories( + ${CMAKE_SOURCE_DIR}/mgmt + ${CMAKE_SOURCE_DIR}/mgmt/rpc + ${CMAKE_SOURCE_DIR}/iocore/eventsystem + ${CMAKE_SOURCE_DIR}/iocore/utils + ${CMAKE_SOURCE_DIR}/iocore/cache + ${CMAKE_SOURCE_DIR}/iocore/aio + ${CMAKE_SOURCE_DIR}/iocore/net + ${CMAKE_SOURCE_DIR}/iocore/dns + ${CMAKE_SOURCE_DIR}/lib + ${CMAKE_SOURCE_DIR}/proxy + ${CMAKE_SOURCE_DIR}/proxy/hdrs + ${CMAKE_SOURCE_DIR}/proxy/http + +) + +add_library(jsonrpc_protocol STATIC + jsonrpc/error/RPCError.cc + jsonrpc/JsonRPCManager.cc + jsonrpc/Context.cc +) + +add_library(jsonrpc_server STATIC + server/RPCServer.cc + server/CommBase.cc + server/IPCSocketServer.cc + config/JsonRPCConfig.cc +) + +add_library(rpcpublichandlers STATIC + handlers/common/RecordsUtils.cc + handlers/config/Configuration.cc + handlers/records/Records.cc + handlers/storage/Storage.cc + handlers/server/Server.cc + handlers/plugins/Plugins.cc +) \ No newline at end of file diff --git a/src/records/CMakeLists.txt b/src/records/CMakeLists.txt index f084d5783c8..20897ed6ada 100644 --- a/src/records/CMakeLists.txt +++ b/src/records/CMakeLists.txt @@ -27,6 +27,9 @@ add_library(records_lm STATIC RecMutex.cc RecRawStats.cc RecUtils.cc + RecYAMLDecoder.cc + RecordsConfig.cc + RecordsConfigUtils.cc ) target_include_directories(records_lm PRIVATE ${CMAKE_SOURCE_DIR}/mgmt @@ -48,6 +51,9 @@ add_library(records_p STATIC RecRawStats.cc RecUtils.cc RecProcess.cc + RecYAMLDecoder.cc + RecordsConfig.cc + RecordsConfigUtils.cc ) target_include_directories(records_p PRIVATE ${CMAKE_SOURCE_DIR}/mgmt diff --git a/src/traffic_server/CMakeLists.txt b/src/traffic_server/CMakeLists.txt index 3a937ea2964..97955731cbf 100644 --- a/src/traffic_server/CMakeLists.txt +++ b/src/traffic_server/CMakeLists.txt @@ -24,6 +24,7 @@ add_executable(traffic_server InkIOCoreAPI.cc SocksProxy.cc traffic_server.cc + RpcAdminPubHandlers.cc ${CMAKE_SOURCE_DIR}/src/shared/overridable_txn_vars.cc ) target_include_directories(traffic_server PRIVATE @@ -38,8 +39,8 @@ target_link_libraries(traffic_server http2 logging hdrs + configmanager diagsconfig - mgmt_p utils_p inkutils inkdns @@ -54,4 +55,8 @@ target_link_libraries(traffic_server records_p inkevent yaml-cpp + libswoc + jsonrpc_protocol + jsonrpc_server + rpcpublichandlers ) \ No newline at end of file diff --git a/src/tscpp/util/CMakeLists.txt b/src/tscpp/util/CMakeLists.txt index 83879fbacba..a4dc5056fed 100644 --- a/src/tscpp/util/CMakeLists.txt +++ b/src/tscpp/util/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(tscpputil SHARED TextView.cc YamlCfg.cc ) +target_link_libraries(tscpputil PRIVATE yaml-cpp libswoc) add_executable(test_tscpputil unit_tests/test_LocalBuffer.cc @@ -29,5 +30,5 @@ add_executable(test_tscpputil unit_tests/test_ts_meta.cc unit_tests/unit_test_main.cc ) -target_link_libraries(test_tscpputil PRIVATE tscpputil) +target_link_libraries(test_tscpputil PRIVATE tscpputil libswoc) target_include_directories(test_tscpputil PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR}) From 538ff8b52577d36e08d4067ffc32b1a34d30b746 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Tue, 14 Feb 2023 12:47:16 -0600 Subject: [PATCH 2/3] add license --- cmake/subproject_version.cmake | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmake/subproject_version.cmake b/cmake/subproject_version.cmake index aa0f369d61f..afa3696a715 100644 --- a/cmake/subproject_version.cmake +++ b/cmake/subproject_version.cmake @@ -1,3 +1,20 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + # subproject_version( ) # # Extract version of a sub-project, which was previously included with add_subdirectory(). @@ -17,4 +34,4 @@ function(subproject_version subproject_name VERSION_VAR) else() message("WARNING: Cannot extract version for subproject '${subproject_name}'") endif() -endfunction(subproject_version) \ No newline at end of file +endfunction(subproject_version) From 6b1be724049f27fdaf5a0d3e69761e99810c50af Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Tue, 14 Feb 2023 15:53:32 -0600 Subject: [PATCH 3/3] remove debug --- lib/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ab9040d3a9f..6d5d7e0ad11 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -19,10 +19,8 @@ # yamlcpp shadows a bunch of variables but we don't want to hear bout it add_compile_options(-Wno-shadow) -message("before yaml ${PROJECT_VERSION}") add_subdirectory(yamlcpp) set(YAML_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/lib/yamlcpp/include PARENT_SCOPE) -message("after yaml ${PROJECT_VERSION} - ${YAML_CPP_PROJECT_VERSION}") add_subdirectory(fastlz) add_subdirectory(swoc) set(SWOC_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lib/swoc/include PARENT_SCOPE)