summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_engine/executor
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-08-01 10:26:13 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-08-01 19:00:47 +0200
commit03f948f4b10e916052a2234448b6658b80ee9143 (patch)
tree8eb0e2c26a31fd83fa0691b0d8fde55a15942a9d /src/buildtool/execution_engine/executor
parented71beee3e3a2bbfcba24281ad9e28a0f6df4054 (diff)
downloadjustbuild-03f948f4b10e916052a2234448b6658b80ee9143.tar.gz
Execution API: support cwd
... following the remote-execution standard that all output paths (but none of the input paths) are relative to the working directory. Therefore, the executor has to do the path translation. For our implementation of the API interface - the local API now handles cwd correctly, - the remote API forwards cwd correctly, and - the git API continues to report actions as not implemented.
Diffstat (limited to 'src/buildtool/execution_engine/executor')
-rw-r--r--src/buildtool/execution_engine/executor/TARGETS1
-rw-r--r--src/buildtool/execution_engine/executor/executor.hpp39
2 files changed, 29 insertions, 11 deletions
diff --git a/src/buildtool/execution_engine/executor/TARGETS b/src/buildtool/execution_engine/executor/TARGETS
index bac83670..15ca2441 100644
--- a/src/buildtool/execution_engine/executor/TARGETS
+++ b/src/buildtool/execution_engine/executor/TARGETS
@@ -19,6 +19,7 @@
, ["src/buildtool/execution_api/remote", "bazel"]
, ["src/buildtool/progress_reporting", "progress"]
, ["src/utils/cpp", "hex_string"]
+ , ["src/utils/cpp", "path_rebase"]
, ["src/utils/cpp", "prefix"]
, ["@", "gsl", "", "gsl"]
, ["src/buildtool/common", "common"]
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp
index 6541fe24..bf107e31 100644
--- a/src/buildtool/execution_engine/executor/executor.hpp
+++ b/src/buildtool/execution_engine/executor/executor.hpp
@@ -46,6 +46,7 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/utils/cpp/hex_string.hpp"
+#include "src/utils/cpp/path_rebase.hpp"
#include "src/utils/cpp/prefix.hpp"
/// \brief Implementations for executing actions and uploading artifacts.
@@ -125,11 +126,17 @@ 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 remote_action = (alternative_api ? *alternative_api : api)
.CreateAction(*root_digest,
action->Command(),
- action->OutputFilePaths(),
- action->OutputDirPaths(),
+ base,
+ cwd_relative_output_files,
+ cwd_relative_output_dirs,
action->Env(),
merged_properties);
@@ -477,11 +484,16 @@ class ExecutorImpl {
IExecutionResponse::ArtifactInfos const& artifacts,
gsl::not_null<DependencyGraph::ActionNode const*> const& action,
bool fail_artifacts) noexcept {
+ auto base = action->Content().Cwd();
for (auto const& [name, node] : action->OutputFiles()) {
- node->Content().SetObjectInfo(artifacts.at(name), fail_artifacts);
+ node->Content().SetObjectInfo(
+ artifacts.at(RebasePathStringRelativeTo(base, name)),
+ fail_artifacts);
}
for (auto const& [name, node] : action->OutputDirs()) {
- node->Content().SetObjectInfo(artifacts.at(name), fail_artifacts);
+ node->Content().SetObjectInfo(
+ artifacts.at(RebasePathStringRelativeTo(base, name)),
+ fail_artifacts);
}
}
@@ -507,11 +519,14 @@ class ExecutorImpl {
/// are present in the artifacts map
[[nodiscard]] static auto CheckOutputsExist(
IExecutionResponse::ArtifactInfos const& artifacts,
- std::vector<Action::LocalPath> const& outputs) noexcept -> bool {
- return std::all_of(
- outputs.begin(), outputs.end(), [&artifacts](auto const& output) {
- return artifacts.contains(output);
- });
+ std::vector<Action::LocalPath> 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));
+ });
}
/// \brief Parse response and write object info to DAG's artifact nodes.
@@ -566,8 +581,10 @@ class ExecutorImpl {
auto output_dirs = action->OutputDirPaths();
if (artifacts.empty() or
- not CheckOutputsExist(artifacts, output_files) or
- not CheckOutputsExist(artifacts, output_dirs)) {
+ not CheckOutputsExist(
+ artifacts, output_files, action->Content().Cwd()) or
+ not CheckOutputsExist(
+ artifacts, output_dirs, action->Content().Cwd())) {
logger.Emit(LogLevel::Error, [&] {
std::string message{
"action executed with missing outputs.\n"