From f99c24b47da7a951e56b54db6993cfaec50b614a Mon Sep 17 00:00:00 2001 From: Leonid Fedorov Date: Mon, 13 Jan 2025 16:05:23 +0000 Subject: [PATCH] MCOL-5880: get rid of CLI11 dep in favour of boost::program_options --- CMakeLists.txt | 1 - cmake/CLI11.cmake | 15 ------ versioning/BRM/CMakeLists.txt | 4 +- versioning/BRM/load_brm_from_file.cpp | 43 +++++++++++----- versioning/BRM/shmem_locks.cpp | 73 +++++++++++++++++++-------- 5 files changed, 84 insertions(+), 52 deletions(-) delete mode 100644 cmake/CLI11.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e26483967..0f8cd0737 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,6 @@ SET (ENGINE_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE(columnstore_version) INCLUDE(misc) INCLUDE(boost) -INCLUDE(CLI11) INCLUDE(thrift) INCLUDE(arrow) diff --git a/cmake/CLI11.cmake b/cmake/CLI11.cmake deleted file mode 100644 index d86e9f99c..000000000 --- a/cmake/CLI11.cmake +++ /dev/null @@ -1,15 +0,0 @@ -set(EXTERNAL_INCLUDE_DIR "${CMAKE_BINARY_DIR}/external/include") -file(MAKE_DIRECTORY "${EXTERNAL_INCLUDE_DIR}") - -set(C11CLI_URL "https://github.com/CLIUtils/CLI11/releases/download/v2.4.2/CLI11.hpp") -set(C11CLI_HEADER "${EXTERNAL_INCLUDE_DIR}/CLI11.hpp") -set(CLI11_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}") - -file(DOWNLOAD - ${C11CLI_URL} - ${C11CLI_HEADER} - SHOW_PROGRESS STATUS download_status -) - -add_library(CLI11 INTERFACE) -target_include_directories(CLI11 INTERFACE ${CLI11_INCLUDE_DIR}) \ No newline at end of file diff --git a/versioning/BRM/CMakeLists.txt b/versioning/BRM/CMakeLists.txt index 203360bad..ac165d79e 100644 --- a/versioning/BRM/CMakeLists.txt +++ b/versioning/BRM/CMakeLists.txt @@ -122,9 +122,9 @@ target_link_libraries(mcs-load-em ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENG install(TARGETS mcs-load-em DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine) add_executable(mcs-load-brm-from-file load_brm_from_file.cpp) -target_link_libraries(mcs-load-brm-from-file ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} CLI11) +target_link_libraries(mcs-load-brm-from-file ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} boost_program_options) install(TARGETS mcs-load-brm-from-file DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine) add_executable(mcs-shmem-locks shmem_locks.cpp) -target_link_libraries(mcs-shmem-locks ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} CLI11) +target_link_libraries(mcs-shmem-locks ${ENGINE_LDFLAGS} ${MARIADB_CLIENT_LIBS} ${ENGINE_OAM_LIBS} ${ENGINE_EXEC_LIBS} ${NETSNMP_LIBRARIES} boost_program_options) install(TARGETS mcs-shmem-locks DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine) \ No newline at end of file diff --git a/versioning/BRM/load_brm_from_file.cpp b/versioning/BRM/load_brm_from_file.cpp index f70baafd7..1ec44f1d1 100644 --- a/versioning/BRM/load_brm_from_file.cpp +++ b/versioning/BRM/load_brm_from_file.cpp @@ -30,13 +30,14 @@ #include #include #include + +#include +namespace po = boost::program_options; + using namespace std; -#include "CLI11.hpp" #include "extentmap.h" -static const char* BIN_NAME = "mcs-load-brm-from-file"; - template T parseField(std::stringstream& ss, const char delimiter) { @@ -75,23 +76,37 @@ BRM::EMEntry parseLine(const std::string& line, char delimiter = '|') int main(int argc, char** argv) { - CLI::App app{BIN_NAME}; - app.description( - "A tool to build Extent Map image file from its text representation. A text representation can be obtained using 'editem -i'" + po::options_description desc( + "A tool to build Extent Map image file from its text representation. A text representation can be " + "obtained using 'editem -i'" "display the lock state."); + std::string srcFilename; std::string dstFilename; bool debug = false; - app.add_option("-i,--input-filename", srcFilename, - "Extent Map as its text representation.") - ->required(); - app.add_option("-o,--output-filename", dstFilename, - "Extent Map output image file, default as input-filename.out") - ->default_val(""); - app.add_option("-d,--debug", debug, "Print extra output")->default_val(false); + // clang-format off + desc.add_options() + ("help", "produce help message") + ("input-filename,i", + po::value(&srcFilename)->required(), + "Extent Map as its text representation.") + ("output-filename,o", + po::value(&dstFilename)->default_value(""), + "Extent Map output image file, default as input-filename.out") + ("debug,d", po::bool_switch(&debug)->default_value(false), "Print extra output"); + // clang-format on - CLI11_PARSE(app, argc, argv); + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + + if (argc == 1 || vm.count("help")) + { + cout << desc << "\n"; + return 1; + } + + po::notify(vm); ifstream in(srcFilename); int e = errno; diff --git a/versioning/BRM/shmem_locks.cpp b/versioning/BRM/shmem_locks.cpp index 917e64b81..f8a455597 100644 --- a/versioning/BRM/shmem_locks.cpp +++ b/versioning/BRM/shmem_locks.cpp @@ -21,12 +21,11 @@ #include #include -#include "CLI11.hpp" - using namespace std; using namespace rwlock; -static const char* BIN_NAME = "mcs-load-brm-from-file"; +#include +namespace po = boost::program_options; std::string getShmemLocksList() { @@ -85,31 +84,66 @@ int lockOp(size_t minLockId, size_t maxLockId, bool lock, bool read) return 0; } +void conflicting_options(const boost::program_options::variables_map& vm, const std::string& opt1, + const std::string& opt2) +{ + if (vm.count(opt1) && !vm[opt1].defaulted() && vm.count(opt2) && !vm[opt2].defaulted()) + { + throw std::logic_error(std::string("Conflicting options '") + opt1 + "' and '" + opt2 + "'."); + } +} + +template +void check_value(const boost::program_options::variables_map& vm, const std::string& opt1, T lower_bound, + T upper_bound) +{ + auto value = vm[opt1].as(); + if (value < lower_bound || value >= upper_bound) + { + throw std::logic_error(std::string("Option '") + opt1 + "' is out of range.: " + std::to_string(value)); + } +} + int main(int argc, char** argv) { - CLI::App app{BIN_NAME}; - app.description( - "A tool to operate or view shmem locks. If neither read nor write operation is specified, the tool will " - "display the lock state."); - uint8_t lockId; + int lockId; bool debug = false; bool read = false; bool write = false; bool lock = false; bool unlock = false; - app.add_option("-i, --lock-id", lockId, "Shmem lock numerical id: " + getShmemLocksList()) - ->expected(0, RWLockNames.size()) - ->required(); - app.add_flag("-r, --read-lock", read, "Use read lock.")->default_val(false); - app.add_flag("-w, --write-lock", write, "Use write lock..")->default_val(false)->excludes("-r"); - app.add_flag("-l, --lock", lock, "Lock the corresponding shmem lock.")->default_val(false); - app.add_flag("-u, --unlock", unlock, "Unlock the corresponding shmem write lock.") - ->default_val(false) - ->excludes("-l"); - app.add_flag("-d,--debug", debug, "Print extra output.")->default_val(false); + po::options_description desc( + "A tool to operate or view shmem locks. If neither read nor write operation is specified, the tool " + "will " + "display the lock state."); - CLI11_PARSE(app, argc, argv); + std::string lockid_description = std::string("Shmem lock numerical id: ") + getShmemLocksList(); + + // clang-format off + desc.add_options()("help", "produce help message") + ("lock-id,i", po::value(&lockId)->required(), lockid_description.c_str()) + ("read-lock,r", po::bool_switch(&read)->default_value(false), "Use read lock.") + ("write-lock,w", po::bool_switch(&write)->default_value(false), "Use write lock.") + ("lock,l", po::bool_switch(&lock)->default_value(false), "Lock the corresponding shmem lock.") + ("unlock,u", po::bool_switch(&unlock)->default_value(false), "Unlock the corresponding shmem write lock.") + ("debug,d", po::bool_switch(&debug)->default_value(false), "Print extra output."); + // clang-format on + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + + if (argc == 1 || vm.count("help")) + { + cout << desc << "\n"; + return 1; + } + + conflicting_options(vm, "lock", "unlock"); + conflicting_options(vm, "read-lock", "write-lock"); + check_value(vm, "lock-id", 0, RWLockNames.size()); + + po::notify(vm); if (!read && !write) { @@ -125,4 +159,3 @@ int main(int argc, char** argv) return 0; } -