summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-07-11 17:03:57 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-12 15:43:37 +0200
commit9362f6c426a6e10d0f77282364a0061ebf192375 (patch)
tree2e49252f9e0494d7287557377aae716c60d627bc
parented0c700088ecb799968013db7f27474dc5541bec (diff)
downloadjustbuild-9362f6c426a6e10d0f77282364a0061ebf192375.tar.gz
Move implementation details of ArtifactDescription to the cpp file
-rw-r--r--src/buildtool/common/TARGETS5
-rw-r--r--src/buildtool/common/action_description.hpp1
-rw-r--r--src/buildtool/common/artifact_description.cpp319
-rw-r--r--src/buildtool/common/artifact_description.hpp279
-rw-r--r--src/buildtool/file_system/TARGETS1
-rw-r--r--src/buildtool/file_system/file_root.hpp1
6 files changed, 340 insertions, 266 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index d8f48a8e..f279640d 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -80,12 +80,14 @@
{ "type": ["@", "rules", "CC", "library"]
, "name": ["artifact_description"]
, "hdrs": ["artifact_description.hpp"]
+ , "srcs": ["artifact_description.cpp"]
, "deps":
[ "common"
+ , ["@", "json", "", "json"]
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/logging", "logging"]
- , ["src/utils/cpp", "json"]
]
+ , "private-deps": [["src/utils/cpp", "json"]]
, "stage": ["src", "buildtool", "common"]
}
, "action_description":
@@ -98,6 +100,7 @@
, ["@", "json", "", "json"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
+ , ["src/utils/cpp", "json"]
]
, "stage": ["src", "buildtool", "common"]
}
diff --git a/src/buildtool/common/action_description.hpp b/src/buildtool/common/action_description.hpp
index bb11c68b..47a92eb8 100644
--- a/src/buildtool/common/action_description.hpp
+++ b/src/buildtool/common/action_description.hpp
@@ -28,6 +28,7 @@
#include "src/buildtool/common/artifact_description.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/utils/cpp/json.hpp"
class ActionDescription {
public:
diff --git a/src/buildtool/common/artifact_description.cpp b/src/buildtool/common/artifact_description.cpp
new file mode 100644
index 00000000..24c34944
--- /dev/null
+++ b/src/buildtool/common/artifact_description.cpp
@@ -0,0 +1,319 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/buildtool/common/artifact_description.hpp"
+
+#include <cstddef>
+
+#include "nlohmann/json.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/logging/logger.hpp"
+#include "src/utils/cpp/json.hpp"
+
+namespace {
+[[nodiscard]] auto DescribeLocalArtifact(std::filesystem::path const& src_path,
+ std::string const& repository) noexcept
+ -> nlohmann::json;
+
+[[nodiscard]] auto DescribeKnownArtifact(
+ std::string const& blob_id,
+ std::size_t size,
+ ObjectType type = ObjectType::File) noexcept -> nlohmann::json;
+
+[[nodiscard]] auto DescribeActionArtifact(std::string const& action_id,
+ std::string const& out_path) noexcept
+ -> nlohmann::json;
+
+[[nodiscard]] auto DescribeTreeArtifact(std::string const& tree_id) noexcept
+ -> nlohmann::json;
+
+[[nodiscard]] auto CreateLocalArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription>;
+
+[[nodiscard]] auto CreateKnownArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription>;
+
+[[nodiscard]] auto CreateActionArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription>;
+
+[[nodiscard]] auto CreateTreeArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription>;
+} // namespace
+
+ArtifactDescription::ArtifactDescription(std::filesystem::path path,
+ std::string repository) noexcept
+ : data_{std::make_pair(std::move(path), std::move(repository))} {}
+
+ArtifactDescription::ArtifactDescription(
+ ArtifactDigest digest,
+ ObjectType file_type,
+ std::optional<std::string> repo) noexcept
+ : data_{std::make_tuple(std::move(digest), file_type, std::move(repo))} {}
+
+ArtifactDescription::ArtifactDescription(std::string action_id,
+ std::filesystem::path path) noexcept
+ : data_{std::make_pair(std::move(action_id), std::move(path))} {}
+
+ArtifactDescription::ArtifactDescription(std::string tree_id) noexcept
+ : data_{std::move(tree_id)} {}
+
+auto ArtifactDescription::FromJson(nlohmann::json const& json) noexcept
+ -> std::optional<ArtifactDescription> {
+ try {
+ auto const type = ExtractValueAs<std::string>(
+ json, "type", [](std::string const& error) {
+ Logger::Log(
+ LogLevel::Error,
+ "{}\ncan not retrieve value for \"type\" from artifact "
+ "description.",
+ error);
+ });
+ auto const data = ExtractValueAs<nlohmann::json>(
+ json, "data", [](std::string const& error) {
+ Logger::Log(
+ LogLevel::Error,
+ "{}\ncan not retrieve value for \"data\" from artifact "
+ "description.",
+ error);
+ });
+
+ if (not(type and data)) {
+ return std::nullopt;
+ }
+
+ if (*type == "LOCAL") {
+ return CreateLocalArtifactDescription(*data);
+ }
+ if (*type == "KNOWN") {
+ return CreateKnownArtifactDescription(*data);
+ }
+ if (*type == "ACTION") {
+ return CreateActionArtifactDescription(*data);
+ }
+ if (*type == "TREE") {
+ return CreateTreeArtifactDescription(*data);
+ }
+ Logger::Log(LogLevel::Error,
+ R"(artifact type must be one of "LOCAL", "KNOWN",
+ "ACTION", or "TREE")");
+ } catch (std::exception const& ex) {
+ Logger::Log(LogLevel::Error,
+ "Failed to parse artifact description from JSON with "
+ "error:\n{}",
+ ex.what());
+ }
+ return std::nullopt;
+}
+
+auto ArtifactDescription::ToJson() const noexcept -> nlohmann::json {
+ try {
+ if (std::holds_alternative<Local>(data_)) {
+ auto const& [path, repo] = std::get<Local>(data_);
+ return DescribeLocalArtifact(path.string(), repo);
+ }
+ if (std::holds_alternative<Known>(data_)) {
+ auto const& [digest, file_type, _] = std::get<Known>(data_);
+ return DescribeKnownArtifact(
+ digest.hash(), digest.size(), file_type);
+ }
+ if (std::holds_alternative<Action>(data_)) {
+ auto const& [action_id, path] = std::get<Action>(data_);
+ return DescribeActionArtifact(action_id, path);
+ }
+ if (std::holds_alternative<Tree>(data_)) {
+ return DescribeTreeArtifact(std::get<Tree>(data_));
+ }
+ Logger::Log(LogLevel::Error, "Internal error, unknown artifact type");
+ } catch (std::exception const& ex) {
+ Logger::Log(LogLevel::Error,
+ "Serializing to JSON failed with error:\n{}",
+ ex.what());
+ }
+ Ensures(false); // unreachable
+ return {};
+}
+
+auto ArtifactDescription::ToArtifact() const noexcept -> Artifact {
+ try {
+ if (std::holds_alternative<Local>(data_)) {
+ auto const& [path, repo] = std::get<Local>(data_);
+ return Artifact::CreateLocalArtifact(id_, path.string(), repo);
+ }
+ if (std::holds_alternative<Known>(data_)) {
+ auto const& [digest, file_type, repo] = std::get<Known>(data_);
+ return Artifact::CreateKnownArtifact(
+ id_, digest.hash(), digest.size(), file_type, repo);
+ }
+ if (std::holds_alternative<Action>(data_) or
+ std::holds_alternative<Tree>(data_)) {
+ return Artifact::CreateActionArtifact(id_);
+ }
+ Logger::Log(LogLevel::Error, "Internal error, unknown artifact type");
+ } catch (std::exception const& ex) {
+ Logger::Log(LogLevel::Error,
+ "Creating artifact failed with error:\n{}",
+ ex.what());
+ }
+ Ensures(false); // unreachable
+ return Artifact{{}};
+}
+
+auto ArtifactDescription::ToString(int indent) const noexcept -> std::string {
+ try {
+ return ToJson().dump(indent);
+ } catch (std::exception const& ex) {
+ Logger::Log(LogLevel::Error,
+ "Serializing artifact failed with error:\n{}",
+ ex.what());
+ }
+ return {};
+}
+
+auto ArtifactDescription::ComputeId(nlohmann::json const& desc) noexcept
+ -> ArtifactIdentifier {
+ try {
+ return HashFunction::ComputeHash(desc.dump()).Bytes();
+ } catch (std::exception const& ex) {
+ Logger::Log(LogLevel::Error,
+ "Computing artifact id failed with error:\n{}",
+ ex.what());
+ }
+ return {};
+}
+
+namespace {
+auto DescribeLocalArtifact(std::filesystem::path const& src_path,
+ std::string const& repository) noexcept
+ -> nlohmann::json {
+ return {
+ {"type", "LOCAL"},
+ {"data", {{"path", src_path.string()}, {"repository", repository}}}};
+}
+
+auto DescribeKnownArtifact(std::string const& blob_id,
+ std::size_t size,
+ ObjectType type) noexcept -> nlohmann::json {
+ std::string const typestr{ToChar(type)};
+ return {
+ {"type", "KNOWN"},
+ {"data", {{"id", blob_id}, {"size", size}, {"file_type", typestr}}}};
+}
+
+auto DescribeActionArtifact(std::string const& action_id,
+ std::string const& out_path) noexcept
+ -> nlohmann::json {
+ return {{"type", "ACTION"},
+ {"data", {{"id", action_id}, {"path", out_path}}}};
+}
+
+auto DescribeTreeArtifact(std::string const& tree_id) noexcept
+ -> nlohmann::json {
+ return {{"type", "TREE"}, {"data", {{"id", tree_id}}}};
+}
+
+auto CreateLocalArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription> {
+ auto const path =
+ ExtractValueAs<std::string>(data, "path", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"path\" from "
+ "LOCAL artifact's data.",
+ error);
+ });
+ auto const repository = ExtractValueAs<std::string>(
+ data, "repository", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"path\" from "
+ "LOCAL artifact's data.",
+ error);
+ });
+ if (path.has_value() and repository.has_value()) {
+ return ArtifactDescription{std::filesystem::path{*path}, *repository};
+ }
+ return std::nullopt;
+}
+
+auto CreateKnownArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription> {
+ auto const blob_id =
+ ExtractValueAs<std::string>(data, "id", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"id\" from "
+ "KNOWN artifact's data.",
+ error);
+ });
+ auto const size =
+ ExtractValueAs<std::size_t>(data, "size", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"size\" from "
+ "KNOWN artifact's data.",
+ error);
+ });
+ auto const file_type = ExtractValueAs<std::string>(
+ data, "file_type", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"file_type\" from "
+ "KNOWN artifact's data.",
+ error);
+ });
+ if (blob_id.has_value() and size.has_value() and file_type.has_value() and
+ file_type->size() == 1) {
+ auto const& object_type = FromChar((*file_type)[0]);
+ return ArtifactDescription{
+ ArtifactDigest{*blob_id, *size, IsTreeObject(object_type)},
+ object_type};
+ }
+ return std::nullopt;
+}
+
+auto CreateActionArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription> {
+ auto const action_id =
+ ExtractValueAs<std::string>(data, "id", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"id\" from "
+ "ACTION artifact's data.",
+ error);
+ });
+
+ auto const path =
+ ExtractValueAs<std::string>(data, "path", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"path\" from "
+ "ACTION artifact's data.",
+ error);
+ });
+ if (action_id.has_value() and path.has_value()) {
+ return ArtifactDescription{*action_id, std::filesystem::path{*path}};
+ }
+ return std::nullopt;
+}
+
+auto CreateTreeArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription> {
+ auto const tree_id =
+ ExtractValueAs<std::string>(data, "id", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"id\" from "
+ "TREE artifact's data.",
+ error);
+ });
+
+ if (tree_id.has_value()) {
+ return ArtifactDescription{*tree_id};
+ }
+ return std::nullopt;
+}
+} // namespace
diff --git a/src/buildtool/common/artifact_description.hpp b/src/buildtool/common/artifact_description.hpp
index ba4723f7..dd312083 100644
--- a/src/buildtool/common/artifact_description.hpp
+++ b/src/buildtool/common/artifact_description.hpp
@@ -15,7 +15,6 @@
#ifndef INCLUDED_SRC_BUILDTOOL_COMMON_ARTIFACT_DESCRIPTION_HPP
#define INCLUDED_SRC_BUILDTOOL_COMMON_ARTIFACT_DESCRIPTION_HPP
-#include <cstddef>
#include <filesystem>
#include <optional>
#include <string>
@@ -25,9 +24,6 @@
#include "src/buildtool/common/artifact.hpp"
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/file_system/object_type.hpp"
-#include "src/buildtool/logging/log_level.hpp"
-#include "src/buildtool/logging/logger.hpp"
-#include "src/utils/cpp/json.hpp"
class ArtifactDescription {
using Local = std::pair<std::filesystem::path, std::string>;
@@ -38,69 +34,17 @@ class ArtifactDescription {
public:
explicit ArtifactDescription(std::filesystem::path path,
- std::string repository) noexcept
- : data_{std::make_pair(std::move(path), std::move(repository))} {}
+ std::string repository) noexcept;
- ArtifactDescription(ArtifactDigest digest,
- ObjectType file_type,
- std::optional<std::string> repo = std::nullopt) noexcept
- : data_{
- std::make_tuple(std::move(digest), file_type, std::move(repo))} {}
+ ArtifactDescription(
+ ArtifactDigest digest,
+ ObjectType file_type,
+ std::optional<std::string> repo = std::nullopt) noexcept;
ArtifactDescription(std::string action_id,
- std::filesystem::path path) noexcept
- : data_{std::make_pair(std::move(action_id), std::move(path))} {}
+ std::filesystem::path path) noexcept;
- explicit ArtifactDescription(std::string tree_id) noexcept
- : data_{std::move(tree_id)} {}
-
- [[nodiscard]] static auto FromJson(nlohmann::json const& json) noexcept
- -> std::optional<ArtifactDescription> {
- try {
- auto const type = ExtractValueAs<std::string>(
- json, "type", [](std::string const& error) {
- Logger::Log(
- LogLevel::Error,
- "{}\ncan not retrieve value for \"type\" from artifact "
- "description.",
- error);
- });
- auto const data = ExtractValueAs<nlohmann::json>(
- json, "data", [](std::string const& error) {
- Logger::Log(
- LogLevel::Error,
- "{}\ncan not retrieve value for \"data\" from artifact "
- "description.",
- error);
- });
-
- if (not(type and data)) {
- return std::nullopt;
- }
-
- if (*type == "LOCAL") {
- return CreateLocalArtifactDescription(*data);
- }
- if (*type == "KNOWN") {
- return CreateKnownArtifactDescription(*data);
- }
- if (*type == "ACTION") {
- return CreateActionArtifactDescription(*data);
- }
- if (*type == "TREE") {
- return CreateTreeArtifactDescription(*data);
- }
- Logger::Log(LogLevel::Error,
- R"(artifact type must be one of "LOCAL", "KNOWN",
- "ACTION", or "TREE")");
- } catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
- "Failed to parse artifact description from JSON with "
- "error:\n{}",
- ex.what());
- }
- return std::nullopt;
- }
+ explicit ArtifactDescription(std::string tree_id) noexcept;
[[nodiscard]] auto Id() const& noexcept -> ArtifactIdentifier const& {
return id_;
@@ -117,71 +61,14 @@ class ArtifactDescription {
return std::holds_alternative<Tree>(data_);
}
- [[nodiscard]] auto ToJson() const noexcept -> nlohmann::json {
- try {
- if (std::holds_alternative<Local>(data_)) {
- auto const& [path, repo] = std::get<Local>(data_);
- return DescribeLocalArtifact(path.string(), repo);
- }
- if (std::holds_alternative<Known>(data_)) {
- auto const& [digest, file_type, _] = std::get<Known>(data_);
- return DescribeKnownArtifact(
- digest.hash(), digest.size(), file_type);
- }
- if (std::holds_alternative<Action>(data_)) {
- auto const& [action_id, path] = std::get<Action>(data_);
- return DescribeActionArtifact(action_id, path);
- }
- if (std::holds_alternative<Tree>(data_)) {
- return DescribeTreeArtifact(std::get<Tree>(data_));
- }
- Logger::Log(LogLevel::Error,
- "Internal error, unknown artifact type");
- } catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
- "Serializing to JSON failed with error:\n{}",
- ex.what());
- }
- Ensures(false); // unreachable
- return {};
- }
+ [[nodiscard]] static auto FromJson(nlohmann::json const& json) noexcept
+ -> std::optional<ArtifactDescription>;
- [[nodiscard]] auto ToArtifact() const noexcept -> Artifact {
- try {
- if (std::holds_alternative<Local>(data_)) {
- auto const& [path, repo] = std::get<Local>(data_);
- return Artifact::CreateLocalArtifact(id_, path.string(), repo);
- }
- if (std::holds_alternative<Known>(data_)) {
- auto const& [digest, file_type, repo] = std::get<Known>(data_);
- return Artifact::CreateKnownArtifact(
- id_, digest.hash(), digest.size(), file_type, repo);
- }
- if (std::holds_alternative<Action>(data_) or
- std::holds_alternative<Tree>(data_)) {
- return Artifact::CreateActionArtifact(id_);
- }
- Logger::Log(LogLevel::Error,
- "Internal error, unknown artifact type");
- } catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
- "Creating artifact failed with error:\n{}",
- ex.what());
- }
- Ensures(false); // unreachable
- return Artifact{{}};
- }
+ [[nodiscard]] auto ToJson() const noexcept -> nlohmann::json;
- [[nodiscard]] auto ToString(int indent = 0) const noexcept -> std::string {
- try {
- return ToJson().dump(indent);
- } catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
- "Serializing artifact failed with error:\n{}",
- ex.what());
- }
- return {};
- }
+ [[nodiscard]] auto ToArtifact() const noexcept -> Artifact;
+
+ [[nodiscard]] auto ToString(int indent = 0) const noexcept -> std::string;
[[nodiscard]] auto operator==(
ArtifactDescription const& other) const noexcept -> bool {
@@ -198,145 +85,7 @@ class ArtifactDescription {
ArtifactIdentifier id_{ComputeId(ToJson())};
[[nodiscard]] static auto ComputeId(nlohmann::json const& desc) noexcept
- -> ArtifactIdentifier {
- try {
- return HashFunction::ComputeHash(desc.dump()).Bytes();
- } catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
- "Computing artifact id failed with error:\n{}",
- ex.what());
- }
- return {};
- }
-
- [[nodiscard]] static auto DescribeLocalArtifact(
- std::filesystem::path const& src_path,
- std::string const& repository) noexcept -> nlohmann::json {
- return {{"type", "LOCAL"},
- {"data",
- {{"path", src_path.string()}, {"repository", repository}}}};
- }
-
- [[nodiscard]] static auto DescribeKnownArtifact(
- std::string const& blob_id,
- std::size_t size,
- ObjectType type = ObjectType::File) noexcept -> nlohmann::json {
- std::string const typestr{ToChar(type)};
- return {{"type", "KNOWN"},
- {"data",
- {{"id", blob_id}, {"size", size}, {"file_type", typestr}}}};
- }
-
- [[nodiscard]] static auto DescribeActionArtifact(
- std::string const& action_id,
- std::string const& out_path) noexcept -> nlohmann::json {
- return {{"type", "ACTION"},
- {"data", {{"id", action_id}, {"path", out_path}}}};
- }
-
- [[nodiscard]] static auto DescribeTreeArtifact(
- std::string const& tree_id) noexcept -> nlohmann::json {
- return {{"type", "TREE"}, {"data", {{"id", tree_id}}}};
- }
-
- [[nodiscard]] static auto CreateLocalArtifactDescription(
- nlohmann::json const& data) -> std::optional<ArtifactDescription> {
-
- auto const path = ExtractValueAs<std::string>(
- data, "path", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"path\" from "
- "LOCAL artifact's data.",
- error);
- });
- auto const repository = ExtractValueAs<std::string>(
- data, "repository", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"path\" from "
- "LOCAL artifact's data.",
- error);
- });
- if (path.has_value() and repository.has_value()) {
- return ArtifactDescription{std::filesystem::path{*path},
- *repository};
- }
- return std::nullopt;
- }
-
- [[nodiscard]] static auto CreateKnownArtifactDescription(
- nlohmann::json const& data) -> std::optional<ArtifactDescription> {
-
- auto const blob_id = ExtractValueAs<std::string>(
- data, "id", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"id\" from "
- "KNOWN artifact's data.",
- error);
- });
- auto const size = ExtractValueAs<std::size_t>(
- data, "size", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"size\" from "
- "KNOWN artifact's data.",
- error);
- });
- auto const file_type = ExtractValueAs<std::string>(
- data, "file_type", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"file_type\" from "
- "KNOWN artifact's data.",
- error);
- });
- if (blob_id.has_value() and size.has_value() and
- file_type.has_value() and file_type->size() == 1) {
- auto const& object_type = FromChar((*file_type)[0]);
- return ArtifactDescription{
- ArtifactDigest{*blob_id, *size, IsTreeObject(object_type)},
- object_type};
- }
- return std::nullopt;
- }
-
- [[nodiscard]] static auto CreateActionArtifactDescription(
- nlohmann::json const& data) -> std::optional<ArtifactDescription> {
-
- auto const action_id = ExtractValueAs<std::string>(
- data, "id", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"id\" from "
- "ACTION artifact's data.",
- error);
- });
-
- auto const path = ExtractValueAs<std::string>(
- data, "path", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"path\" from "
- "ACTION artifact's data.",
- error);
- });
- if (action_id.has_value() and path.has_value()) {
- return ArtifactDescription{*action_id,
- std::filesystem::path{*path}};
- }
- return std::nullopt;
- }
-
- [[nodiscard]] static auto CreateTreeArtifactDescription(
- nlohmann::json const& data) -> std::optional<ArtifactDescription> {
- auto const tree_id = ExtractValueAs<std::string>(
- data, "id", [](std::string const& error) {
- Logger::Log(LogLevel::Error,
- "{}\ncan not retrieve value for \"id\" from "
- "TREE artifact's data.",
- error);
- });
-
- if (tree_id.has_value()) {
- return ArtifactDescription{*tree_id};
- }
- return std::nullopt;
- }
+ -> ArtifactIdentifier;
};
namespace std {
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS
index 81c7000d..2d3198c5 100644
--- a/src/buildtool/file_system/TARGETS
+++ b/src/buildtool/file_system/TARGETS
@@ -170,6 +170,7 @@
, ["@", "gsl", "", "gsl"]
, ["@", "json", "", "json"]
, ["src/utils/cpp", "concepts"]
+ , ["src/utils/cpp", "json"]
]
, "stage": ["src", "buildtool", "file_system"]
}
diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp
index eff4d450..db7ff07d 100644
--- a/src/buildtool/file_system/file_root.hpp
+++ b/src/buildtool/file_system/file_root.hpp
@@ -32,6 +32,7 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/concepts.hpp"
+#include "src/utils/cpp/json.hpp"
/// FilteredIterator is an helper class to allow for iteration over
/// directory-only or file-only entries stored inside the class