From 619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 22 Feb 2022 17:03:21 +0100 Subject: Initial self-hosting commit This is the initial version of our tool that is able to build itself. In can be bootstrapped by ./bin/bootstrap.py Co-authored-by: Oliver Reiche Co-authored-by: Victor Moreno --- src/buildtool/execution_api/remote/config.hpp | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/buildtool/execution_api/remote/config.hpp (limited to 'src/buildtool/execution_api/remote/config.hpp') diff --git a/src/buildtool/execution_api/remote/config.hpp b/src/buildtool/execution_api/remote/config.hpp new file mode 100644 index 00000000..e29b8aa7 --- /dev/null +++ b/src/buildtool/execution_api/remote/config.hpp @@ -0,0 +1,72 @@ +#ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP +#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gsl-lite/gsl-lite.hpp" +#include "src/buildtool/logging/logger.hpp" + +class RemoteExecutionConfig { + public: + [[nodiscard]] static auto ParseAddress(std::string const& address) noexcept + -> std::optional> { + 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; + } + try { + return std::make_pair(host, std::stoi(port)); + } catch (std::out_of_range const& e) { + Logger::Log(LogLevel::Error, "Port raised out_of_range exception."); + return std::nullopt; + } catch (std::invalid_argument const& e) { + Logger::Log(LogLevel::Error, + "Port raised invalid_argument exception."); + return std::nullopt; + } + } + + // Obtain global instance + [[nodiscard]] static auto Instance() noexcept -> RemoteExecutionConfig& { + static RemoteExecutionConfig config; + return config; + } + + [[nodiscard]] auto IsValidAddress() const noexcept -> bool { + return valid_; + } + + [[nodiscard]] auto SetAddress(std::string const& address) noexcept -> bool { + auto pair = ParseAddress(address); + return pair and SetAddress(pair->first, pair->second); + } + + [[nodiscard]] auto SetAddress(std::string const& host, int port) noexcept + -> bool { + host_ = host; + port_ = port, + valid_ = (not host.empty() and port >= 0 and port <= kMaxPortNumber); + return valid_; + } + + [[nodiscard]] auto Host() const noexcept -> std::string { return host_; } + [[nodiscard]] auto Port() const noexcept -> int { return port_; } + + private: + static constexpr int kMaxPortNumber{std::numeric_limits::max()}; + std::string host_{}; + int port_{}; + bool valid_{false}; +}; + +#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP -- cgit v1.2.3