summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/bazel_msg/TARGETS2
-rw-r--r--src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp68
-rw-r--r--src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp59
-rw-r--r--src/buildtool/execution_api/local/local_action.hpp23
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_action.cpp32
5 files changed, 93 insertions, 91 deletions
diff --git a/src/buildtool/execution_api/bazel_msg/TARGETS b/src/buildtool/execution_api/bazel_msg/TARGETS
index 0e66a685..cc14a0df 100644
--- a/src/buildtool/execution_api/bazel_msg/TARGETS
+++ b/src/buildtool/execution_api/bazel_msg/TARGETS
@@ -28,11 +28,11 @@
, ["src/buildtool/common", "bazel_types"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
+ , ["@", "gsl", "", "gsl"]
]
, "private-deps":
[ ["src/buildtool/compatibility", "compatibility"]
, ["src/utils/cpp", "hex_string"]
- , ["@", "gsl", "", "gsl"]
, ["src/buildtool/file_system", "file_system_manager"]
, ["src/buildtool/file_system", "git_repo"]
]
diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
index 1ce53021..ba564ad8 100644
--- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
+++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
@@ -25,7 +25,6 @@
#include <utility> // std::move
#include <vector>
-#include "gsl/gsl"
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/compatibility/native_support.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
@@ -319,29 +318,24 @@ template <class T>
/// \brief Create bundle for protobuf message Command from args strings.
[[nodiscard]] auto CreateCommandBundle(
- std::vector<std::string> const& args,
- std::vector<std::string> const& output_files,
- std::vector<std::string> const& output_dirs,
- std::vector<bazel_re::Command_EnvironmentVariable> const& env_vars,
- std::vector<bazel_re::Platform_Property> const& platform_properties)
- -> CommandBundle::Ptr {
+ BazelMsgFactory::ActionDigestRequest const& request) -> CommandBundle::Ptr {
bazel_re::Command msg;
// DEPRECATED as of v2.2: platform properties are now specified
// directly in the action. See documentation note in the
// [Action][build.bazel.remote.execution.v2.Action] for migration.
// (https://github.com/bazelbuild/remote-apis/blob/e1fe21be4c9ae76269a5a63215bb3c72ed9ab3f0/build/bazel/remote/execution/v2/remote_execution.proto#L646)
- msg.set_allocated_platform(CreatePlatform(platform_properties).release());
- std::copy(std::cbegin(args),
- std::cend(args),
+ msg.set_allocated_platform(CreatePlatform(*request.properties).release());
+ std::copy(request.command_line->begin(),
+ request.command_line->end(),
pb::back_inserter(msg.mutable_arguments()));
- std::copy(std::cbegin(output_files),
- std::cend(output_files),
+ std::copy(request.output_files->begin(),
+ request.output_files->end(),
pb::back_inserter(msg.mutable_output_files()));
- std::copy(std::cbegin(output_dirs),
- std::cend(output_dirs),
+ std::copy(request.output_dirs->begin(),
+ request.output_dirs->end(),
pb::back_inserter(msg.mutable_output_directories()));
- std::copy(std::cbegin(env_vars),
- std::cend(env_vars),
+ std::copy(request.env_vars->begin(),
+ request.env_vars->end(),
pb::back_inserter(msg.mutable_environment_variables()));
auto content_creator = [&msg] { return SerializeMessage(msg); };
@@ -356,32 +350,29 @@ template <class T>
/// \brief Create bundle for protobuf message Action from Command.
[[nodiscard]] auto CreateActionBundle(
bazel_re::Digest const& command,
- bazel_re::Digest const& root_dir,
- std::vector<bazel_re::Platform_Property> const& platform_properties,
- bool do_not_cache,
- std::chrono::milliseconds const& timeout) -> ActionBundle::Ptr {
+ BazelMsgFactory::ActionDigestRequest const& request) -> ActionBundle::Ptr {
using seconds = std::chrono::seconds;
using nanoseconds = std::chrono::nanoseconds;
- auto sec = std::chrono::duration_cast<seconds>(timeout);
- auto nanos = std::chrono::duration_cast<nanoseconds>(timeout - sec);
+ auto sec = std::chrono::duration_cast<seconds>(request.timeout);
+ auto nanos = std::chrono::duration_cast<nanoseconds>(request.timeout - sec);
auto duration = std::make_unique<google::protobuf::Duration>();
duration->set_seconds(sec.count());
duration->set_nanos(nanos.count());
bazel_re::Action msg;
- msg.set_do_not_cache(do_not_cache);
+ msg.set_do_not_cache(request.skip_action_cache);
msg.set_allocated_timeout(duration.release());
msg.set_allocated_command_digest(
gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{command}});
msg.set_allocated_input_root_digest(
- gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{root_dir}});
+ gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{*request.exec_dir}});
// New in version 2.2: clients SHOULD set these platform properties
// as well as those in the
// [Command][build.bazel.remote.execution.v2.Command]. Servers
// SHOULD prefer those set here.
// (https://github.com/bazelbuild/remote-apis/blob/e1fe21be4c9ae76269a5a63215bb3c72ed9ab3f0/build/bazel/remote/execution/v2/remote_execution.proto#L516)
- msg.set_allocated_platform(CreatePlatform(platform_properties).release());
+ msg.set_allocated_platform(CreatePlatform(*request.properties).release());
auto content_creator = [&msg] { return SerializeMessage(msg); };
@@ -651,26 +642,13 @@ auto BazelMsgFactory::CreateGitTreeDigestFromLocalTree(
}
auto BazelMsgFactory::CreateActionDigestFromCommandLine(
- std::vector<std::string> const& cmdline,
- bazel_re::Digest const& exec_dir,
- std::vector<std::string> const& output_files,
- std::vector<std::string> const& output_dirs,
- std::vector<bazel_re::Command_EnvironmentVariable> const& env_vars,
- std::vector<bazel_re::Platform_Property> const& properties,
- bool do_not_cache,
- std::chrono::milliseconds const& timeout,
- std::optional<BlobStoreFunc> const& store_blob) -> bazel_re::Digest {
- // create command
- auto cmd = CreateCommandBundle(
- cmdline, output_files, output_dirs, env_vars, properties);
-
- // create action
- auto action = CreateActionBundle(
- cmd->Digest(), exec_dir, properties, do_not_cache, timeout);
-
- if (store_blob) {
- (*store_blob)(cmd->MakeBlob(/*is_exec=*/false));
- (*store_blob)(action->MakeBlob(/*is_exec=*/false));
+ ActionDigestRequest const& request) -> bazel_re::Digest {
+ auto cmd = CreateCommandBundle(request);
+ auto action = CreateActionBundle(cmd->Digest(), request);
+
+ if (request.store_blob) {
+ (*request.store_blob)(cmd->MakeBlob(/*is_exec=*/false));
+ (*request.store_blob)(action->MakeBlob(/*is_exec=*/false));
}
return action->Digest();
diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp
index 0a07806d..ff61e9f3 100644
--- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp
+++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
+#include "gsl/gsl"
#include "src/buildtool/common/artifact.hpp"
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/common/bazel_types.hpp"
@@ -40,8 +41,6 @@ class BazelMsgFactory {
public:
/// \brief Store or otherwise process a blob. Returns success flag.
using BlobProcessFunc = std::function<bool(BazelBlob&&)>;
- /// \brief Store blob.
- using BlobStoreFunc = std::function<void(BazelBlob&&)>;
using LinkDigestResolveFunc =
std::function<void(std::vector<bazel_re::Digest> const&,
std::vector<std::string>*)>;
@@ -92,31 +91,13 @@ class BazelMsgFactory {
SymlinkStoreFunc const& store_symlink) noexcept
-> std::optional<bazel_re::Digest>;
+ struct ActionDigestRequest;
/// \brief Creates Action digest from command line.
/// As part of the internal process, it creates an ActionBundle and
/// CommandBundle that can be captured via BlobStoreFunc.
- /// \param[in] cmdline The command line.
- /// \param[in] exec_dir The Digest of the execution directory.
- /// \param[in] output_files The paths of output files.
- /// \param[in] output_dirs The paths of output directories.
- /// \param[in] output_node. The output node's properties.
- /// \param[in] env_vars The environment variables set.
- /// \param[in] properties The target platform's properties.
- /// \param[in] do_not_cache Skip action cache.
- /// \param[in] timeout The command execution timeout.
- /// \param[in] store_blob Function for storing action and cmd bundles.
/// \returns Digest representing the action.
[[nodiscard]] static auto CreateActionDigestFromCommandLine(
- std::vector<std::string> const& cmdline,
- bazel_re::Digest const& exec_dir,
- std::vector<std::string> const& output_files,
- std::vector<std::string> const& output_dirs,
- std::vector<bazel_re::Command_EnvironmentVariable> const& env_vars,
- std::vector<bazel_re::Platform_Property> const& properties,
- bool do_not_cache,
- std::chrono::milliseconds const& timeout,
- std::optional<BlobStoreFunc> const& store_blob = std::nullopt)
- -> bazel_re::Digest;
+ ActionDigestRequest const& request) -> bazel_re::Digest;
/// \brief Create message vector from std::map.
/// \param[in] input map
@@ -152,4 +133,38 @@ class BazelMsgFactory {
}
};
+struct BazelMsgFactory::ActionDigestRequest final {
+ using BlobStoreFunc = std::function<void(BazelBlob&&)>;
+
+ template <typename T>
+ using VectorPtr = gsl::not_null<std::vector<T> const*>;
+
+ /// \brief The command line.
+ VectorPtr<std::string> const command_line;
+
+ /// \brief The paths of output files.
+ VectorPtr<std::string> const output_files;
+
+ /// \brief The paths of output directories.
+ VectorPtr<std::string> const output_dirs;
+
+ /// \brief The environment variables set.
+ VectorPtr<bazel_re::Command_EnvironmentVariable> const env_vars;
+
+ /// \brief The target platform's properties.
+ VectorPtr<bazel_re::Platform_Property> const properties;
+
+ /// \brief The Digest of the execution directory.
+ gsl::not_null<bazel_re::Digest const*> const exec_dir;
+
+ /// \brief The command execution timeout.
+ std::chrono::milliseconds const timeout;
+
+ /// \brief Skip action cache.
+ bool skip_action_cache;
+
+ /// \brief Function for storing action and cmd bundles.
+ std::optional<BlobStoreFunc> const store_blob = std::nullopt;
+};
+
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_BAZEL_MSG_BAZEL_MSG_FACTORY_HPP
diff --git a/src/buildtool/execution_api/local/local_action.hpp b/src/buildtool/execution_api/local/local_action.hpp
index a6c69b29..7999da33 100644
--- a/src/buildtool/execution_api/local/local_action.hpp
+++ b/src/buildtool/execution_api/local/local_action.hpp
@@ -98,16 +98,19 @@ class LocalAction final : public IExecutionAction {
[[nodiscard]] auto CreateActionDigest(bazel_re::Digest const& exec_dir,
bool do_not_cache)
-> bazel_re::Digest {
- return BazelMsgFactory::CreateActionDigestFromCommandLine(
- cmdline_,
- exec_dir,
- output_files_,
- output_dirs_,
- BazelMsgFactory::CreateMessageVectorFromMap<
- bazel_re::Command_EnvironmentVariable>(env_vars_),
- properties_,
- do_not_cache,
- timeout_);
+ auto const env_vars = BazelMsgFactory::CreateMessageVectorFromMap<
+ bazel_re::Command_EnvironmentVariable>(env_vars_);
+
+ BazelMsgFactory::ActionDigestRequest request{
+ .command_line = &cmdline_,
+ .output_files = &output_files_,
+ .output_dirs = &output_dirs_,
+ .env_vars = &env_vars,
+ .properties = &properties_,
+ .exec_dir = &exec_dir,
+ .timeout = timeout_,
+ .skip_action_cache = do_not_cache};
+ return BazelMsgFactory::CreateActionDigestFromCommandLine(request);
}
[[nodiscard]] auto Run(bazel_re::Digest const& action_id) const noexcept
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_action.cpp b/src/buildtool/execution_api/remote/bazel/bazel_action.cpp
index f96f4774..74634838 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_action.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_action.cpp
@@ -14,6 +14,7 @@
#include "src/buildtool/execution_api/remote/bazel/bazel_action.hpp"
+#include <optional>
#include <utility> // std::move
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
@@ -95,17 +96,22 @@ auto BazelAction::CreateBundlesForAction(BazelBlobContainer* blobs,
bazel_re::Digest const& exec_dir,
bool do_not_cache) const noexcept
-> bazel_re::Digest {
- return BazelMsgFactory::CreateActionDigestFromCommandLine(
- cmdline_,
- exec_dir,
- output_files_,
- output_dirs_,
- env_vars_,
- properties_,
- do_not_cache,
- timeout_,
- blobs == nullptr ? std::nullopt
- : std::make_optional([&blobs](BazelBlob&& blob) {
- blobs->Emplace(std::move(blob));
- }));
+ using StoreFunc = BazelMsgFactory::ActionDigestRequest::BlobStoreFunc;
+ std::optional<StoreFunc> store_blob = std::nullopt;
+ if (blobs != nullptr) {
+ store_blob = [&blobs](BazelBlob&& blob) {
+ blobs->Emplace(std::move(blob));
+ };
+ }
+ BazelMsgFactory::ActionDigestRequest request{
+ .command_line = &cmdline_,
+ .output_files = &output_files_,
+ .output_dirs = &output_dirs_,
+ .env_vars = &env_vars_,
+ .properties = &properties_,
+ .exec_dir = &exec_dir,
+ .timeout = timeout_,
+ .skip_action_cache = do_not_cache,
+ .store_blob = std::move(store_blob)};
+ return BazelMsgFactory::CreateActionDigestFromCommandLine(request);
}