summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/local
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/execution_api/local')
-rw-r--r--src/buildtool/execution_api/local/TARGETS7
-rw-r--r--src/buildtool/execution_api/local/config.hpp65
-rw-r--r--src/buildtool/execution_api/local/local_action.cpp3
3 files changed, 39 insertions, 36 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"};