summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_engine/dag/TARGETS1
-rw-r--r--src/buildtool/execution_engine/dag/dag.hpp37
-rw-r--r--src/buildtool/execution_engine/executor/TARGETS1
-rw-r--r--src/buildtool/execution_engine/executor/executor.hpp40
4 files changed, 39 insertions, 40 deletions
diff --git a/src/buildtool/execution_engine/dag/TARGETS b/src/buildtool/execution_engine/dag/TARGETS
index e6d581b1..5b385d48 100644
--- a/src/buildtool/execution_engine/dag/TARGETS
+++ b/src/buildtool/execution_engine/dag/TARGETS
@@ -6,6 +6,7 @@
, "deps":
[ ["src/utils/cpp", "hex_string"]
, ["src/utils/cpp", "type_safe_arithmetic"]
+ , ["src/utils/cpp", "transformed_range"]
, ["src/buildtool/common", "common"]
, ["src/buildtool/common", "action_description"]
, ["src/buildtool/common", "artifact_description"]
diff --git a/src/buildtool/execution_engine/dag/dag.hpp b/src/buildtool/execution_engine/dag/dag.hpp
index 7e2194ff..a61143f6 100644
--- a/src/buildtool/execution_engine/dag/dag.hpp
+++ b/src/buildtool/execution_engine/dag/dag.hpp
@@ -37,6 +37,7 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/hex_string.hpp"
+#include "src/utils/cpp/transformed_range.hpp"
#include "src/utils/cpp/type_safe_arithmetic.hpp"
/// \brief Plain DirectedAcyclicGraph.
@@ -262,6 +263,9 @@ class DependencyGraph : DirectedAcyclicGraph {
Action::LocalPath path;
base::OtherNodePtr node;
};
+ using LocalPaths =
+ TransformedRange<std::vector<NamedOtherNodePtr>::const_iterator,
+ Action::LocalPath>;
[[nodiscard]] static auto Create(Action const& content) noexcept
-> Ptr {
@@ -357,19 +361,16 @@ class DependencyGraph : DirectedAcyclicGraph {
return Content().NoCache();
}
- [[nodiscard]] auto OutputFilePaths() const noexcept
- -> std::vector<Action::LocalPath> {
- return NodePaths(output_files_);
+ [[nodiscard]] auto OutputFilePaths() const& noexcept -> LocalPaths {
+ return NodePaths(&output_files_);
}
- [[nodiscard]] auto OutputDirPaths() const noexcept
- -> std::vector<Action::LocalPath> {
- return NodePaths(output_dirs_);
+ [[nodiscard]] auto OutputDirPaths() const& noexcept -> LocalPaths {
+ return NodePaths(&output_dirs_);
}
- [[nodiscard]] auto DependencyPaths() const noexcept
- -> std::vector<Action::LocalPath> {
- return NodePaths(dependencies_);
+ [[nodiscard]] auto DependencyPaths() const& noexcept -> LocalPaths {
+ return NodePaths(&dependencies_);
}
// To initialise the action traversal specific data before traversing
@@ -390,19 +391,13 @@ class DependencyGraph : DirectedAcyclicGraph {
std::unique_ptr<ActionNodeTraversalState> traversal_state_{
std::make_unique<ActionNodeTraversalState>()};
- // Collect paths from named nodes.
- // TODO(oreiche): This could be potentially speed up by using a wrapper
- // iterator to provide a read-only view (similar to BazelBlobContainer)
[[nodiscard]] static auto NodePaths(
- std::vector<NamedOtherNodePtr> const& nodes)
- -> std::vector<Action::LocalPath> {
- std::vector<Action::LocalPath> paths{nodes.size()};
- std::transform(
- nodes.cbegin(),
- nodes.cend(),
- paths.begin(),
- [](auto const& named_node) { return named_node.path; });
- return paths;
+ gsl::not_null<std::vector<NamedOtherNodePtr> const*> const& nodes)
+ -> LocalPaths {
+ return TransformedRange{
+ nodes->begin(),
+ nodes->end(),
+ [](NamedOtherNodePtr const& node) { return node.path; }};
}
};
diff --git a/src/buildtool/execution_engine/executor/TARGETS b/src/buildtool/execution_engine/executor/TARGETS
index eabbb371..e2d1a7b4 100644
--- a/src/buildtool/execution_engine/executor/TARGETS
+++ b/src/buildtool/execution_engine/executor/TARGETS
@@ -23,6 +23,7 @@
, ["src/utils/cpp", "hex_string"]
, ["src/utils/cpp", "path_rebase"]
, ["src/utils/cpp", "prefix"]
+ , ["src/utils/cpp", "transformed_range"]
, ["@", "gsl", "", "gsl"]
, ["src/buildtool/common", "common"]
, ["src/buildtool/crypto", "hash_function"]
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp
index 097284e1..c9914ab6 100644
--- a/src/buildtool/execution_engine/executor/executor.hpp
+++ b/src/buildtool/execution_engine/executor/executor.hpp
@@ -50,6 +50,7 @@
#include "src/utils/cpp/hex_string.hpp"
#include "src/utils/cpp/path_rebase.hpp"
#include "src/utils/cpp/prefix.hpp"
+#include "src/utils/cpp/transformed_range.hpp"
/// \brief Implementations for executing actions and uploading artifacts.
class ExecutorImpl {
@@ -129,10 +130,10 @@ class ExecutorImpl {
}
auto base = action->Content().Cwd();
- auto cwd_relative_output_files =
- RebasePathStringsRelativeTo(base, action->OutputFilePaths());
- auto cwd_relative_output_dirs =
- RebasePathStringsRelativeTo(base, action->OutputDirPaths());
+ auto cwd_relative_output_files = RebasePathStringsRelativeTo(
+ base, action->OutputFilePaths().ToVector());
+ auto cwd_relative_output_dirs = RebasePathStringsRelativeTo(
+ base, action->OutputDirPaths().ToVector());
auto remote_action = (alternative_api ? *alternative_api : api)
.CreateAction(*root_digest,
action->Command(),
@@ -535,14 +536,15 @@ class ExecutorImpl {
/// are present in the artifacts map
[[nodiscard]] static auto CheckOutputsExist(
IExecutionResponse::ArtifactInfos const& artifacts,
- std::vector<Action::LocalPath> const& outputs,
+ DependencyGraph::ActionNode::LocalPaths const& outputs,
std::string base) noexcept -> bool {
- return std::all_of(outputs.begin(),
- outputs.end(),
- [&artifacts, &base](auto const& output) {
- return artifacts.contains(
- RebasePathStringRelativeTo(base, output));
- });
+ return std::all_of(
+ outputs.begin(),
+ outputs.end(),
+ [&artifacts, &base](Action::LocalPath const& output) {
+ return artifacts.contains(
+ RebasePathStringRelativeTo(base, output));
+ });
}
/// \brief Parse response and write object info to DAG's artifact nodes.
@@ -597,22 +599,22 @@ class ExecutorImpl {
logger.Emit(LogLevel::Error, artifacts.error());
return false;
}
- auto output_files = action->OutputFilePaths();
- auto output_dirs = action->OutputDirPaths();
if (artifacts.value()->empty() or
- not CheckOutputsExist(
- *artifacts.value(), output_files, action->Content().Cwd()) or
- not CheckOutputsExist(
- *artifacts.value(), output_dirs, action->Content().Cwd())) {
+ not CheckOutputsExist(*artifacts.value(),
+ action->OutputFilePaths(),
+ action->Content().Cwd()) or
+ not CheckOutputsExist(*artifacts.value(),
+ action->OutputDirPaths(),
+ action->Content().Cwd())) {
logger.Emit(LogLevel::Error, [&] {
std::string message{
"action executed with missing outputs.\n"
" Action outputs should be the following artifacts:"};
- for (auto const& output : output_files) {
+ for (auto const& output : action->OutputFilePaths()) {
message += "\n - file: " + output;
}
- for (auto const& output : output_dirs) {
+ for (auto const& output : action->OutputDirPaths()) {
message += "\n - dir: " + output;
}
return message;