diff options
Diffstat (limited to 'src/buildtool/file_system/precomputed_root.cpp')
-rw-r--r-- | src/buildtool/file_system/precomputed_root.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/buildtool/file_system/precomputed_root.cpp b/src/buildtool/file_system/precomputed_root.cpp index 0ff02628..73d99ef1 100644 --- a/src/buildtool/file_system/precomputed_root.cpp +++ b/src/buildtool/file_system/precomputed_root.cpp @@ -51,10 +51,12 @@ template <typename T> template <> [[nodiscard]] auto ParseImpl<ComputedRoot>(nlohmann::json const& root) -> expected<ComputedRoot, std::string> { - if (root.size() != ComputedRoot::kSchemeLength) { + if ((root.size() != ComputedRoot::kSchemeLength) and + (root.size() != ComputedRoot::kSchemeLength + 1)) { return unexpected{fmt::format( "The root has a wrong number of arguments: {}\nThe scheme requires " - "[<scheme>, <root>, <module>, <name>, <config>]", + "[<scheme>, <root>, <module>, <name>, <config>] optionally " + "followed by a pragma object", root.dump())}; } @@ -77,14 +79,37 @@ template <> if (not root[4].is_object()) { return unexpected{ fmt::format("The root has a wrong type of <config>. Expected a " - "plain json, got {}", + "plain json object, got {}", root[4].dump())}; } + auto absent = false; + + if (root.size() > ComputedRoot::kSchemeLength) { + if (not root[ComputedRoot::kSchemeLength].is_object()) { + return unexpected{ + fmt::format("The root has a wrong type of optional pragma " + "argument. Expected a " + "plain json object, got {}", + root[ComputedRoot::kSchemeLength].dump())}; + } + if (root[ComputedRoot::kSchemeLength].contains("absent")) { + auto absent_entry = root[ComputedRoot::kSchemeLength]["absent"]; + if (not absent_entry.is_boolean()) { + return unexpected{ + fmt::format("Expected pragma entry \"absent\" to be " + "boolean, but found {}", + absent_entry.dump())}; + } + absent = absent_entry; + } + } + return ComputedRoot{.repository = std::string{root[1]}, .target_module = std::string{root[2]}, .target_name = std::string{root[3]}, - .config = root[4]}; + .config = root[4], + .absent = absent}; } template <> @@ -135,7 +160,8 @@ auto ComputedRoot::operator==(ComputedRoot const& other) const noexcept -> bool { return repository == other.repository and target_module == other.target_module and - target_name == other.target_name and config == other.config; + target_name == other.target_name and config == other.config and + absent == other.absent; } auto ComputedRoot::operator<(ComputedRoot const& other) const noexcept -> bool { @@ -148,14 +174,18 @@ auto ComputedRoot::operator<(ComputedRoot const& other) const noexcept -> bool { if (auto const res = target_name <=> other.target_name; res != 0) { return res < 0; } + if (absent != other.absent) { + return absent; + } return config < other.config; } auto ComputedRoot::ToString() const -> std::string { - return fmt::format("([\"@\", {}, {}, {}], {})", + return fmt::format("([\"@\", {}, {}, {}{}], {})", nlohmann::json(repository).dump(), nlohmann::json(target_module).dump(), nlohmann::json(target_name).dump(), + absent ? ", {\"absent\": true}" : "", config.dump()); } @@ -165,6 +195,7 @@ auto ComputedRoot::ComputeHash() const -> std::size_t { hash_combine<std::string>(&seed, repository); hash_combine<std::string>(&seed, target_module); hash_combine<std::string>(&seed, target_name); + hash_combine<bool>(&seed, absent); hash_combine<nlohmann::json>(&seed, config); return seed; } |