summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/TARGETS6
-rw-r--r--src/buildtool/main/install_cas.cpp53
-rw-r--r--src/buildtool/main/install_cas.hpp7
3 files changed, 39 insertions, 27 deletions
diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS
index 7298af47..9c9cebfb 100644
--- a/src/buildtool/main/TARGETS
+++ b/src/buildtool/main/TARGETS
@@ -131,16 +131,16 @@
, ["src/buildtool/common", "common"]
, ["src/buildtool/execution_api/common", "api_bundle"]
, ["src/buildtool/execution_api/remote", "context"]
+ , ["src/buildtool/crypto", "hash_function"]
]
, "stage": ["src", "buildtool", "main"]
, "private-deps":
- [ ["src/buildtool/compatibility", "compatibility"]
- , ["src/buildtool/crypto", "hash_function"]
- , ["src/buildtool/logging", "log_level"]
+ [ ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/execution_api/utils", "subobject"]
, ["src/buildtool/execution_api/common", "common"]
, "archive"
+ , ["src/buildtool/common", "artifact_digest_factory"]
]
}
, "add_to_cas":
diff --git a/src/buildtool/main/install_cas.cpp b/src/buildtool/main/install_cas.cpp
index 1f5873e1..4e926457 100644
--- a/src/buildtool/main/install_cas.cpp
+++ b/src/buildtool/main/install_cas.cpp
@@ -16,8 +16,7 @@
#include <cstddef>
-#include "src/buildtool/compatibility/compatibility.hpp"
-#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/common/artifact_digest_factory.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
@@ -28,14 +27,16 @@
namespace {
-[[nodiscard]] auto InvalidSizeString(std::string const& size_str,
+[[nodiscard]] auto InvalidSizeString(HashFunction::Type hash_type,
+ std::string const& size_str,
std::string const& hash,
bool has_remote) noexcept -> bool {
// Only in compatible mode the size is checked, so an empty SHA256 hash is
// needed.
static auto const kEmptyHash =
HashFunction{HashFunction::Type::PlainSHA256}.HashBlobData("");
- return Compatibility::IsCompatible() and // native mode is fine
+ return hash_type ==
+ HashFunction::Type::PlainSHA256 and // native mode is fine
(size_str == "0" or size_str.empty()) and // not "0" or "" is fine
kEmptyHash.HexString() != hash and // empty hash is fine
has_remote; // local is fine
@@ -43,9 +44,10 @@ namespace {
} // namespace
-[[nodiscard]] auto ObjectInfoFromLiberalString(std::string const& s,
+[[nodiscard]] auto ObjectInfoFromLiberalString(HashFunction::Type hash_type,
+ std::string const& s,
bool has_remote) noexcept
- -> Artifact::ObjectInfo {
+ -> std::optional<Artifact::ObjectInfo> {
std::istringstream iss(s);
std::string id{};
std::string size_str{};
@@ -60,7 +62,7 @@ namespace {
if (not iss.eof()) {
std::getline(iss, type, ']');
}
- if (InvalidSizeString(size_str, id, has_remote)) {
+ if (InvalidSizeString(hash_type, size_str, id, has_remote)) {
Logger::Log(
LogLevel::Warning,
"{} size in object-id is not supported in compatiblity mode.",
@@ -69,9 +71,13 @@ namespace {
auto size = static_cast<std::size_t>(
size_str.empty() ? 0 : std::atol(size_str.c_str()));
auto const& object_type = FromChar(*type.c_str());
- return Artifact::ObjectInfo{
- .digest = ArtifactDigest{id, size, IsTreeObject(object_type)},
- .type = object_type};
+ auto digest = ArtifactDigestFactory::Create(
+ hash_type, id, size, IsTreeObject(object_type));
+ if (not digest) {
+ return std::nullopt;
+ }
+ return Artifact::ObjectInfo{.digest = *std::move(digest),
+ .type = object_type};
}
#ifndef BOOTSTRAP_BUILD_TOOL
@@ -79,24 +85,27 @@ auto FetchAndInstallArtifacts(ApiBundle const& apis,
FetchArguments const& clargs,
RemoteContext const& remote_context) -> bool {
auto object_info = ObjectInfoFromLiberalString(
+ apis.hash_function.GetType(),
clargs.object_id,
remote_context.exec_config->remote_address.has_value());
+ if (not object_info) {
+ return false;
+ }
if (clargs.remember) {
if (not apis.remote->ParallelRetrieveToCas(
- {object_info}, *apis.local, 1, true)) {
+ {*object_info}, *apis.local, 1, true)) {
Logger::Log(LogLevel::Warning,
"Failed to copy artifact {} to local CAS",
- object_info.ToString());
+ object_info->ToString());
}
}
if (clargs.sub_path) {
- std::filesystem::path sofar{};
auto new_object_info =
- RetrieveSubPathId(object_info, *apis.remote, *clargs.sub_path);
+ RetrieveSubPathId(*object_info, *apis.remote, *clargs.sub_path);
if (new_object_info) {
- object_info = *new_object_info;
+ object_info = new_object_info;
}
else {
return false;
@@ -108,7 +117,7 @@ auto FetchAndInstallArtifacts(ApiBundle const& apis,
// Compute output location and create parent directories
auto output_path = (*clargs.output_path / "").parent_path();
if (FileSystemManager::IsDirectory(output_path)) {
- output_path /= object_info.digest.hash();
+ output_path /= object_info->digest.hash();
}
if (not FileSystemManager::CreateDirectory(output_path.parent_path())) {
@@ -121,30 +130,30 @@ auto FetchAndInstallArtifacts(ApiBundle const& apis,
}
if (clargs.archive) {
- if (object_info.type != ObjectType::Tree) {
+ if (object_info->type != ObjectType::Tree) {
Logger::Log(LogLevel::Error,
"Archive requested on non-tree {}",
- object_info.ToString());
+ object_info->ToString());
return false;
}
- return GenerateArchive(*apis.remote, object_info, out);
+ return GenerateArchive(*apis.remote, *object_info, out);
}
if (out) {
if (not apis.remote->RetrieveToPaths(
- {object_info}, {*out}, &*apis.local)) {
+ {*object_info}, {*out}, &*apis.local)) {
Logger::Log(LogLevel::Error, "failed to retrieve artifact.");
return false;
}
Logger::Log(LogLevel::Info,
"artifact {} was installed to {}",
- object_info.ToString(),
+ object_info->ToString(),
out->string());
}
else { // dump to stdout
if (not apis.remote->RetrieveToFds(
- {object_info}, {dup(fileno(stdout))}, clargs.raw_tree)) {
+ {*object_info}, {dup(fileno(stdout))}, clargs.raw_tree)) {
Logger::Log(LogLevel::Error, "failed to dump artifact.");
return false;
}
diff --git a/src/buildtool/main/install_cas.hpp b/src/buildtool/main/install_cas.hpp
index 97324569..e7a42ae4 100644
--- a/src/buildtool/main/install_cas.hpp
+++ b/src/buildtool/main/install_cas.hpp
@@ -15,9 +15,11 @@
#ifndef INCLUDED_SRC_BUILDTOOL_MAIN_INSTALL_CAS_HPP
#define INCLUDED_SRC_BUILDTOOL_MAIN_INSTALL_CAS_HPP
+#include <optional>
#include <string>
#include "src/buildtool/common/artifact.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
#include "src/buildtool/common/cli.hpp"
#include "src/buildtool/execution_api/common/api_bundle.hpp"
@@ -25,9 +27,10 @@
#endif
/// \note Method is public for use also in tests.
-[[nodiscard]] auto ObjectInfoFromLiberalString(std::string const& s,
+[[nodiscard]] auto ObjectInfoFromLiberalString(HashFunction::Type hash_type,
+ std::string const& s,
bool has_remote) noexcept
- -> Artifact::ObjectInfo;
+ -> std::optional<Artifact::ObjectInfo>;
#ifndef BOOTSTRAP_BUILD_TOOL
[[nodiscard]] auto FetchAndInstallArtifacts(ApiBundle const& apis,