diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-30 18:59:11 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-02-16 17:22:22 +0100 |
commit | 08f3b06e3f6d5d702e754e8809b3c2e3cee73066 (patch) | |
tree | 4b3b2cd5533b58cb528d52e710c84231c6c61ca8 /src/buildtool/main/build_utils.hpp | |
parent | cfa8c2a41e8a585834e4d04d56ff7eec0d57f608 (diff) | |
download | justbuild-08f3b06e3f6d5d702e754e8809b3c2e3cee73066.tar.gz |
export targets: Enforce the invariant when writing target cache entries
We ensure that for each export target to be written to the target
cache all its implied export targets are written to the target
cache first. This ensures that the target cache maintains its
consistency at all times with respect to export target
dependencies.
Diffstat (limited to 'src/buildtool/main/build_utils.hpp')
-rw-r--r-- | src/buildtool/main/build_utils.hpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/buildtool/main/build_utils.hpp b/src/buildtool/main/build_utils.hpp index 116ef1a9..cf1c68ec 100644 --- a/src/buildtool/main/build_utils.hpp +++ b/src/buildtool/main/build_utils.hpp @@ -15,6 +15,7 @@ #ifndef INCLUDED_SRC_BUILDOOL_MAIN_BUILD_UTILS_HPP #define INCLUDED_SRC_BUILDOOL_MAIN_BUILD_UTILS_HPP +#include <functional> #include <map> #include <optional> #include <string> @@ -27,7 +28,9 @@ #ifndef BOOTSTRAP_BUILD_TOOL #include "gsl/gsl" #include "src/buildtool/common/artifact.hpp" +#include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" +#include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/storage/storage.hpp" #include "src/buildtool/storage/target_cache.hpp" #endif // BOOTSTRAP_BUILD_TOOL @@ -53,6 +56,29 @@ auto ToTargetCacheWriteStrategy(std::string const&) -> std::optional<TargetCacheWriteStrategy>; #ifndef BOOTSTRAP_BUILD_TOOL +/// \brief Maps the Id of a TargetCacheKey to nullptr_t, as we only care if +/// writing the tc entry succeeds or not. +using TargetCacheWriterMap = + AsyncMapConsumer<Artifact::ObjectInfo, std::nullptr_t>; + +/// \brief Handles the writing of target cache keys after analysis concludes. +[[nodiscard]] auto CreateTargetCacheWriterMap( + std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets, + std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const& + extra_infos, + std::size_t jobs, + gsl::not_null<IExecutionApi*> const& local_api, + gsl::not_null<IExecutionApi*> const& remote_api, + TargetCacheWriteStrategy strategy = TargetCacheWriteStrategy::Sync, + TargetCache<true> const& tc = Storage::Instance().TargetCache()) + -> TargetCacheWriterMap; + +// use explicit cast to std::function to allow template deduction when used +static const std::function<std::string(Artifact::ObjectInfo const&)> + kObjectInfoPrinter = [](Artifact::ObjectInfo const& x) -> std::string { + return x.ToString(); +}; + void WriteTargetCacheEntries( std::unordered_map<TargetCacheKey, AnalysedTargetPtr> const& cache_targets, std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const& |