summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/common/artifact.hpp29
-rw-r--r--src/buildtool/storage/target_cache.tpp6
-rw-r--r--test/buildtool/main/TARGETS1
-rw-r--r--test/buildtool/main/install_cas.test.cpp33
4 files changed, 41 insertions, 28 deletions
diff --git a/src/buildtool/common/artifact.hpp b/src/buildtool/common/artifact.hpp
index ec36964e..a788075a 100644
--- a/src/buildtool/common/artifact.hpp
+++ b/src/buildtool/common/artifact.hpp
@@ -25,6 +25,8 @@
#include "nlohmann/json.hpp"
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/common/identifier.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/crypto/hash_info.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
@@ -68,7 +70,8 @@ class Artifact {
{"file_type", std::string{ToChar(type)}}};
}
- [[nodiscard]] static auto FromString(std::string const& s) noexcept
+ [[nodiscard]] static auto FromString(HashFunction::Type hash_type,
+ std::string const& s) noexcept
-> std::optional<ObjectInfo> {
std::istringstream iss(s);
std::string id{};
@@ -81,21 +84,31 @@ class Artifact {
"failed parsing object info from string.");
return std::nullopt;
}
+
+ std::size_t size = 0;
try {
- std::size_t size = std::stoul(size_str);
- auto const& object_type = FromChar(*type.c_str());
- return ObjectInfo{
- .digest =
- ArtifactDigest{id, size, IsTreeObject(object_type)},
- .type = object_type};
+ size = std::stoul(size_str);
} catch (std::out_of_range const& e) {
Logger::Log(LogLevel::Debug,
"size raised out_of_range exception.");
+ return std::nullopt;
} catch (std::invalid_argument const& e) {
Logger::Log(LogLevel::Debug,
"size raised invalid_argument exception.");
+ return std::nullopt;
+ }
+
+ auto const object_type = FromChar(*type.c_str());
+ auto hash_info =
+ HashInfo::Create(hash_type, id, IsTreeObject(object_type));
+ if (not hash_info) {
+ Logger::Log(
+ LogLevel::Debug, "{}", std::move(hash_info).error());
+ return std::nullopt;
}
- return std::nullopt;
+ return ObjectInfo{
+ .digest = ArtifactDigest{*std::move(hash_info), size},
+ .type = object_type};
}
};
diff --git a/src/buildtool/storage/target_cache.tpp b/src/buildtool/storage/target_cache.tpp
index be1b9560..f19a37d5 100644
--- a/src/buildtool/storage/target_cache.tpp
+++ b/src/buildtool/storage/target_cache.tpp
@@ -86,7 +86,8 @@ auto TargetCache<kDoGlobalUplink>::Read(
entry_path.string());
return std::nullopt;
}
- if (auto info = Artifact::ObjectInfo::FromString(*entry)) {
+ auto const hash_type = cas_.GetHashFunction().GetType();
+ if (auto info = Artifact::ObjectInfo::FromString(hash_type, *entry)) {
if (auto path = cas_.BlobPath(info->digest, /*is_executable=*/false)) {
if (auto value = FileSystemManager::ReadFile(*path)) {
try {
@@ -136,7 +137,8 @@ auto TargetCache<kDoGlobalUplink>::LocalUplinkEntry(
}
// Determine target cache entry location.
- auto entry_info = Artifact::ObjectInfo::FromString(*raw_key);
+ auto entry_info = Artifact::ObjectInfo::FromString(
+ cas_.GetHashFunction().GetType(), *raw_key);
if (not entry_info) {
return false;
}
diff --git a/test/buildtool/main/TARGETS b/test/buildtool/main/TARGETS
index af6e228a..1e77cdb9 100644
--- a/test/buildtool/main/TARGETS
+++ b/test/buildtool/main/TARGETS
@@ -8,7 +8,6 @@
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/main", "install_cas"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
- , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "stage": ["test", "buildtool", "main"]
}
diff --git a/test/buildtool/main/install_cas.test.cpp b/test/buildtool/main/install_cas.test.cpp
index 8e9bc121..b74ef143 100644
--- a/test/buildtool/main/install_cas.test.cpp
+++ b/test/buildtool/main/install_cas.test.cpp
@@ -16,12 +16,15 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/common/artifact.hpp"
-#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
TEST_CASE("ObjectInfoFromLiberalString", "[artifact]") {
auto expected = *Artifact::ObjectInfo::FromString(
+ HashFunction::Type::GitSHA1,
"[5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689:11:f]");
+ auto expected_as_tree = *Artifact::ObjectInfo::FromString(
+ HashFunction::Type::GitSHA1,
+ "[5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689:0:t]");
// Check (default) file hashes
CHECK(ObjectInfoFromLiberalString(
@@ -66,20 +69,16 @@ TEST_CASE("ObjectInfoFromLiberalString", "[artifact]") {
/*has_remote=*/false) == expected);
// Check tree hashes
- if (not Compatibility::IsCompatible()) {
- auto expected_as_tree = *Artifact::ObjectInfo::FromString(
- "[5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689:0:t]");
- CHECK(ObjectInfoFromLiberalString(
- HashFunction::Type::GitSHA1,
- "5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689::t",
- /*has_remote=*/false) == expected_as_tree);
- CHECK(ObjectInfoFromLiberalString(
- HashFunction::Type::GitSHA1,
- "5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689::tree",
- /*has_remote=*/false) == expected_as_tree);
- CHECK(ObjectInfoFromLiberalString(
- HashFunction::Type::GitSHA1,
- "5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689:xyz:t",
- /*has_remote=*/false) == expected_as_tree);
- }
+ CHECK(ObjectInfoFromLiberalString(
+ HashFunction::Type::GitSHA1,
+ "5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689::t",
+ /*has_remote=*/false) == expected_as_tree);
+ CHECK(ObjectInfoFromLiberalString(
+ HashFunction::Type::GitSHA1,
+ "5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689::tree",
+ /*has_remote=*/false) == expected_as_tree);
+ CHECK(ObjectInfoFromLiberalString(
+ HashFunction::Type::GitSHA1,
+ "5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689:xyz:t",
+ /*has_remote=*/false) == expected_as_tree);
}