summaryrefslogtreecommitdiff
path: root/src/other_tools/repo_map
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-11 11:59:52 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-11 14:52:07 +0200
commit7c476a707544f2de6ed7ecc296eb08591ca1a691 (patch)
tree99ccf450cb367f444a99b69b8c3ab507bb4c79a5 /src/other_tools/repo_map
parentb81206fe9885ed9f6fb0426d91ac607f7d8393c3 (diff)
downloadjustbuild-7c476a707544f2de6ed7ecc296eb08591ca1a691.tar.gz
Move ParseArchiveContent function to the header
...to remove code duplications in ReposToSetupMap.
Diffstat (limited to 'src/other_tools/repo_map')
-rw-r--r--src/other_tools/repo_map/repos_to_setup_map.cpp104
1 files changed, 13 insertions, 91 deletions
diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp
index 48074fd4..29a0715c 100644
--- a/src/other_tools/repo_map/repos_to_setup_map.cpp
+++ b/src/other_tools/repo_map/repos_to_setup_map.cpp
@@ -495,106 +495,28 @@ void DistdirCheckout(ExpressionPtr const& repo_desc,
}
// only do work if repo is archive type
if (kCheckoutTypeMap.at(repo_type_str) == CheckoutType::Archive) {
- // check mandatory fields
- auto repo_desc_content = (*resolved_repo_desc)->At("content");
- if (not repo_desc_content) {
- (*logger)(fmt::format(
- "DistdirCheckout: Mandatory field \"content\" is "
- "missing for repository {}",
- nlohmann::json(dist_repo_name).dump()),
- /*fatal=*/true);
- return;
- }
- if (not repo_desc_content->get()->IsString()) {
- (*logger)(fmt::format("DistdirCheckout: Unsupported value {} "
- "for mandatory field \"content\" for "
- "repository {}",
- repo_desc_content->get()->ToString(),
- nlohmann::json(dist_repo_name).dump()),
- /*fatal=*/true);
- return;
- }
- auto repo_desc_fetch = (*resolved_repo_desc)->At("fetch");
- if (not repo_desc_fetch) {
- (*logger)(fmt::format("DistdirCheckout: Mandatory field "
- "\"fetch\" is missing for repository {}",
- nlohmann::json(dist_repo_name).dump()),
- /*fatal=*/true);
- return;
- }
- if (not repo_desc_fetch->get()->IsString()) {
- (*logger)(fmt::format(
- "DistdirCheckout: Unsupported value {} "
- "for mandatory field \"fetch\" for repository {}",
- repo_desc_fetch->get()->ToString(),
- nlohmann::json(dist_repo_name).dump()),
- /*fatal=*/true);
- return;
- }
- auto repo_desc_distfile =
- (*resolved_repo_desc)->Get("distfile", Expression::none_t{});
- auto repo_desc_sha256 =
- (*resolved_repo_desc)->Get("sha256", Expression::none_t{});
- auto repo_desc_sha512 =
- (*resolved_repo_desc)->Get("sha512", Expression::none_t{});
-
- // check optional mirrors
- auto repo_desc_mirrors =
- (*resolved_repo_desc)->Get("mirrors", Expression::list_t{});
- std::vector<std::string> mirrors{};
- if (repo_desc_mirrors->IsList()) {
- mirrors.reserve(repo_desc_mirrors->List().size());
- for (auto const& elem : repo_desc_mirrors->List()) {
- if (not elem->IsString()) {
- (*logger)(fmt::format(
- "DistdirCheckout: Unsupported list entry "
- "{} in optional field \"mirrors\" for "
- "repository {}",
- elem->ToString(),
- nlohmann::json(dist_repo_name).dump()),
- /*fatal=*/true);
- return;
- }
- mirrors.emplace_back(elem->String());
- }
- }
- else {
- (*logger)(fmt::format("DistdirCheckout: Optional field "
- "\"mirrors\" for repository {} should be "
- "a list of strings, but found: {}",
+ auto const archive =
+ ParseArchiveContent(*resolved_repo_desc, dist_repo_name);
+ if (not archive) {
+ (*logger)(fmt::format("DistdirCheckout: an error occurred "
+ "while parsing repository {}\n{}",
nlohmann::json(dist_repo_name).dump(),
- repo_desc_mirrors->ToString()),
+ archive.error()),
/*fatal=*/true);
return;
}
- ArchiveContent archive = {
- .content = repo_desc_content->get()->String(),
- .distfile =
- repo_desc_distfile->IsString()
- ? std::make_optional(repo_desc_distfile->String())
- : std::nullopt,
- .fetch_url = repo_desc_fetch->get()->String(),
- .mirrors = std::move(mirrors),
- .sha256 = repo_desc_sha256->IsString()
- ? std::make_optional(repo_desc_sha256->String())
- : std::nullopt,
- .sha512 = repo_desc_sha512->IsString()
- ? std::make_optional(repo_desc_sha512->String())
- : std::nullopt,
- .origin = dist_repo_name};
-
// add to distdir content map
auto repo_distfile =
- (archive.distfile ? archive.distfile.value()
- : std::filesystem::path(archive.fetch_url)
- .filename()
- .string());
+ (archive->distfile ? archive->distfile.value()
+ : std::filesystem::path(archive->fetch_url)
+ .filename()
+ .string());
distdir_content_for_id->insert_or_assign(
- repo_distfile, std::make_pair(archive.content, false));
- distdir_content->insert_or_assign(repo_distfile, archive.content);
+ repo_distfile, std::make_pair(archive->content, false));
+ distdir_content->insert_or_assign(repo_distfile, archive->content);
// add to fetch list
- dist_repos_to_fetch->emplace_back(std::move(archive));
+ dist_repos_to_fetch->emplace_back(*std::move(archive));
}
}
// get hash of distdir content