From b5e747f86180d204b9aa2b33f9037638b8e75dbf Mon Sep 17 00:00:00 2001 From: tedli Date: Mon, 3 Jul 2023 21:58:23 +0800 Subject: [PATCH] command docs conditional build (#1670) * add command docs impl Signed-off-by: lizhen6 * add command docs impl, add unit test Signed-off-by: lizhen6 * add pika specialization Signed-off-by: lizhen6 * command docs conditional build Signed-off-by: lizhen6 * command docs conditional build, fix test Signed-off-by: lizhen6 --------- Signed-off-by: lizhen6 --- CMakeLists.txt | 4 ++++ Makefile | 3 ++- build.sh | 7 ++++++- include/pika_admin.h | 3 +++ src/pika_admin.cc | 4 ++++ src/pika_command.cc | 3 +++ src/pika_command_docs.cc | 16 ++++++++++------ tests/test_helper.tcl | 3 +-- 8 files changed, 33 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dc2becbf5..690a04db4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,10 @@ else () message(STATUS "found clang-apply-replacements at ${CLANG_APPLY_REPLACEMENTS_BIN}") endif () +option(WITH_COMMAND_DOCS "build with command docs support" OFF) +if (WITH_COMMAND_DOCS) + add_definitions(-DWITH_COMMAND_DOCS) +endif() include(protogen.cmake) include(ExternalProject) diff --git a/Makefile b/Makefile index 83509c8f83..ace9031203 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ export PRINT_HELP_PYSCRIPT BROWSER := python -c "$$BROWSER_PYSCRIPT" INSTALL_LOCATION := ~/.local +WITH_COMMAND_DOCS ?= ${WITH_COMMAND_DOCS:-OFF} help: @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) @@ -33,7 +34,7 @@ help: pika: rm -rf build/ rm -rf buildtrees/ - cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$(INSTALL_LOCATION) -DWITH_COMMAND_DOCS=$(WITH_COMMAND_DOCS) cmake --build build --config Release codis: diff --git a/build.sh b/build.sh index bc851633f0..e5fd942bd5 100755 --- a/build.sh +++ b/build.sh @@ -97,7 +97,12 @@ if [ $1 = "tools" ]; then use_pika_tools="-DUSE_PIKA_TOOLS=ON" fi -${CMAKE} ${use_pika_tools} .. . +with_command_docs="" +if [ "${WITH_COMMAND_DOCS}" = "ON" ]; then + with_command_docs="-DWITH_COMMAND_DOCS=ON" +fi + +${CMAKE} ${use_pika_tools} ${with_command_docs} .. . if [ $? -ne 0 ]; then echo -e "${C_RED} cmake execution error ${C_END}" diff --git a/include/pika_admin.h b/include/pika_admin.h index 6fb4cf73b3..5b028e334b 100644 --- a/include/pika_admin.h +++ b/include/pika_admin.h @@ -446,6 +446,7 @@ class HelloCmd : public Cmd { void DoInitial() override; }; +#ifdef WITH_COMMAND_DOCS class CommandCmd : public Cmd { public: CommandCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag) {} @@ -588,4 +589,6 @@ static CommandCmd::EncodablePtr RedisMap(CommandCmd::EncodableMap::RedisMap valu static CommandCmd::EncodablePtr RedisSet(std::vector values); static CommandCmd::EncodablePtr RedisArray(std::vector values); +#endif // WITH_COMMAND_DOCS + #endif // PIKA_ADMIN_H_ diff --git a/src/pika_admin.cc b/src/pika_admin.cc index e63ec73433..fe41c40cb8 100644 --- a/src/pika_admin.cc +++ b/src/pika_admin.cc @@ -2393,6 +2393,8 @@ void HelloCmd::Do(std::shared_ptr slot) { res_.AppendStringRaw(raw); } +#ifdef WITH_COMMAND_DOCS + bool CommandCmd::CommandFieldCompare::operator()(const std::string& a, const std::string& b) const { int av{0}; int bv{0}; @@ -2575,3 +2577,5 @@ void CommandCmd::Do(std::shared_ptr slots) { } EncodableMap::EncodeTo(res_, cmds, specializations); } + +#endif // WITH_COMMAND_DOCS diff --git a/src/pika_command.cc b/src/pika_command.cc index 352d31eb62..4966366d0a 100644 --- a/src/pika_command.cc +++ b/src/pika_command.cc @@ -92,8 +92,11 @@ void InitCmdTable(CmdTable* cmd_table) { cmd_table->insert(std::pair>(kCmdDummy, std::move(dummyptr))); std::unique_ptr quitptr = std::make_unique(kCmdNameQuit, 1, kCmdFlagsRead); cmd_table->insert(std::pair>(kCmdNameQuit, std::move(quitptr))); + +#ifdef WITH_COMMAND_DOCS std::unique_ptr commandptr = std::make_unique(kCmdNameCommand, -1, kCmdFlagsRead | kCmdFlagsAdmin); cmd_table->insert(std::pair>(kCmdNameCommand, std::move(commandptr))); +#endif // Slots related std::unique_ptr slotsinfoptr = diff --git a/src/pika_command_docs.cc b/src/pika_command_docs.cc index 17a16191a0..50087d17d3 100644 --- a/src/pika_command_docs.cc +++ b/src/pika_command_docs.cc @@ -3,12 +3,14 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. -#include "include/pika_admin.h" +#ifdef WITH_COMMAND_DOCS -#include -#include -#include -#include +# include "include/pika_admin.h" + +# include +# include +# include +# include static CommandCmd::EncodablePtr operator""_RedisInt(unsigned long long value) { return std::make_shared(value); @@ -10838,4 +10840,6 @@ const std::unordered_map CommandCmd::kCom }), })}, })}, -}; \ No newline at end of file +}; + +#endif // WITH_COMMAND_DOCS diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 60df5114d9..25722a95c6 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -49,8 +49,7 @@ set ::all_tests { # unit/bitops # unit/memefficiency # unit/hyperloglog - unit/type - unit/command + # unit/command unit/type }