From d22adef666d704680ee74b35a46d530f6b6d5f15 Mon Sep 17 00:00:00 2001 From: Sascha Roloff Date: Fri, 14 Oct 2022 18:10:56 +0200 Subject: Recursively scan provided results for known artifacts This recursive scan of the provided results map of a target-cache entry for known artifacts is required since the serialization format of target results currently does not produce a single flat artifact list, but keeps the result entry structure with a nested list of artifacts. Once the serialization format of target results is changed in a way that a flat list of artifacts is produced, this recursive scan is not required anymore and can be reverted. --- .../build_engine/target_map/target_cache.cpp | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/buildtool/build_engine/target_map/target_cache.cpp') diff --git a/src/buildtool/build_engine/target_map/target_cache.cpp b/src/buildtool/build_engine/target_map/target_cache.cpp index b2f3b209..f1a0c750 100644 --- a/src/buildtool/build_engine/target_map/target_cache.cpp +++ b/src/buildtool/build_engine/target_map/target_cache.cpp @@ -92,6 +92,12 @@ auto TargetCache::Entry::ToResult() const noexcept return true; } +// Function prototype for recursive call in ScanProvidesMap +auto ScanTargetResult( + gsl::not_null*> const& /*infos*/, + nlohmann::json const& /*json*/) -> bool; + +// NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto ScanProvidesMap( gsl::not_null*> const& infos, nlohmann::json const& json) -> bool { @@ -99,6 +105,8 @@ auto TargetCache::Entry::ToResult() const noexcept return false; } auto const& nodes = json["nodes"]; + + // Process provided artifacts auto const& provided_artifacts = json["provided_artifacts"]; infos->reserve(infos->size() + provided_artifacts.size()); std::transform( @@ -108,16 +116,32 @@ auto TargetCache::Entry::ToResult() const noexcept [&nodes](auto const& item) { return ToObjectInfo(nodes[item.template get()]); }); - return true; + + // Process provided results + auto const& provided_results = json["provided_results"]; + return std::all_of(provided_results.begin(), + provided_results.end(), + // NOLINTNEXTLINE(misc-no-recursion) + [&infos, &nodes](auto const& item) { + return ScanTargetResult( + infos, nodes[item.template get()]); + }); +} + +// NOLINTNEXTLINE(misc-no-recursion) +[[nodiscard]] auto ScanTargetResult( + gsl::not_null*> const& infos, + nlohmann::json const& result) -> bool { + return ScanArtifactMap(infos, result["artifacts"]) and + ScanArtifactMap(infos, result["runfiles"]) and + ScanProvidesMap(infos, result["provides"]); } auto TargetCache::Entry::ToArtifacts( gsl::not_null*> const& infos) const noexcept -> bool { try { - if (ScanArtifactMap(infos, desc_["artifacts"]) and - ScanArtifactMap(infos, desc_["runfiles"]) and - ScanProvidesMap(infos, desc_["provides"])) { + if (ScanTargetResult(infos, desc_)) { return true; } } catch (std::exception const& ex) { -- cgit v1.2.3