diff options
-rw-r--r-- | src/buildtool/profile/TARGETS | 5 | ||||
-rw-r--r-- | src/buildtool/profile/profile.cpp | 24 | ||||
-rw-r--r-- | src/buildtool/profile/profile.hpp | 1 | ||||
-rw-r--r-- | test/end-to-end/profile/basic.sh | 6 |
4 files changed, 34 insertions, 2 deletions
diff --git a/src/buildtool/profile/TARGETS b/src/buildtool/profile/TARGETS index 657758ba..9f4db4d8 100644 --- a/src/buildtool/profile/TARGETS +++ b/src/buildtool/profile/TARGETS @@ -7,6 +7,11 @@ [ ["@", "json", "", "json"] , ["src/buildtool/execution_api/common", "common"] ] + , "private-deps": + [ ["@", "gsl", "", "gsl"] + , ["src/buildtool/common", "common"] + , ["src/utils/cpp", "expected"] + ] , "stage": ["src", "buildtool", "profile"] } } diff --git a/src/buildtool/profile/profile.cpp b/src/buildtool/profile/profile.cpp index 9a7eaf7d..66ea50d6 100644 --- a/src/buildtool/profile/profile.cpp +++ b/src/buildtool/profile/profile.cpp @@ -16,6 +16,10 @@ #include <fstream> +#include "gsl/gsl" +#include "src/buildtool/common/artifact_digest.hpp" +#include "src/utils/cpp/expected.hpp" + void Profile::Write(int exit_code) { if (not output_file_) { return; @@ -29,6 +33,7 @@ void Profile::Write(int exit_code) { if (not v.cached) { entry["duration"] = v.duration; } + entry["artifacts"] = v.artifacts; actions[k] = entry; } profile_["actions"] = actions; @@ -51,6 +56,21 @@ void Profile::SetConfiguration(nlohmann::json configuration) { void Profile::NoteActionCompleted(std::string const& id, IExecutionResponse::Ptr const& response) { std::unique_lock lock{mutex_}; - actions_[id] = ActionData{.cached = response->IsCached(), - .duration = response->ExecutionDuration()}; + auto artifacts = response->Artifacts(); + if (not artifacts) { + actions_[id] = ActionData{ + .cached = response->IsCached(), + .duration = response->ExecutionDuration(), + .artifacts = std::unordered_map<std::string, std::string>()}; + } + else { + actions_[id] = ActionData{ + .cached = response->IsCached(), + .duration = response->ExecutionDuration(), + .artifacts = std::unordered_map<std::string, std::string>( + (*artifacts)->size())}; + for (auto const& [k, v] : **artifacts) { + actions_[id].artifacts.emplace(k, v.digest.hash()); + } + } } diff --git a/src/buildtool/profile/profile.hpp b/src/buildtool/profile/profile.hpp index 60f8f007..7e03b0ae 100644 --- a/src/buildtool/profile/profile.hpp +++ b/src/buildtool/profile/profile.hpp @@ -42,6 +42,7 @@ class Profile { struct ActionData { bool cached; double duration; + std::unordered_map<std::string, std::string> artifacts; }; std::optional<std::string> output_file_; diff --git a/test/end-to-end/profile/basic.sh b/test/end-to-end/profile/basic.sh index aeafb9e7..70ba2b5a 100644 --- a/test/end-to-end/profile/basic.sh +++ b/test/end-to-end/profile/basic.sh @@ -22,6 +22,7 @@ readonly LBR="${TEST_TMPDIR}/local-build-root" readonly LOG_DIR="${PWD}/log" readonly ETC_DIR="${PWD}/etc" readonly WRK_DIR="${PWD}/work" +readonly OUT="${TEST_TMPDIR}/out" # Set up an rc file, requesting invocation logging mkdir -p "${ETC_DIR}" @@ -69,6 +70,11 @@ PROFILE="${INVOCATION_DIR}/profile.json" cat "${PROFILE}" [ $(jq '.actions | .[] | .cached' "${PROFILE}") = "false" ] +OUT_ARTIFACT=$(jq -r '.actions | .[] | .artifacts."upper.txt"' "${PROFILE}") +"${JUST_MR}" --rc "${RC}" install-cas -o "${OUT}/upper.txt" "${OUT_ARTIFACT}" 2>&1 +grep BLABLABLA "${OUT}/upper.txt" +echo + # Build again, this time the action should be cached; # again abuse the project id to distingush the runs cat > rc.json <<'EOF' |