diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-12-07 10:59:10 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-12-11 15:41:58 +0100 |
commit | a1bdc438f3e17b0c30f3a53b0bc5e38ebb7bb936 (patch) | |
tree | dca0a5c292eb573d36888cc631e92f6ed4d74428 /src/other_tools/just_mr/rc.cpp | |
parent | bcbfd1fc659df948899fa34e8a1af7fa6f7920e6 (diff) | |
download | justbuild-a1bdc438f3e17b0c30f3a53b0bc5e38ebb7bb936.tar.gz |
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.
Diffstat (limited to 'src/other_tools/just_mr/rc.cpp')
-rw-r--r-- | src/other_tools/just_mr/rc.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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<std::filesystem::path> const& ws_root, + std::string const& argument_name) -> std::optional<std::filesystem::path> { + 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()) { |