diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-30 16:31:00 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-12-05 10:48:10 +0100 |
commit | 4e2986281e3b6b8b5d3649975a7fc621ea884760 (patch) | |
tree | 4a9888f1d35e5bcdd21f6e1b13c0c4286e69d26d /src/buildtool/execution_engine/executor | |
parent | 793396ad5e68dba634350c9c5c3429083254f906 (diff) | |
download | justbuild-4e2986281e3b6b8b5d3649975a7fc621ea884760.tar.gz |
executor: Move helper methods inside ExecutorImpl class
...with appropriate scope depending on where they are called from,
to avoid unnecessary code duplication.
Diffstat (limited to 'src/buildtool/execution_engine/executor')
-rw-r--r-- | src/buildtool/execution_engine/executor/executor.hpp | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index 986d17f8..c4e6c6b7 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -38,49 +38,6 @@ #include "src/buildtool/progress_reporting/progress.hpp" #include "src/utils/cpp/hex_string.hpp" -namespace detail { -static inline auto scale_time(std::chrono::milliseconds t, double f) - -> std::chrono::milliseconds { - return std::chrono::milliseconds(std::lround(t.count() * f)); -} - -static inline auto merge_properties( - const std::map<std::string, std::string>& base, - const std::map<std::string, std::string>& overlay) { - std::map<std::string, std::string> result = base; - for (auto const& [k, v] : overlay) { - result[k] = v; - } - return result; -} - -static inline auto get_alternative_endpoint( - const std::map<std::string, std::string>& properties) - -> std::unique_ptr<BazelApi> { - for (auto const& [pred, endpoint] : RemoteExecutionConfig::DispatchList()) { - bool match = true; - for (auto const& [k, v] : pred) { - auto v_it = properties.find(k); - if (not(v_it != properties.end() and v_it->second == v)) { - match = false; - } - } - if (match) { - Logger::Log(LogLevel::Debug, [endpoint = endpoint] { - return fmt::format("Dispatching action to endpoint {}", - endpoint.ToJson().dump()); - }); - ExecutionConfiguration config; - return std::make_unique<BazelApi>("alternative remote execution", - endpoint.host, - endpoint.port, - config); - } - } - return nullptr; -} -} // namespace detail - /// \brief Implementations for executing actions and uploading artifacts. class ExecutorImpl { public: @@ -137,7 +94,7 @@ class ExecutorImpl { Statistics::Instance().IncrementActionsQueuedCounter(); } - auto alternative_api = detail::get_alternative_endpoint(properties); + auto alternative_api = GetAlternativeEndpoint(properties); if (alternative_api) { if (not api->RetrieveToCas( std::vector<Artifact::ObjectInfo>{Artifact::ObjectInfo{ @@ -633,6 +590,51 @@ class ExecutorImpl { "Failed to execute command {}", nlohmann::json(command).dump()); } + + [[nodiscard]] static inline auto ScaleTime(std::chrono::milliseconds t, + double f) + -> std::chrono::milliseconds { + return std::chrono::milliseconds(std::lround(t.count() * f)); + } + + [[nodiscard]] static inline auto MergeProperties( + const std::map<std::string, std::string>& base, + const std::map<std::string, std::string>& overlay) { + std::map<std::string, std::string> result = base; + for (auto const& [k, v] : overlay) { + result[k] = v; + } + return result; + } + + private: + [[nodiscard]] static inline auto GetAlternativeEndpoint( + const std::map<std::string, std::string>& properties) + -> std::unique_ptr<BazelApi> { + for (auto const& [pred, endpoint] : + RemoteExecutionConfig::DispatchList()) { + bool match = true; + for (auto const& [k, v] : pred) { + auto v_it = properties.find(k); + if (not(v_it != properties.end() and v_it->second == v)) { + match = false; + } + } + if (match) { + Logger::Log(LogLevel::Debug, [endpoint = endpoint] { + return fmt::format("Dispatching action to endpoint {}", + endpoint.ToJson().dump()); + }); + ExecutionConfiguration config; + return std::make_unique<BazelApi>( + "alternative remote execution", + endpoint.host, + endpoint.port, + config); + } + } + return nullptr; + } }; /// \brief Executor for using concrete Execution API. @@ -666,9 +668,8 @@ class Executor { logger, action, remote_api_, - detail::merge_properties(properties_, - action->ExecutionProperties()), - detail::scale_time(timeout_, action->TimeoutScale()), + Impl::MergeProperties(properties_, action->ExecutionProperties()), + Impl::ScaleTime(timeout_, action->TimeoutScale()), action->NoCache() ? CF::DoNotCacheOutput : CF::CacheOutput); // check response and save digests of results @@ -729,9 +730,8 @@ class Rebuilder { logger, action, remote_api_, - detail::merge_properties(properties_, - action->ExecutionProperties()), - detail::scale_time(timeout_, action->TimeoutScale()), + Impl::MergeProperties(properties_, action->ExecutionProperties()), + Impl::ScaleTime(timeout_, action->TimeoutScale()), CF::PretendCached); if (not response) { @@ -743,9 +743,8 @@ class Rebuilder { logger_cached, action, api_cached_, - detail::merge_properties(properties_, - action->ExecutionProperties()), - detail::scale_time(timeout_, action->TimeoutScale()), + Impl::MergeProperties(properties_, action->ExecutionProperties()), + Impl::ScaleTime(timeout_, action->TimeoutScale()), CF::FromCacheOnly); if (not response_cached) { |