summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-04-23 11:26:01 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-04-23 17:33:35 +0200
commitcb0a1d3e92d5b11effdf91779d49e1bed4a7c083 (patch)
tree8f8fecc842530a3b7dd927e54683927b08c80c58
parent72d8bb2c3bf74f24e5def6b16c932c9c0165c6ee (diff)
downloadjustbuild-cb0a1d3e92d5b11effdf91779d49e1bed4a7c083.tar.gz
just-mr: Fix map key type bug in repository setup
When taking over roots from the input repository description, the JSON value was not properly checked for validity (i.e., if it is of type string), resulting in an unhandled exception being thrown. The issue is fixed with a proper type check.
-rw-r--r--src/other_tools/just_mr/setup.cpp53
1 files changed, 38 insertions, 15 deletions
diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp
index e4430b79..5ec71a59 100644
--- a/src/other_tools/just_mr/setup.cpp
+++ b/src/other_tools/just_mr/setup.cpp
@@ -14,7 +14,10 @@
#include "src/other_tools/just_mr/setup.hpp"
-#include <filesystem>
+#include <atomic>
+#include <condition_variable>
+#include <cstddef>
+#include <thread>
#include "nlohmann/json.hpp"
#include "src/buildtool/execution_api/common/execution_api.hpp"
@@ -282,8 +285,14 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config,
repos_to_setup_map.ConsumeAfterKeysReady(
&ts,
setup_repos->to_setup,
- [&mr_config, config, setup_repos, main, interactive](
- auto const& values) {
+ [&failed,
+ &mr_config,
+ repos,
+ setup_repos,
+ main,
+ interactive,
+ multi_repo_tool_name](auto const& values) {
+ // set the initial setup repositories
nlohmann::json mr_repos{};
for (auto const& repo : setup_repos->to_setup) {
auto i = static_cast<std::size_t>(
@@ -291,24 +300,38 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config,
mr_repos[repo] = *values[i];
}
// populate ALT_DIRS
- auto repos = (*config)["repositories"];
- if (repos.IsNotNull()) {
- for (auto const& repo : setup_repos->to_include) {
- auto desc = repos->Get(repo, Expression::none_t{});
- if (desc.IsNotNull()) {
- if (not((main and (repo == *main)) and
- interactive)) {
- for (auto const& key : kAltDirs) {
- auto val =
- desc->Get(key, Expression::none_t{});
- if (val.IsNotNull() and
- not((main and val->IsString() and
+ constexpr auto err_msg_format =
+ "While performing {} {}:\nWhile populating fields for "
+ "repository {}:\nExpected value for key \"{}\" to be a "
+ "string, but found {}";
+ for (auto const& repo : setup_repos->to_include) {
+ auto desc = repos->Get(repo, Expression::none_t{});
+ if (desc.IsNotNull()) {
+ if (not((main and (repo == *main)) and interactive)) {
+ for (auto const& key : kAltDirs) {
+ auto val = desc->Get(key, Expression::none_t{});
+ if (val.IsNotNull()) {
+ // we expect a string
+ if (not val->IsString()) {
+ Logger::Log(
+ LogLevel::Error,
+ err_msg_format,
+ multi_repo_tool_name,
+ interactive ? "setup-env" : "setup",
+ repo,
+ key,
+ val->ToString());
+ failed = true;
+ return;
+ }
+ if (not((main and
(val->String() == *main)) and
interactive)) {
mr_repos[repo][key] =
mr_repos[val->String()]
["workspace_root"];
}
+ // otherwise, continue
}
}
}