Skip to content

Commit

Permalink
#2175: link vt with yaml-cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Dec 20, 2023
1 parent 5e56352 commit 2f7e45c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
19 changes: 19 additions & 0 deletions cmake/link_vt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function(link_target_with_vt)
LINK_FCONTEXT
LINK_CHECKPOINT
LINK_CLI11
LINK_YAMLCPP
LINK_DL
LINK_ZOLTAN
LINK_FORT
Expand Down Expand Up @@ -203,6 +204,24 @@ function(link_target_with_vt)
)
endif()

if (NOT DEFINED ARG_LINK_YAMLCPP AND ${ARG_DEFAULT_LINK_SET} OR ARG_LINK_YAMLCPP)
if (${ARG_DEBUG_LINK})
message(STATUS "link_target_with_vt: yaml-cpp=${ARG_LINK_YAMLCPP}")
endif()

# Find the yaml-cpp package
find_package(yaml-cpp REQUIRED)

# Link with yaml-cpp
target_link_libraries(${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} yaml-cpp)

# Include yaml-cpp headers
target_include_directories(${ARG_TARGET} PUBLIC
$<BUILD_INTERFACE:${YAML_CPP_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include/yaml-cpp>
)
endif()

if (${vt_mimalloc_enabled})
if (${ARG_DEBUG_LINK})
message(STATUS "link_target_with_vt: mimalloc=${vt_mimalloc_enabled}")
Expand Down
37 changes: 16 additions & 21 deletions src/vt/configs/arguments/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void postParseTransform(AppConfig& appConfig) {
}
}

void parse_yaml(std::string& config_file, AppConfig& appConfig);

std::tuple<int, std::string> parseArguments(
CLI::App& app, int& argc, char**& argv, AppConfig& appConfig
) {
Expand Down Expand Up @@ -125,20 +127,20 @@ std::tuple<int, std::string> parseArguments(

// Dispatch to CLI or yaml-cpp for config file
std::string config_file;
app.add_option("--vt_input_config", config_file, "Read in a yaml, toml, or ini config file for VT")
if (config_file) {
config_ending = config_file.substr(config_file.size()-4)
if (config_ending == ".yml") | (config_ending == "yaml") {
app.add_option("--vt_input_config", config_file, "Read in a yaml, toml, or ini config file for VT");
if (!config_file.empty()) {
std::string config_ending = config_file.substr(config_file.size()-4);
if (config_ending == ".yml" || config_ending == "yaml") {
// use yaml-cpp
parse_yaml(config_file, appConfig);
} else if (config_ending == ".ini") | (config_ending == "toml") {
} else if (config_ending == ".ini" || config_ending == "toml") {
// use CLI parser
app.set_config(
"--vt_input_CLI_config",
config_file,
"Read in a config file with CLI library",
false // not required
)
);
}
}

Expand Down Expand Up @@ -199,27 +201,20 @@ std::tuple<int, std::string> parseArguments(

void parse_yaml(std::string& config_file, AppConfig& appConfig) {
// Assume input yaml is structured the same as --vt-help
auto yaml_input = YAML::LoadAllFromFile(config_file);
auto yaml_input = YAML::LoadFile(config_file);

// Output control
YAML::Node output_control = yaml_input["Output Control"];
auto quiet = "Quiet the output from vt (only errors, warnings)";
auto always = "Colorize output (default)";
auto never = "Do not colorize output (overrides --vt_color)";
appConfig.vt_color = output_control["vt_color"].as<std::string>(always);
appConfig.vt_no_color = output_control["vt_no_color"].as<std::string>(never);
appConfig.vt_quiet = output_control["vt_quiet"].as<std::string>(quiet);
appConfig.vt_color = output_control["vt_color"].as<bool>(false);
appConfig.vt_no_color = output_control["vt_no_color"].as<bool>(false);
appConfig.vt_quiet = output_control["vt_quiet"].as<bool>(false);

// Signal handling
YAML::Node signal_handling = yaml_input["Signal Handling"];
auto no_sigint = "Do not register signal handler for SIGINT";
auto no_sigsegv = "Do not register signal handler for SIGSEGV";
auto no_sigbus = "Do not register signal handler for SIGBUS";
auto no_terminate = "Do not register handler for std::terminate";
appConfig.vt_no_sigint = signal_handling["vt_no_SIGINT"].as<std::string>(no_sigint);
appConfig.vt_no_sigsegv = signal_handling["vt_no_SIGSEGV"].as<std::string>(no_sigsegv);
appConfig.vt_no_sigbus = signal_handling["vt_no_SIGBUS"].as<std::string>(no_sigbus);
appConfig.vt_no_terminate = signal_handling["vt_no_terminate"].as<std::string>(no_terminate);
appConfig.vt_no_sigint = signal_handling["vt_no_SIGINT"].as<bool>(false);
appConfig.vt_no_sigsegv = signal_handling["vt_no_SIGSEGV"].as<bool>(false);
appConfig.vt_no_sigbus = signal_handling["vt_no_SIGBUS"].as<bool>(false);
appConfig.vt_no_terminate = signal_handling["vt_no_terminate"].as<bool>(false);
}

void addColorArgs(CLI::App& app, AppConfig& appConfig) {
Expand Down

0 comments on commit 2f7e45c

Please sign in to comment.