diff options
author | Sascha Roloff <sascha.roloff@huawei.com> | 2022-10-14 18:10:56 +0200 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2022-10-14 18:29:52 +0200 |
commit | d22adef666d704680ee74b35a46d530f6b6d5f15 (patch) | |
tree | 4e00eea8291196ee1cc7aa997e88d2998a7231f3 | |
parent | f7e4ebf0e2913ff1b987e40baab5c0c809e6c0de (diff) | |
download | justbuild-d22adef666d704680ee74b35a46d530f6b6d5f15.tar.gz |
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.
-rw-r--r-- | src/buildtool/build_engine/target_map/target_cache.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
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<std::vector<Artifact::ObjectInfo>*> const& /*infos*/, + nlohmann::json const& /*json*/) -> bool; + +// NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto ScanProvidesMap( gsl::not_null<std::vector<Artifact::ObjectInfo>*> 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<std::string>()]); }); - 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<std::string>()]); + }); +} + +// NOLINTNEXTLINE(misc-no-recursion) +[[nodiscard]] auto ScanTargetResult( + gsl::not_null<std::vector<Artifact::ObjectInfo>*> 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<std::vector<Artifact::ObjectInfo>*> 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) { |