summaryrefslogtreecommitdiff
path: root/src/buildtool/build_engine/target_map/target_cache.cpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-10-13 15:59:25 +0200
committerSascha Roloff <sascha.roloff@huawei.com>2022-10-18 12:00:32 +0200
commit2cfab6bdf859695b934187b6d847329895ecd324 (patch)
tree6872af5e4370d7c0c79778aa7020b671e23a8dfd /src/buildtool/build_engine/target_map/target_cache.cpp
parentd22adef666d704680ee74b35a46d530f6b6d5f15 (diff)
downloadjustbuild-2cfab6bdf859695b934187b6d847329895ecd324.tar.gz
TargetResult: Serialise inner TargetResults flat
Before this change, TargetResults that appear inside of other TargetResults (typically via value nodes) were serialised via the top-level serialisation function for TargetResults. While technically correct, it is rather inefficient as identical expressions from outer and inner TargetResults are not properly deduplicated and a deeply nested data structure is maintained. With this change, expressions of inner TargetResults are serialised in the context of outer TargetResults, resulting in a flat list of all transitively contained expressions with proper deduplication applied. As this serialisation of TargetResult is used in target-level cache entries, the new format is a breaking change to existing entries. Therefore, after switching to the new serialisation format introduced by this commit, users are required to clean their target-level cache. This also reverts commit d22adef666d704680ee74b35a46d530f6b6d5f15, "Recursively scan provided results for known artifacts".
Diffstat (limited to 'src/buildtool/build_engine/target_map/target_cache.cpp')
-rw-r--r--src/buildtool/build_engine/target_map/target_cache.cpp32
1 files changed, 4 insertions, 28 deletions
diff --git a/src/buildtool/build_engine/target_map/target_cache.cpp b/src/buildtool/build_engine/target_map/target_cache.cpp
index f1a0c750..b2f3b209 100644
--- a/src/buildtool/build_engine/target_map/target_cache.cpp
+++ b/src/buildtool/build_engine/target_map/target_cache.cpp
@@ -92,12 +92,6 @@ 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 {
@@ -105,8 +99,6 @@ auto ScanTargetResult(
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(
@@ -116,32 +108,16 @@ auto ScanTargetResult(
[&nodes](auto const& item) {
return ToObjectInfo(nodes[item.template get<std::string>()]);
});
-
- // 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"]);
+ return true;
}
auto TargetCache::Entry::ToArtifacts(
gsl::not_null<std::vector<Artifact::ObjectInfo>*> const& infos)
const noexcept -> bool {
try {
- if (ScanTargetResult(infos, desc_)) {
+ if (ScanArtifactMap(infos, desc_["artifacts"]) and
+ ScanArtifactMap(infos, desc_["runfiles"]) and
+ ScanProvidesMap(infos, desc_["provides"])) {
return true;
}
} catch (std::exception const& ex) {