From f0ac970bac223f64e287d9b28f75b0d8da7de706 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 9 Jul 2024 15:28:37 +0200 Subject: Return std::nullopt if creation of an action digest fails ...instead of dereferencing nullptr. --- src/buildtool/execution_api/local/local_action.cpp | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/buildtool/execution_api/local/local_action.cpp') 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 #include #include -#include #include #include #include @@ -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_}}; } } -- cgit v1.2.3