diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/common/artifact.cpp | 24 | ||||
-rw-r--r-- | src/buildtool/common/artifact.hpp | 3 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 16 |
4 files changed, 34 insertions, 10 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS index 4cc2dcbf..5d06723a 100644 --- a/src/buildtool/common/TARGETS +++ b/src/buildtool/common/TARGETS @@ -30,6 +30,7 @@ , "identifier.hpp" , "statistics.hpp" ] + , "srcs": ["artifact.cpp"] , "deps": [ "bazel_types" , ["src/buildtool/crypto", "hash_function"] diff --git a/src/buildtool/common/artifact.cpp b/src/buildtool/common/artifact.cpp new file mode 100644 index 00000000..fc3c5b6e --- /dev/null +++ b/src/buildtool/common/artifact.cpp @@ -0,0 +1,24 @@ +#include "src/buildtool/common/artifact.hpp" + +#include <string> + +auto Artifact::ObjectInfo::LiberalFromString(std::string const& s) noexcept + -> Artifact::ObjectInfo { + std::istringstream iss(s); + std::string id{}; + std::string size_str{"0"}; + std::string type{"f"}; + if (iss.peek() == '[') { + (void)iss.get(); + } + std::getline(iss, id, ':'); + if (not iss.eof()) { + std::getline(iss, size_str, ':'); + } + if (not iss.eof()) { + std::getline(iss, type, ']'); + } + auto size = static_cast<std::size_t>(std::atol(size_str.c_str())); + return Artifact::ObjectInfo{ArtifactDigest{id, size}, + FromChar(*type.c_str())}; +} diff --git a/src/buildtool/common/artifact.hpp b/src/buildtool/common/artifact.hpp index 6c97ab24..3f68a351 100644 --- a/src/buildtool/common/artifact.hpp +++ b/src/buildtool/common/artifact.hpp @@ -86,6 +86,9 @@ class Artifact { } return std::nullopt; } + + [[nodiscard]] static auto LiberalFromString( + std::string const& s) noexcept -> ObjectInfo; }; explicit Artifact(ArtifactIdentifier id) noexcept : id_{std::move(id)} {} diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index e3c1385a..4c977955 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -1160,32 +1160,28 @@ void ReportTaintedness(const AnalysisResult& result) { [[nodiscard]] auto FetchAndInstallArtifacts( gsl::not_null<IExecutionApi*> const& api, FetchArguments const& clargs) -> bool { - auto object_info = Artifact::ObjectInfo::FromString(clargs.object_id); - if (not object_info) { - Logger::Log( - LogLevel::Error, "failed to parse object id {}.", clargs.object_id); - return false; - } + auto object_info = + Artifact::ObjectInfo::LiberalFromString(clargs.object_id); if (clargs.output_path) { 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()) or - not api->RetrieveToPaths({*object_info}, {output_path})) { + not api->RetrieveToPaths({object_info}, {output_path})) { Logger::Log(LogLevel::Error, "failed to retrieve artifact."); return false; } Logger::Log(LogLevel::Info, "artifact {} was installed to {}", - object_info->ToString(), + object_info.ToString(), output_path.string()); } else { // dump to stdout - if (not api->RetrieveToFds({*object_info}, {dup(fileno(stdout))})) { + if (not api->RetrieveToFds({object_info}, {dup(fileno(stdout))})) { Logger::Log(LogLevel::Error, "failed to dump artifact."); return false; } |