From d65d711f844224dcf9215c52be8f69fd2885adfc Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 17 Apr 2025 13:18:37 +0200 Subject: profile: also honor action cwd In all presentations of actions to the user, we use output paths relative to the root of the action directory. Therefore, we should do the same in the profile. However, when noting the completion of an action, we get paths as in the wire protocol, i.e., relative to the working directory of the action. Therefore, rebase appropriately. --- src/buildtool/execution_engine/executor/executor.hpp | 7 +++++-- src/buildtool/profile/TARGETS | 1 + src/buildtool/profile/profile.cpp | 17 ++++++++++++++--- src/buildtool/profile/profile.hpp | 3 ++- 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index 7015f559..d47397f0 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -928,7 +928,9 @@ class Executor { context_.progress); if (context_.profile) { (*context_.profile) - ->NoteActionCompleted(action->Content().Id(), *response); + ->NoteActionCompleted(action->Content().Id(), + *response, + action->Content().Cwd()); } return result; } @@ -956,7 +958,8 @@ class Executor { logger, *response, action, context_.statistics, context_.progress); if (context_.profile) { (*context_.profile) - ->NoteActionCompleted(action->Content().Id(), *response); + ->NoteActionCompleted( + action->Content().Id(), *response, action->Content().Cwd()); } return result; } diff --git a/src/buildtool/profile/TARGETS b/src/buildtool/profile/TARGETS index 318ed075..7906c2b4 100644 --- a/src/buildtool/profile/TARGETS +++ b/src/buildtool/profile/TARGETS @@ -13,6 +13,7 @@ , ["src/buildtool/common", "cli"] , ["src/buildtool/common", "common"] , ["src/utils/cpp", "expected"] + , ["src/utils/cpp", "path_rebase"] ] , "stage": ["src", "buildtool", "profile"] } diff --git a/src/buildtool/profile/profile.cpp b/src/buildtool/profile/profile.cpp index 4655ccf4..bc0560cf 100644 --- a/src/buildtool/profile/profile.cpp +++ b/src/buildtool/profile/profile.cpp @@ -20,6 +20,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/cli.hpp" #include "src/utils/cpp/expected.hpp" +#include "src/utils/cpp/path_rebase.hpp" void Profile::Write(int exit_code) { if (not actions_.empty()) { @@ -96,7 +97,8 @@ void Profile::SetCLI(CommandLineArguments const& cli) { } void Profile::NoteActionCompleted(std::string const& id, - IExecutionResponse::Ptr const& response) { + IExecutionResponse::Ptr const& response, + std::string const& cwd) { std::unique_lock lock{mutex_}; auto artifacts = response->Artifacts(); std::optional out = std::nullopt; @@ -131,8 +133,17 @@ void Profile::NoteActionCompleted(std::string const& id, .err = err, .artifacts = std::unordered_map( (*artifacts)->size())}; - for (auto const& [k, v] : **artifacts) { - actions_[id].artifacts.emplace(k, v.digest.hash()); + if (cwd.empty()) { + // the typical case of empty cwd, avoid unnecessary calls + for (auto const& [k, v] : **artifacts) { + actions_[id].artifacts.emplace(k, v.digest.hash()); + } + } + else { + for (auto const& [k, v] : **artifacts) { + actions_[id].artifacts.emplace( + RebasePathStringRelativeTo(cwd, k), v.digest.hash()); + } } } } diff --git a/src/buildtool/profile/profile.hpp b/src/buildtool/profile/profile.hpp index 82a23a94..9067a309 100644 --- a/src/buildtool/profile/profile.hpp +++ b/src/buildtool/profile/profile.hpp @@ -38,7 +38,8 @@ class Profile { void SetTarget(nlohmann::json target); void SetConfiguration(nlohmann::json configuration); void NoteActionCompleted(std::string const& id, - IExecutionResponse::Ptr const& response); + IExecutionResponse::Ptr const& response, + std::string const& cwd); private: struct ActionData { -- cgit v1.2.3