1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-18 21:44:02 +03:00

MCOL-5880: get rid of CLI11 dep in favour of boost::program_options

This commit is contained in:
Leonid Fedorov 2025-01-13 16:05:23 +00:00 committed by Leonid Fedorov
parent dd8fac35ae
commit f99c24b47d
5 changed files with 84 additions and 52 deletions

View File

@ -136,7 +136,6 @@ SET (ENGINE_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE(columnstore_version) INCLUDE(columnstore_version)
INCLUDE(misc) INCLUDE(misc)
INCLUDE(boost) INCLUDE(boost)
INCLUDE(CLI11)
INCLUDE(thrift) INCLUDE(thrift)
INCLUDE(arrow) INCLUDE(arrow)

View File

@ -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})

View File

@ -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) install(TARGETS mcs-load-em DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine)
add_executable(mcs-load-brm-from-file load_brm_from_file.cpp) 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) install(TARGETS mcs-load-brm-from-file DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine)
add_executable(mcs-shmem-locks shmem_locks.cpp) 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) install(TARGETS mcs-shmem-locks DESTINATION ${ENGINE_BINDIR} COMPONENT columnstore-engine)

View File

@ -30,13 +30,14 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include <limits> #include <limits>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
using namespace std; using namespace std;
#include "CLI11.hpp"
#include "extentmap.h" #include "extentmap.h"
static const char* BIN_NAME = "mcs-load-brm-from-file";
template <typename T> template <typename T>
T parseField(std::stringstream& ss, const char delimiter) 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) int main(int argc, char** argv)
{ {
CLI::App app{BIN_NAME}; po::options_description desc(
app.description( "A tool to build Extent Map image file from its text representation. A text representation can be "
"A tool to build Extent Map image file from its text representation. A text representation can be obtained using 'editem -i'" "obtained using 'editem -i'"
"display the lock state."); "display the lock state.");
std::string srcFilename; std::string srcFilename;
std::string dstFilename; std::string dstFilename;
bool debug = false; bool debug = false;
app.add_option("-i,--input-filename", srcFilename, // clang-format off
desc.add_options()
("help", "produce help message")
("input-filename,i",
po::value<std::string>(&srcFilename)->required(),
"Extent Map as its text representation.") "Extent Map as its text representation.")
->required(); ("output-filename,o",
app.add_option("-o,--output-filename", dstFilename, po::value<std::string>(&dstFilename)->default_value(""),
"Extent Map output image file, default as input-filename.out") "Extent Map output image file, default as input-filename.out")
->default_val(""); ("debug,d", po::bool_switch(&debug)->default_value(false), "Print extra output");
app.add_option("-d,--debug", debug, "Print extra output")->default_val(false); // 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); ifstream in(srcFilename);
int e = errno; int e = errno;

View File

@ -21,12 +21,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <rwlock.h> #include <rwlock.h>
#include "CLI11.hpp"
using namespace std; using namespace std;
using namespace rwlock; using namespace rwlock;
static const char* BIN_NAME = "mcs-load-brm-from-file"; #include <boost/program_options.hpp>
namespace po = boost::program_options;
std::string getShmemLocksList() std::string getShmemLocksList()
{ {
@ -85,31 +84,66 @@ int lockOp(size_t minLockId, size_t maxLockId, bool lock, bool read)
return 0; 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 <class T>
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<T>();
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) int main(int argc, char** argv)
{ {
CLI::App app{BIN_NAME}; int lockId;
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;
bool debug = false; bool debug = false;
bool read = false; bool read = false;
bool write = false; bool write = false;
bool lock = false; bool lock = false;
bool unlock = false; bool unlock = false;
app.add_option<uint8_t>("-i, --lock-id", lockId, "Shmem lock numerical id: " + getShmemLocksList()) po::options_description desc(
->expected(0, RWLockNames.size()) "A tool to operate or view shmem locks. If neither read nor write operation is specified, the tool "
->required(); "will "
app.add_flag("-r, --read-lock", read, "Use read lock.")->default_val(false); "display the lock state.");
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);
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<int>(&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<int>(vm, "lock-id", 0, RWLockNames.size());
po::notify(vm);
if (!read && !write) if (!read && !write)
{ {
@ -125,4 +159,3 @@ int main(int argc, char** argv)
return 0; return 0;
} }