summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/local/local_action.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-07-09 15:28:37 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-12 15:13:52 +0200
commitf0ac970bac223f64e287d9b28f75b0d8da7de706 (patch)
treec0a0675d862bc382519ff41d454fb4365dc53f54 /src/buildtool/execution_api/local/local_action.cpp
parent5057bd9e9a55fd8423ad7112086a3cafd3162e2c (diff)
downloadjustbuild-f0ac970bac223f64e287d9b28f75b0d8da7de706.tar.gz
Return std::nullopt if creation of an action digest fails
...instead of dereferencing nullptr.
Diffstat (limited to 'src/buildtool/execution_api/local/local_action.cpp')
-rw-r--r--src/buildtool/execution_api/local/local_action.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp
index 4b8bc0dc..94d98d6b 100644
--- a/src/buildtool/execution_api/local/local_action.cpp
+++ b/src/buildtool/execution_api/local/local_action.cpp
@@ -17,7 +17,6 @@
#include <algorithm>
#include <cstddef>
#include <filesystem>
-#include <optional>
#include <string>
#include <system_error>
#include <utility>
@@ -86,6 +85,14 @@ auto LocalAction::Execute(Logger const* logger) noexcept
-> IExecutionResponse::Ptr {
auto do_cache = CacheEnabled(cache_flag_);
auto action = CreateActionDigest(root_digest_, not do_cache);
+ if (not action) {
+ if (logger != nullptr) {
+ logger->Emit(LogLevel::Error,
+ "failed to create an action digest for {}",
+ root_digest_.hash());
+ }
+ return nullptr;
+ }
if (logger != nullptr) {
logger->Emit(LogLevel::Trace,
@@ -93,16 +100,16 @@ auto LocalAction::Execute(Logger const* logger) noexcept
" - exec_dir digest: {}\n"
" - action digest: {}",
root_digest_.hash(),
- NativeSupport::Unprefix(action.hash()));
+ NativeSupport::Unprefix(action->hash()));
}
if (do_cache) {
- if (auto result = storage_.ActionCache().CachedResult(action)) {
+ if (auto result = storage_.ActionCache().CachedResult(*action)) {
if (result->exit_code() == 0 and
ActionResultContainsExpectedOutputs(
*result, output_files_, output_dirs_)) {
return IExecutionResponse::Ptr{
- new LocalResponse{action.hash(),
+ new LocalResponse{action->hash(),
{std::move(*result), /*is_cached=*/true},
&storage_}};
}
@@ -110,16 +117,26 @@ auto LocalAction::Execute(Logger const* logger) noexcept
}
if (ExecutionEnabled(cache_flag_)) {
- if (auto output = Run(action)) {
+ if (auto output = Run(*action)) {
if (cache_flag_ == CacheFlag::PretendCached) {
// ensure the same id is created as if caching were enabled
- auto action_id = CreateActionDigest(root_digest_, false).hash();
+ auto action_cached = CreateActionDigest(root_digest_, false);
+ if (not action_cached) {
+ if (logger != nullptr) {
+ logger->Emit(
+ LogLevel::Error,
+ "failed to create a cached action digest for {}",
+ root_digest_.hash());
+ }
+ return nullptr;
+ }
+
output->is_cached = true;
return IExecutionResponse::Ptr{new LocalResponse{
- std::move(action_id), std::move(*output), &storage_}};
+ action_cached->hash(), std::move(*output), &storage_}};
}
return IExecutionResponse::Ptr{new LocalResponse{
- action.hash(), std::move(*output), &storage_}};
+ action->hash(), std::move(*output), &storage_}};
}
}