diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/execution_api/local/TARGETS | 7 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/config.hpp | 65 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_action.cpp | 3 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 44 | ||||
-rw-r--r-- | src/other_tools/just_mr/TARGETS | 1 | ||||
-rw-r--r-- | src/other_tools/just_mr/fetch.cpp | 9 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup.cpp | 9 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup_utils.cpp | 16 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup_utils.hpp | 5 |
9 files changed, 106 insertions, 53 deletions
diff --git a/src/buildtool/execution_api/local/TARGETS b/src/buildtool/execution_api/local/TARGETS index 2c848bf7..53b7f717 100644 --- a/src/buildtool/execution_api/local/TARGETS +++ b/src/buildtool/execution_api/local/TARGETS @@ -5,14 +5,9 @@ , "deps": [ ["@", "fmt", "", "fmt"] , ["@", "json", "", "json"] - , ["@", "gsl", "", "gsl"] - , ["src/buildtool/common", "common"] - , ["src/buildtool/file_system", "file_system_manager"] - , ["src/buildtool/file_system", "object_type"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] - , ["src/buildtool/execution_api/remote", "config"] - , ["src/buildtool/compatibility", "compatibility"] + , ["src/utils/cpp", "expected"] ] , "stage": ["src", "buildtool", "execution_api", "local"] } diff --git a/src/buildtool/execution_api/local/config.hpp b/src/buildtool/execution_api/local/config.hpp index 92d6606a..f2c8bf57 100644 --- a/src/buildtool/execution_api/local/config.hpp +++ b/src/buildtool/execution_api/local/config.hpp @@ -15,49 +15,56 @@ #ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_CONFIG_HPP #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_CONFIG_HPP -#include <filesystem> -#include <functional> +#include <exception> +#include <optional> #include <string> +#include <utility> // std::move #include <vector> -#include "gsl/gsl" +#include "fmt/core.h" #include "nlohmann/json.hpp" -#include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/file_system/file_system_manager.hpp" -#include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/utils/cpp/expected.hpp" -/// \brief Store global build system configuration. -class LocalExecutionConfig { +/// \brief Store local execution configuration. +struct LocalExecutionConfig final { + class Builder; + + // Launcher to be prepended to action's command before executed. + // Default: ["env", "--"] + std::vector<std::string> const launcher = {"env", "--"}; +}; + +class LocalExecutionConfig::Builder final { public: - [[nodiscard]] static auto SetLauncher( - std::vector<std::string> const& launcher) noexcept -> bool { - try { - Instance().launcher_ = launcher; - } catch (std::exception const& e) { - Logger::Log(LogLevel::Error, - "when setting the local launcher\n{}", - e.what()); - return false; - } - return true; + auto SetLauncher(std::vector<std::string> launcher) noexcept -> Builder& { + launcher_ = std::move(launcher); + return *this; } - [[nodiscard]] static auto GetLauncher() noexcept - -> std::vector<std::string> { - return Instance().launcher_; - } + /// \brief Finalize building and create LocalExecutionConfig. + /// \return LocalExecutionConfig on success, an error string on failure. + [[nodiscard]] auto Build() const noexcept + -> expected<LocalExecutionConfig, std::string> { + // To not duplicate default arguments in builder, create a default + // config and copy arguments from there. + LocalExecutionConfig const default_config; + auto launcher = default_config.launcher; + if (launcher_.has_value()) { + try { + launcher = *launcher_; + } catch (std::exception const& ex) { + return unexpected{ + fmt::format("Failed to set launcher:\n{}", ex.what())}; + } + } - [[nodiscard]] static auto Instance() noexcept -> LocalExecutionConfig& { - static LocalExecutionConfig config; - return config; + return LocalExecutionConfig{.launcher = std::move(launcher)}; } private: - // Launcher to be prepended to action's command before executed. - // Default: ["env", "--"] - std::vector<std::string> launcher_ = {"env", "--"}; + std::optional<std::vector<std::string>> launcher_; }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_CONFIG_HPP diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index 73d78e36..b44fbd5c 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -165,7 +165,8 @@ auto LocalAction::Run(bazel_re::Digest const& action_id) const noexcept return std::nullopt; } - auto cmdline = exec_config_.GetLauncher(); + // prepare actual command by including the launcher + auto cmdline = exec_config_.launcher; std::copy(cmdline_.begin(), cmdline_.end(), std::back_inserter(cmdline)); SystemCommand system{"LocalExecution"}; diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index c42b83a3..36f03345 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -118,16 +118,25 @@ void SetupLogging(LogArguments const& clargs) { } #ifndef BOOTSTRAP_BUILD_TOOL -void SetupExecutionConfig(EndpointArguments const& eargs, - BuildArguments const& bargs, - RebuildArguments const& rargs) { - using LocalConfig = LocalExecutionConfig; - using RemoteConfig = RemoteExecutionConfig; - if (bargs.local_launcher and - not LocalConfig::SetLauncher(*bargs.local_launcher)) { - Logger::Log(LogLevel::Error, "Failed to configure local execution."); - std::exit(kExitFailure); +[[nodiscard]] auto CreateLocalExecutionConfig( + BuildArguments const& bargs) noexcept + -> std::optional<LocalExecutionConfig> { + LocalExecutionConfig::Builder builder; + if (bargs.local_launcher.has_value()) { + builder.SetLauncher(*bargs.local_launcher); + } + + auto config = builder.Build(); + if (config) { + return *std::move(config); } + Logger::Log(LogLevel::Error, config.error()); + return std::nullopt; +} + +void SetupRemoteExecutionConfig(EndpointArguments const& eargs, + RebuildArguments const& rargs) { + using RemoteConfig = RemoteExecutionConfig; for (auto const& property : eargs.platform_properties) { if (not RemoteConfig::AddPlatformProperty(property)) { Logger::Log(LogLevel::Error, @@ -781,8 +790,13 @@ auto main(int argc, char* argv[]) -> int { SetupHashFunction(); SetupFileChunker(); - SetupExecutionConfig( - arguments.endpoint, arguments.build, arguments.rebuild); + + auto local_exec_config = CreateLocalExecutionConfig(arguments.build); + if (not local_exec_config) { + return kExitFailure; + } + + SetupRemoteExecutionConfig(arguments.endpoint, arguments.rebuild); auto serve_config = CreateServeConfig( arguments.serve, arguments.common, arguments.build, arguments.tc); @@ -822,7 +836,7 @@ auto main(int argc, char* argv[]) -> int { SetupExecutionServiceConfig(arguments.service); ApiBundle const exec_apis{&*storage_config, &storage, - &LocalExecutionConfig::Instance(), + &*local_exec_config, /*repo_config=*/nullptr, &*auth_config, RemoteExecutionConfig::RemoteAddress()}; @@ -851,7 +865,7 @@ auto main(int argc, char* argv[]) -> int { ApiBundle const serve_apis{ &*storage_config, &storage, - &LocalExecutionConfig::Instance(), + &*local_exec_config, /*repo_config=*/nullptr, &*auth_config, RemoteExecutionConfig::RemoteAddress()}; @@ -861,7 +875,7 @@ auto main(int argc, char* argv[]) -> int { return serve_server->Run(*serve_config, *storage_config, storage, - LocalExecutionConfig::Instance(), + *local_exec_config, serve, serve_apis, with_execute) @@ -922,7 +936,7 @@ auto main(int argc, char* argv[]) -> int { } ApiBundle const main_apis{&*storage_config, &storage, - &LocalExecutionConfig::Instance(), + &*local_exec_config, &repo_config, &*auth_config, RemoteExecutionConfig::RemoteAddress()}; diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS index 560a08f6..3b4a3df6 100644 --- a/src/other_tools/just_mr/TARGETS +++ b/src/other_tools/just_mr/TARGETS @@ -87,6 +87,7 @@ [ ["src/buildtool/auth", "auth"] , ["src/buildtool/build_engine/expression", "expression_ptr_interface"] , ["src/buildtool/build_engine/expression", "expression"] + , ["src/buildtool/execution_api/local", "config"] , ["src/buildtool/serve_api/remote", "config"] , "cli" ] diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp index 6b247e7c..44b9bdb1 100644 --- a/src/other_tools/just_mr/fetch.cpp +++ b/src/other_tools/just_mr/fetch.cpp @@ -407,9 +407,16 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, return kExitConfigError; } + // setup local execution + auto local_exec_config = + JustMR::Utils::CreateLocalExecutionConfig(common_args); + if (not local_exec_config) { + return kExitConfigError; + } + ApiBundle const apis{&storage_config, &storage, - &LocalExecutionConfig::Instance(), + &*local_exec_config, /*repo_config=*/nullptr, &*auth_config, RemoteExecutionConfig::RemoteAddress()}; diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp index 10c15312..6cf5eaa6 100644 --- a/src/other_tools/just_mr/setup.cpp +++ b/src/other_tools/just_mr/setup.cpp @@ -126,9 +126,16 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, return std::nullopt; } + // setup local execution + auto local_exec_config = + JustMR::Utils::CreateLocalExecutionConfig(common_args); + if (not local_exec_config) { + return std::nullopt; + } + ApiBundle const apis{&storage_config, &storage, - &LocalExecutionConfig::Instance(), + &*local_exec_config, /*repo_config=*/nullptr, &*auth_config, RemoteExecutionConfig::RemoteAddress()}; diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp index 2c219d95..ae6f5a28 100644 --- a/src/other_tools/just_mr/setup_utils.cpp +++ b/src/other_tools/just_mr/setup_utils.cpp @@ -217,6 +217,22 @@ auto CreateAuthConfig(MultiRepoRemoteAuthArguments const& authargs) noexcept return Auth{}; } +auto CreateLocalExecutionConfig(MultiRepoCommonArguments const& cargs) noexcept + -> std::optional<LocalExecutionConfig> { + + LocalExecutionConfig::Builder builder; + if (cargs.local_launcher.has_value()) { + builder.SetLauncher(*cargs.local_launcher); + } + + auto config = builder.Build(); + if (config) { + return *std::move(config); + } + Logger::Log(LogLevel::Error, config.error()); + return std::nullopt; +} + void SetupRemoteConfig( std::optional<std::string> const& remote_exec_addr, std::optional<std::string> const& remote_serve_addr) noexcept { diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp index 3043855c..f96ca81e 100644 --- a/src/other_tools/just_mr/setup_utils.hpp +++ b/src/other_tools/just_mr/setup_utils.hpp @@ -24,6 +24,7 @@ #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/build_engine/expression/expression_ptr.hpp" +#include "src/buildtool/execution_api/local/config.hpp" #include "src/buildtool/serve_api/remote/config.hpp" #include "src/other_tools/just_mr/cli.hpp" @@ -65,6 +66,10 @@ void DefaultReachableRepositories( MultiRepoRemoteAuthArguments const& authargs) noexcept -> std::optional<Auth>; +[[nodiscard]] auto CreateLocalExecutionConfig( + MultiRepoCommonArguments const& cargs) noexcept + -> std::optional<LocalExecutionConfig>; + void SetupRemoteConfig( std::optional<std::string> const& remote_exec_addr, std::optional<std::string> const& remote_serve_addr) noexcept; |