diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/main/main.cpp | 20 | ||||
-rw-r--r-- | src/buildtool/main/serve.cpp | 54 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/config.hpp | 44 |
3 files changed, 116 insertions, 2 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 6fd8dded..4f874da0 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -134,7 +134,9 @@ void SetupExecutionConfig(EndpointArguments const& eargs, } } -void SetupServeConfig(ServeArguments const& srvargs) { +void SetupServeConfig(ServeArguments const& srvargs, + CommonArguments const& cargs, + BuildArguments const& bargs) { if (srvargs.remote_serve_address) { if (not RemoteServeConfig::SetRemoteAddress( *srvargs.remote_serve_address)) { @@ -165,6 +167,20 @@ void SetupServeConfig(ServeArguments const& srvargs) { "Setting serve service repositories failed."); std::exit(kExitFailure); } + // make parallelism and build options available for remote builds + if (not RemoteServeConfig::SetJobs(cargs.jobs)) { + Logger::Log(LogLevel::Error, "Setting jobs failed."); + std::exit(kExitFailure); + } + if (bargs.build_jobs > 0 and + not RemoteServeConfig::SetBuildJobs(bargs.build_jobs)) { + Logger::Log(LogLevel::Error, "Setting build jobs failed."); + std::exit(kExitFailure); + } + if (not RemoteServeConfig::SetActionTimeout(bargs.timeout)) { + Logger::Log(LogLevel::Error, "Setting action timeout failed."); + std::exit(kExitFailure); + } } void SetupAuthConfig(CommonAuthArguments const& authargs, @@ -814,7 +830,7 @@ auto main(int argc, char* argv[]) -> int { SetupHashFunction(); SetupExecutionConfig( arguments.endpoint, arguments.build, arguments.rebuild); - SetupServeConfig(arguments.serve); + SetupServeConfig(arguments.serve, arguments.common, arguments.build); SetupAuthConfig(arguments.auth, arguments.cauth, arguments.sauth); if (arguments.cmd == SubCommand::kGc) { diff --git a/src/buildtool/main/serve.cpp b/src/buildtool/main/serve.cpp index 74d78bdc..1c079032 100644 --- a/src/buildtool/main/serve.cpp +++ b/src/buildtool/main/serve.cpp @@ -14,6 +14,8 @@ #include "src/buildtool/main/serve.hpp" +#include <chrono> + #ifndef BOOTSTRAP_BUILD_TOOL #include <fstream> @@ -346,6 +348,58 @@ void ReadJustServeConfig(gsl::not_null<CommandLineArguments*> const& clargs) { clargs->endpoint.remote_execution_address = address->String(); } } + // read jobs value + auto jobs = serve_config["jobs"]; + if (jobs.IsNotNull()) { + if (not jobs->IsNumber()) { + Logger::Log(LogLevel::Error, + "just serve: configuration-file provided jobs has to " + "be a number, but found {}", + jobs->ToString()); + std::exit(kExitFailure); + } + clargs->common.jobs = jobs->Number(); + } + // read build options + auto build_args = serve_config["build"]; + if (build_args.IsNotNull()) { + if (not build_args->IsMap()) { + Logger::Log(LogLevel::Error, + "just-serve: configuration-file provided build " + "arguments has to be a map, but found {}", + build_args->ToString()); + std::exit(kExitFailure); + } + // read the build jobs + auto build_jobs = build_args->Get("build jobs", Expression::none_t{}); + if (build_jobs.IsNotNull()) { + if (not build_jobs->IsNumber()) { + Logger::Log( + LogLevel::Error, + "just serve: configuration-file provided build jobs " + "has to be a number, but found {}", + build_jobs->ToString()); + std::exit(kExitFailure); + } + clargs->build.build_jobs = build_jobs->Number(); + } + else { + clargs->build.build_jobs = clargs->common.jobs; + } + // read action timeout + auto timeout = build_args->Get("action timeout", Expression::none_t{}); + if (timeout.IsNotNull()) { + if (not timeout->IsNumber()) { + Logger::Log(LogLevel::Error, + "just serve: configuration-file provided action " + "timeout has to be a number, but found {}", + timeout->ToString()); + std::exit(kExitFailure); + } + clargs->build.timeout = + std::size_t(timeout->Number()) * std::chrono::seconds{1}; + } + } } #endif // BOOTSTRAP_BUILD_TOOL diff --git a/src/buildtool/serve_api/remote/config.hpp b/src/buildtool/serve_api/remote/config.hpp index 02461167..94f00f8e 100644 --- a/src/buildtool/serve_api/remote/config.hpp +++ b/src/buildtool/serve_api/remote/config.hpp @@ -15,6 +15,7 @@ #ifndef INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_CONFIG_HPP #define INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_CONFIG_HPP +#include <chrono> #include <filesystem> #include <iterator> #include <vector> @@ -46,6 +47,24 @@ class RemoteServeConfig { return repos.size() == inst.repositories_.size(); } + // Set the number of jobs + [[nodiscard]] static auto SetJobs(std::size_t jobs) noexcept -> bool { + return static_cast<bool>(Instance().jobs_ = jobs); + } + + // Set the number of build jobs + [[nodiscard]] static auto SetBuildJobs(std::size_t build_jobs) noexcept + -> bool { + return static_cast<bool>(Instance().build_jobs_ = build_jobs); + } + + // Set the action timeout + [[nodiscard]] static auto SetActionTimeout( + std::chrono::milliseconds const& timeout) noexcept -> bool { + Instance().timeout_ = timeout; + return Instance().timeout_ > std::chrono::seconds{0}; + } + // Remote execution address, if set [[nodiscard]] static auto RemoteAddress() noexcept -> std::optional<ServerAddress> { @@ -58,12 +77,37 @@ class RemoteServeConfig { return Instance().repositories_; } + // Get the number of jobs + [[nodiscard]] static auto Jobs() noexcept -> std::size_t { + return Instance().jobs_; + } + + // Get the number of build jobs + [[nodiscard]] static auto BuildJobs() noexcept -> std::size_t { + return Instance().build_jobs_; + } + + // Get the action timeout + [[nodiscard]] static auto ActionTimeout() noexcept + -> std::chrono::milliseconds { + return Instance().timeout_; + } + private: // Server address of remote execution. std::optional<ServerAddress> remote_address_{}; // Known Git repositories to serve server. std::vector<std::filesystem::path> repositories_{}; + + // Number of jobs + std::size_t jobs_{}; + + // Number of build jobs + std::size_t build_jobs_{}; + + // Action timeout + std::chrono::milliseconds timeout_{}; }; #endif // INCLUDED_SRC_BUILDTOOL_SERVE_API_REMOTE_CONFIG_HPP |