diff options
-rw-r--r-- | src/buildtool/common/remote/TARGETS | 7 | ||||
-rw-r--r-- | src/buildtool/common/remote/remote_common.hpp | 63 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/TARGETS | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/config.hpp | 45 | ||||
-rw-r--r-- | src/buildtool/graph_traverser/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/graph_traverser/graph_traverser.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/config.hpp | 20 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.hpp | 3 |
11 files changed, 98 insertions, 55 deletions
diff --git a/src/buildtool/common/remote/TARGETS b/src/buildtool/common/remote/TARGETS index daf7afc2..97966431 100644 --- a/src/buildtool/common/remote/TARGETS +++ b/src/buildtool/common/remote/TARGETS @@ -22,4 +22,11 @@ ] , "stage": ["src", "buildtool", "common", "remote"] } +, "remote_common": + { "type": ["@", "rules", "CC", "library"] + , "name": ["remote_common"] + , "hdrs": ["remote_common.hpp"] + , "deps": [["@", "fmt", "", "fmt"], ["@", "json", "", "json"], "port"] + , "stage": ["src", "buildtool", "common", "remote"] + } } diff --git a/src/buildtool/common/remote/remote_common.hpp b/src/buildtool/common/remote/remote_common.hpp new file mode 100644 index 00000000..e8ce2ed7 --- /dev/null +++ b/src/buildtool/common/remote/remote_common.hpp @@ -0,0 +1,63 @@ +// 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_BUILDTOOL_COMMON_REMOTE_ADDRESS_HPP +#define INCLUDED_SRC_BUILDTOOL_COMMON_REMOTE_ADDRESS_HPP + +#include <optional> +#include <sstream> +#include <string> + +#include <fmt/core.h> +#include <nlohmann/json.hpp> + +#include "src/buildtool/common/remote/port.hpp" + +struct ServerAddress { + std::string host{}; + Port port{}; + + [[nodiscard]] auto ToJson() const noexcept -> nlohmann::json { + return nlohmann::json{ + fmt::format("{}:{}", host, static_cast<std::uint16_t>(port))}; + } +}; + +[[nodiscard]] static auto ParseAddress(std::string const& address) noexcept + -> std::optional<ServerAddress> { + std::istringstream iss(address); + std::string host; + std::string port; + if (not std::getline(iss, host, ':') or not std::getline(iss, port, ':')) { + return std::nullopt; + } + auto port_num = ParsePort(port); + if (not host.empty() and port_num) { + return ServerAddress{std::move(host), *port_num}; + } + return std::nullopt; +} + +[[nodiscard]] static auto ParseProperty(std::string const& property) noexcept + -> std::optional<std::pair<std::string, std::string>> { + std::istringstream pss(property); + std::string key; + std::string val; + if (not std::getline(pss, key, ':') or not std::getline(pss, val, ':')) { + return std::nullopt; + } + return std::make_pair(key, val); +} + +#endif // INCLUDED_SRC_BUILDTOOL_COMMON_REMOTE_ADDRESS_HPP diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS index 234050ce..8543db0d 100644 --- a/src/buildtool/execution_api/remote/TARGETS +++ b/src/buildtool/execution_api/remote/TARGETS @@ -72,11 +72,7 @@ , "name": ["config"] , "hdrs": ["config.hpp"] , "srcs": ["config.cpp"] - , "deps": - [ ["@", "fmt", "", "fmt"] - , ["@", "json", "", "json"] - , ["src/buildtool/common/remote", "port"] - ] + , "deps": [["src/buildtool/common/remote", "remote_common"]] , "stage": ["src", "buildtool", "execution_api", "remote"] } } diff --git a/src/buildtool/execution_api/remote/config.hpp b/src/buildtool/execution_api/remote/config.hpp index e7ad3a57..bad729ab 100644 --- a/src/buildtool/execution_api/remote/config.hpp +++ b/src/buildtool/execution_api/remote/config.hpp @@ -19,29 +19,15 @@ #include <filesystem> #include <map> #include <optional> -#include <sstream> #include <stdexcept> #include <string> #include <utility> #include <vector> -#include <fmt/core.h> -#include <nlohmann/json.hpp> - -#include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/common/remote/remote_common.hpp" class RemoteExecutionConfig { public: - struct ServerAddress { - std::string host{}; - Port port{}; - - [[nodiscard]] auto ToJson() const noexcept -> nlohmann::json { - return nlohmann::json{ - fmt::format("{}:{}", host, static_cast<std::uint16_t>(port))}; - } - }; - // Obtain global instance [[nodiscard]] static auto Instance() noexcept -> RemoteExecutionConfig& { static RemoteExecutionConfig config; @@ -114,35 +100,6 @@ class RemoteExecutionConfig { // Platform properties for execution. std::map<std::string, std::string> platform_properties_{}; - - [[nodiscard]] static auto ParseAddress(std::string const& address) noexcept - -> std::optional<ServerAddress> { - std::istringstream iss(address); - std::string host; - std::string port; - if (not std::getline(iss, host, ':') or - not std::getline(iss, port, ':')) { - return std::nullopt; - } - auto port_num = ParsePort(port); - if (not host.empty() and port_num) { - return ServerAddress{std::move(host), *port_num}; - } - return std::nullopt; - } - - [[nodiscard]] static auto ParseProperty( - std::string const& property) noexcept - -> std::optional<std::pair<std::string, std::string>> { - std::istringstream pss(property); - std::string key; - std::string val; - if (not std::getline(pss, key, ':') or - not std::getline(pss, val, ':')) { - return std::nullopt; - } - return std::make_pair(key, val); - } }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP diff --git a/src/buildtool/graph_traverser/TARGETS b/src/buildtool/graph_traverser/TARGETS index b9911633..51b0a653 100644 --- a/src/buildtool/graph_traverser/TARGETS +++ b/src/buildtool/graph_traverser/TARGETS @@ -5,6 +5,7 @@ , "deps": [ ["src/buildtool/common", "cli"] , ["src/buildtool/common", "tree"] + , ["src/buildtool/common/remote", "remote_common"] , ["src/buildtool/execution_engine/dag", "dag"] , ["src/buildtool/execution_engine/executor", "executor"] , ["src/buildtool/execution_engine/traverser", "traverser"] diff --git a/src/buildtool/graph_traverser/graph_traverser.hpp b/src/buildtool/graph_traverser/graph_traverser.hpp index 9f99e6f2..8567395e 100644 --- a/src/buildtool/graph_traverser/graph_traverser.hpp +++ b/src/buildtool/graph_traverser/graph_traverser.hpp @@ -30,6 +30,7 @@ #include "fmt/core.h" #include "gsl/gsl" #include "src/buildtool/common/cli.hpp" +#include "src/buildtool/common/remote/remote_common.hpp" #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/common/tree.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" @@ -270,7 +271,7 @@ class GraphTraverser { } [[nodiscard]] static auto CreateExecutionApi( - std::optional<RemoteExecutionConfig::ServerAddress> const& address) + std::optional<ServerAddress> const& address) -> gsl::not_null<IExecutionApi::Ptr> { if (address) { ExecutionConfiguration config; diff --git a/src/buildtool/serve_api/remote/TARGETS b/src/buildtool/serve_api/remote/TARGETS index 71f82b82..45114f57 100644 --- a/src/buildtool/serve_api/remote/TARGETS +++ b/src/buildtool/serve_api/remote/TARGETS @@ -2,7 +2,7 @@ { "type": ["@", "rules", "CC", "library"] , "name": ["config"] , "hdrs": ["config.hpp"] - , "deps": [["src/buildtool/execution_api/remote", "config"]] + , "deps": [["src/buildtool/common/remote", "remote_common"]] , "stage": ["src", "buildtool", "serve_api", "remote"] } , "serve_target_level_cache_client": diff --git a/src/buildtool/serve_api/remote/config.hpp b/src/buildtool/serve_api/remote/config.hpp index dac7fabf..6ea927cb 100644 --- a/src/buildtool/serve_api/remote/config.hpp +++ b/src/buildtool/serve_api/remote/config.hpp @@ -16,9 +16,9 @@ #include <iterator> #include <vector> -#include "src/buildtool/execution_api/remote/config.hpp" +#include "src/buildtool/common/remote/remote_common.hpp" -class RemoteServeConfig : public RemoteExecutionConfig { +class RemoteServeConfig { public: // Obtain global instance [[nodiscard]] static auto Instance() noexcept -> RemoteServeConfig& { @@ -26,6 +26,13 @@ class RemoteServeConfig : public RemoteExecutionConfig { return config; } + // Set remote execution and cache address, unsets if parsing `address` fails + [[nodiscard]] static auto SetRemoteAddress( + std::string const& address) noexcept -> bool { + auto& inst = Instance(); + return static_cast<bool>(inst.remote_address_ = ParseAddress(address)); + } + // Set the list of known repositories [[nodiscard]] static auto SetKnownRepositories( std::vector<std::filesystem::path> const& repos) noexcept -> bool { @@ -36,6 +43,12 @@ class RemoteServeConfig : public RemoteExecutionConfig { return repos.size() == inst.repositories_.size(); } + // Remote execution address, if set + [[nodiscard]] static auto RemoteAddress() noexcept + -> std::optional<ServerAddress> { + return Instance().remote_address_; + } + // Repositories known to 'just serve' [[nodiscard]] static auto KnownRepositories() noexcept -> const std::vector<std::filesystem::path>& { @@ -43,6 +56,9 @@ class RemoteServeConfig : public RemoteExecutionConfig { } private: + // Server address of remote execution. + std::optional<ServerAddress> remote_address_{}; + // Known Git repositories to serve server. std::vector<std::filesystem::path> repositories_{}; }; diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS index ec94ee76..dae08d35 100644 --- a/src/buildtool/serve_api/serve_service/TARGETS +++ b/src/buildtool/serve_api/serve_service/TARGETS @@ -14,6 +14,7 @@ , "proto": ["just_serve_proto"] , "deps": [ ["src/buildtool/logging", "logging"] + , ["src/buildtool/common/remote", "remote_common"] , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/execution_api/remote", "config"] ] diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp index 8d91c2f5..69a7a607 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.cpp +++ b/src/buildtool/serve_api/serve_service/source_tree.cpp @@ -25,7 +25,7 @@ #include "src/buildtool/storage/config.hpp" auto SourceTreeService::CreateExecutionApi( - std::optional<RemoteExecutionConfig::ServerAddress> const& address) + std::optional<ServerAddress> const& address) -> gsl::not_null<IExecutionApi::Ptr> { if (address) { ExecutionConfiguration config; diff --git a/src/buildtool/serve_api/serve_service/source_tree.hpp b/src/buildtool/serve_api/serve_service/source_tree.hpp index a1599508..0bdf48b8 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.hpp +++ b/src/buildtool/serve_api/serve_service/source_tree.hpp @@ -23,6 +23,7 @@ #include "gsl/gsl" #include "justbuild/just_serve/just_serve.grpc.pb.h" +#include "src/buildtool/common/remote/remote_common.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/logging/logger.hpp" @@ -57,7 +58,7 @@ class SourceTreeService final CreateExecutionApi(std::nullopt)}; [[nodiscard]] static auto CreateExecutionApi( - std::optional<RemoteExecutionConfig::ServerAddress> const& address) + std::optional<ServerAddress> const& address) -> gsl::not_null<IExecutionApi::Ptr>; [[nodiscard]] static auto GetTreeFromCommit( |