Skip to content

Commit

Permalink
command docs conditional build (OpenAtomFoundation#1670)
Browse files Browse the repository at this point in the history
* add command docs impl

Signed-off-by: lizhen6 <[email protected]>

* add command docs impl, add unit test

Signed-off-by: lizhen6 <[email protected]>

* add pika specialization

Signed-off-by: lizhen6 <[email protected]>

* command docs conditional build

Signed-off-by: lizhen6 <[email protected]>

* command docs conditional build, fix test

Signed-off-by: lizhen6 <[email protected]>

---------

Signed-off-by: lizhen6 <[email protected]>
  • Loading branch information
tedli authored Jul 3, 2023
1 parent 6abf2b5 commit b5e747f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ 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)

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:
Expand Down
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
3 changes: 3 additions & 0 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -588,4 +589,6 @@ static CommandCmd::EncodablePtr RedisMap(CommandCmd::EncodableMap::RedisMap valu
static CommandCmd::EncodablePtr RedisSet(std::vector<CommandCmd::EncodablePtr> values);
static CommandCmd::EncodablePtr RedisArray(std::vector<CommandCmd::EncodablePtr> values);

#endif // WITH_COMMAND_DOCS

#endif // PIKA_ADMIN_H_
4 changes: 4 additions & 0 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,8 @@ void HelloCmd::Do(std::shared_ptr<Slot> 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};
Expand Down Expand Up @@ -2575,3 +2577,5 @@ void CommandCmd::Do(std::shared_ptr<Slot> slots) {
}
EncodableMap::EncodeTo(res_, cmds, specializations);
}

#endif // WITH_COMMAND_DOCS
3 changes: 3 additions & 0 deletions src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ void InitCmdTable(CmdTable* cmd_table) {
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdDummy, std::move(dummyptr)));
std::unique_ptr<Cmd> quitptr = std::make_unique<QuitCmd>(kCmdNameQuit, 1, kCmdFlagsRead);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameQuit, std::move(quitptr)));

#ifdef WITH_COMMAND_DOCS
std::unique_ptr<Cmd> commandptr = std::make_unique<CommandCmd>(kCmdNameCommand, -1, kCmdFlagsRead | kCmdFlagsAdmin);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameCommand, std::move(commandptr)));
#endif

// Slots related
std::unique_ptr<Cmd> slotsinfoptr =
Expand Down
16 changes: 10 additions & 6 deletions src/pika_command_docs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
# include "include/pika_admin.h"

# include <memory>
# include <string>
# include <unordered_map>
# include <unordered_set>

static CommandCmd::EncodablePtr operator""_RedisInt(unsigned long long value) {
return std::make_shared<CommandCmd::EncodableInt>(value);
Expand Down Expand Up @@ -10838,4 +10840,6 @@ const std::unordered_map<std::string, CommandCmd::EncodablePtr> CommandCmd::kCom
}),
})},
})},
};
};

#endif // WITH_COMMAND_DOCS
3 changes: 1 addition & 2 deletions tests/test_helper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ set ::all_tests {
# unit/bitops
# unit/memefficiency
# unit/hyperloglog
unit/type
unit/command
# unit/command
unit/type
}

Expand Down

0 comments on commit b5e747f

Please sign in to comment.