summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-03 11:32:41 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-14 13:35:01 +0100
commite1cb494e522d352f8d06d4f210a4d1dfbf3a890c (patch)
tree677cf3f35943f6241ca2e26d1b80a77989b60f58 /src
parent180abedbc498bd8b5efc19ad068bc0a5704559b2 (diff)
downloadjustbuild-e1cb494e522d352f8d06d4f210a4d1dfbf3a890c.tar.gz
just-mr: Parse mirrors specification from checkout locations file
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/just_mr/TARGETS11
-rw-r--r--src/other_tools/just_mr/cli.hpp2
-rw-r--r--src/other_tools/just_mr/main.cpp8
-rw-r--r--src/other_tools/just_mr/mirrors.hpp29
4 files changed, 47 insertions, 3 deletions
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index a3ed87c9..d98d2e60 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -66,11 +66,11 @@
, ["src/buildtool/common", "clidefaults"]
, ["src/buildtool/common", "user_structs"]
, ["src/buildtool/execution_api/local", "config"]
- , ["src/other_tools/just_mr", "utils"]
, ["src/buildtool/logging", "log_level"]
+ , "mirrors"
+ , "utils"
]
, "stage": ["src", "other_tools", "just_mr"]
- , "private-deps": [["src/buildtool/logging", "logging"]]
}
, "setup_utils":
{ "type": ["@", "rules", "CC", "library"]
@@ -186,4 +186,11 @@
, "setup_utils"
]
}
+, "mirrors":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["mirrors"]
+ , "hdrs": ["mirrors.hpp"]
+ , "deps": [["@", "json", "", "json"]]
+ , "stage": ["src", "other_tools", "just_mr"]
+ }
}
diff --git a/src/other_tools/just_mr/cli.hpp b/src/other_tools/just_mr/cli.hpp
index adc72578..0031cd4e 100644
--- a/src/other_tools/just_mr/cli.hpp
+++ b/src/other_tools/just_mr/cli.hpp
@@ -29,6 +29,7 @@
#include "src/buildtool/common/user_structs.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
#include "src/buildtool/logging/log_level.hpp"
+#include "src/other_tools/just_mr/mirrors.hpp"
#include "src/other_tools/just_mr/utils.hpp"
/// \brief Arguments common to all just-mr subcommands
@@ -38,6 +39,7 @@ struct MultiRepoCommonArguments {
std::optional<std::filesystem::path> checkout_locations_file{std::nullopt};
std::vector<std::string> explicit_distdirs{};
LocalPathsPtr just_mr_paths = std::make_shared<LocalPaths>();
+ MirrorsPtr alternative_mirrors = std::make_shared<Mirrors>();
std::optional<std::vector<std::string>> local_launcher{std::nullopt};
CAInfoPtr ca_info = std::make_shared<CAInfo>();
std::optional<std::filesystem::path> just_path{std::nullopt};
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp
index 1e8905d6..47ec2633 100644
--- a/src/other_tools/just_mr/main.cpp
+++ b/src/other_tools/just_mr/main.cpp
@@ -676,7 +676,7 @@ auto main(int argc, char* argv[]) -> int {
kDefaultDistdirs);
}
- // read checkout locations
+ // read checkout locations and alternative mirrors
if (arguments.common.checkout_locations_file) {
try {
std::ifstream ifs(*arguments.common.checkout_locations_file);
@@ -685,6 +685,12 @@ auto main(int argc, char* argv[]) -> int {
checkout_locations_json
.value("checkouts", nlohmann::json::object())
.value("git", nlohmann::json::object());
+ arguments.common.alternative_mirrors->local_mirrors =
+ checkout_locations_json.value("local mirrors",
+ nlohmann::json::object());
+ arguments.common.alternative_mirrors->preferred_hostnames =
+ checkout_locations_json.value("preferred hostnames",
+ nlohmann::json::array());
} catch (std::exception const& e) {
Logger::Log(
LogLevel::Error,
diff --git a/src/other_tools/just_mr/mirrors.hpp b/src/other_tools/just_mr/mirrors.hpp
new file mode 100644
index 00000000..d59300c5
--- /dev/null
+++ b/src/other_tools/just_mr/mirrors.hpp
@@ -0,0 +1,29 @@
+// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_OTHER_TOOLS_JUST_MR_MIRRORS_HPP
+#define INCLUDED_SRC_OTHER_TOOLS_JUST_MR_MIRRORS_HPP
+
+#include <memory>
+
+#include "nlohmann/json.hpp"
+
+struct Mirrors {
+ nlohmann::json local_mirrors{}; // maps URLs to list of local mirrors
+ nlohmann::json preferred_hostnames{}; // list of mirror hostnames
+};
+
+using MirrorsPtr = std::shared_ptr<Mirrors>;
+
+#endif // INCLUDED_SRC_OTHER_TOOLS_JUST_MR_MIRRORS_HPP