summaryrefslogtreecommitdiff
path: root/src/buildtool/storage/backend_description.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-12-20 12:47:39 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2025-01-07 14:18:09 +0100
commit32c865dce37ff18d796caa9f3cd760eb22edd8f5 (patch)
tree30c4b6961b28adc5a8b7fe2334856b3e48c40d58 /src/buildtool/storage/backend_description.cpp
parentbc0085a9b4bc9f9b66f04e6971ac6eadc58e4479 (diff)
downloadjustbuild-32c865dce37ff18d796caa9f3cd760eb22edd8f5.tar.gz
Pack BackendDescription to a class
...to let it be stored as an independent instance.
Diffstat (limited to 'src/buildtool/storage/backend_description.cpp')
-rw-r--r--src/buildtool/storage/backend_description.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/buildtool/storage/backend_description.cpp b/src/buildtool/storage/backend_description.cpp
index a290dc22..0f1a3401 100644
--- a/src/buildtool/storage/backend_description.cpp
+++ b/src/buildtool/storage/backend_description.cpp
@@ -19,11 +19,24 @@
#include "fmt/core.h"
#include "nlohmann/json.hpp"
+#include "src/buildtool/common/artifact_digest_factory.hpp"
+#include "src/buildtool/file_system/object_type.hpp"
-auto DescribeBackend(std::optional<ServerAddress> const& address,
- ExecutionProperties const& properties,
- std::vector<DispatchEndpoint> const& dispatch) noexcept
- -> expected<std::string, std::string> {
+BackendDescription::BackendDescription() noexcept {
+ if (auto dummy = Describe(
+ /*address=*/std::nullopt, /*properties=*/{}, /*dispatch=*/{})) {
+ description_ = dummy->description_;
+ }
+ else {
+ description_ = std::make_shared<std::string>();
+ }
+}
+
+auto BackendDescription::Describe(
+ std::optional<ServerAddress> const& address,
+ ExecutionProperties const& properties,
+ std::vector<DispatchEndpoint> const& dispatch) noexcept
+ -> expected<BackendDescription, std::string> {
nlohmann::json description;
try {
description["remote_address"] =
@@ -54,16 +67,32 @@ auto DescribeBackend(std::optional<ServerAddress> const& address,
"Failed to serialize endpoint dispatch list:\n{}", e.what())};
}
}
+
+ std::shared_ptr<std::string> result;
+ std::shared_ptr<std::string> sha256;
try {
// json::dump with json::error_handler_t::replace will not throw an
// exception if invalid UTF-8 sequences are detected in the input.
// Instead, it will replace them with the UTF-8 replacement
// character, but still it needs to be inside a try-catch clause to
// ensure the noexcept modifier of the enclosing function.
- return description.dump(
- 2, ' ', false, nlohmann::json::error_handler_t::replace);
+ result = std::make_shared<std::string>(description.dump(
+ 2, ' ', false, nlohmann::json::error_handler_t::replace));
+
+ std::string hash =
+ ArtifactDigestFactory::HashDataAs<ObjectType::File>(
+ HashFunction(HashFunction::Type::PlainSHA256), *result)
+ .hash();
+ sha256 = std::make_shared<std::string>(std::move(hash));
} catch (std::exception const& e) {
return unexpected{fmt::format(
"Failed to dump backend description to JSON:\n{}", e.what())};
}
+ return BackendDescription(std::move(result), std::move(sha256));
+}
+
+auto BackendDescription::HashContent(HashFunction hash_function) const noexcept
+ -> ArtifactDigest {
+ return ArtifactDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, GetDescription());
}