diff options
Diffstat (limited to 'src/buildtool/serve_api')
4 files changed, 18 insertions, 20 deletions
diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp index 98966e6a..510881cb 100644 --- a/src/buildtool/serve_api/remote/serve_api.hpp +++ b/src/buildtool/serve_api/remote/serve_api.hpp @@ -37,10 +37,8 @@ class ServeApi final {}; class ServeApi final { public: - [[nodiscard]] static auto Instance() noexcept -> ServeApi const& { - static ServeApi instance = ServeApi::init(); - return instance; - } + explicit ServeApi(ServerAddress const& address) noexcept + : stc_{address}, tc_{address}, cc_{address} {} ~ServeApi() noexcept = default; ServeApi(ServeApi const&) = delete; @@ -48,6 +46,15 @@ class ServeApi final { auto operator=(ServeApi const&) -> ServeApi& = delete; auto operator=(ServeApi&&) -> ServeApi& = delete; + [[nodiscard]] static auto Create( + RemoteServeConfig const& serve_config) noexcept + -> std::optional<ServeApi> { + if (auto address = serve_config.RemoteAddress()) { + return std::make_optional<ServeApi>(*address); + } + return std::nullopt; + } + [[nodiscard]] auto RetrieveTreeFromCommit(std::string const& commit, std::string const& subdir = ".", bool sync_tree = false) @@ -130,14 +137,6 @@ class ServeApi final { } private: - explicit ServeApi(ServerAddress const& address) noexcept - : stc_{address}, tc_{address}, cc_{address} {} - - [[nodiscard]] static auto init() noexcept -> ServeApi { - auto sadd = RemoteServeConfig::Instance().RemoteAddress(); - return ServeApi{*sadd}; - } - // source tree service client SourceTreeClient const stc_; // target service client diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp index b8b092f8..b588fc45 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp @@ -60,10 +60,9 @@ auto TryWrite(std::string const& file, T const& content) noexcept -> bool { } } // namespace -auto ServeServerImpl::Run( - RemoteServeConfig const& serve_config, - std::optional<gsl::not_null<const ServeApi*>> const& serve, - bool with_execute) -> bool { +auto ServeServerImpl::Run(RemoteServeConfig const& serve_config, + std::optional<ServeApi> const& serve, + bool with_execute) -> bool { // make sure the git root directory is properly initialized if (not FileSystemManager::CreateDirectory(StorageConfig::GitRoot())) { Logger::Log(LogLevel::Error, diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp index f9eea2f6..b3c0ee51 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp @@ -55,7 +55,7 @@ class ServeServerImpl { /// \param with_execute Flag specifying if just serve should act also as /// just execute (i.e., start remote execution services with same interface) auto Run(RemoteServeConfig const& serve_config, - std::optional<gsl::not_null<const ServeApi*>> const& serve, + std::optional<ServeApi> const& serve, bool with_execute) -> bool; ~ServeServerImpl() = default; diff --git a/src/buildtool/serve_api/serve_service/target.hpp b/src/buildtool/serve_api/serve_service/target.hpp index 7e94c919..171ac42b 100644 --- a/src/buildtool/serve_api/serve_service/target.hpp +++ b/src/buildtool/serve_api/serve_service/target.hpp @@ -40,8 +40,8 @@ class TargetService final : public justbuild::just_serve::Target::Service { public: TargetService(RemoteServeConfig const& serve_config, - std::optional<gsl::not_null<const ServeApi*>> serve) noexcept - : serve_config_{serve_config}, serve_(std::move(serve)) {} + std::optional<ServeApi> const& serve) noexcept + : serve_config_{serve_config}, serve_(serve) {} // Given a target-level caching key, returns the computed value. In doing // so, it can build on the associated endpoint passing the @@ -120,7 +120,7 @@ class TargetService final : public justbuild::just_serve::Target::Service { private: RemoteServeConfig const& serve_config_; - std::optional<gsl::not_null<const ServeApi*>> serve_; + std::optional<ServeApi> const& serve_; std::shared_ptr<Logger> logger_{std::make_shared<Logger>("target-service")}; // type of dispatch list; reduces verbosity |