From a1bdc438f3e17b0c30f3a53b0bc5e38ebb7bb936 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 7 Dec 2023 10:59:10 +0100 Subject: just-mrrc: support file options for the launcher functionality When just-mr acts as a launcher, for most subcommand options the "just args" entry in the rc files provides a convenient way to set them. However, some options take a file as argument; for those it can be desirable to set them without assuming a fixed file-system layout and instead refer to logical roots, in particular the work space. for the ones that refer to files, it is often desirable to have a potential reference to the work space. Add this functionality. --- src/other_tools/just_mr/rc.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/other_tools/just_mr/rc.cpp') diff --git a/src/other_tools/just_mr/rc.cpp b/src/other_tools/just_mr/rc.cpp index 63e772bf..d8b8067a 100644 --- a/src/other_tools/just_mr/rc.cpp +++ b/src/other_tools/just_mr/rc.cpp @@ -103,6 +103,30 @@ namespace { std::filesystem::weakly_canonical( std::filesystem::absolute(root_path / base))); } + +[[nodiscard]] auto ReadOptionalLocationList( + ExpressionPtr const& location_list, + std::optional const& ws_root, + std::string const& argument_name) -> std::optional { + if (location_list->IsNone()) { + return std::nullopt; + } + if (not location_list->IsList()) { + Logger::Log(LogLevel::Error, + "Argument {} has to be a list, but found {}", + argument_name, + location_list->ToString()); + std::exit(kExitConfigError); + } + for (auto const& location : location_list->List()) { + auto p = ReadLocation(location, ws_root); + if (p and FileSystemManager::IsFile(p->first)) { + return p->first; + } + } + return std::nullopt; +} + } // namespace /// \brief Read just-mrrc file and set up various configs. Return the path to @@ -216,6 +240,26 @@ namespace { clargs->common.git_path = git->first; } } + // read the just file-arguments + auto just_files = rc_config["just files"]; + if (just_files.IsNotNull()) { + if (not just_files->IsMap()) { + Logger::Log(LogLevel::Error, + "Configration-file provided 'just files' has to be a " + "map, but found {}.", + just_files->ToString()); + std::exit(kExitConfigError); + } + auto files = Configuration(just_files); + clargs->just_cmd.config = ReadOptionalLocationList( + files["config"], + clargs->common.just_mr_paths->workspace_root, + "'config' in 'just files'"); + clargs->just_cmd.endpoint_configuration = ReadOptionalLocationList( + files["endpoint-configuration"], + clargs->common.just_mr_paths->workspace_root, + "'endpoint-configuration' in 'just files'"); + } // read additional just args; user can append, but does not overwrite auto just_args = rc_config["just args"]; if (just_args.IsNotNull()) { -- cgit v1.2.3