summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2025-03-24 11:34:43 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2025-04-07 13:29:28 +0200
commit19c8f8ac038d77d9f97629504d930d85471e47bb (patch)
tree85e80834af450bf42ca8f3b0b6fedf43fa0f1796 /src
parentd56f9705f656f1e81e92abacd14524b45c311d88 (diff)
downloadjustbuild-19c8f8ac038d77d9f97629504d930d85471e47bb.tar.gz
ArtifactDescription: support tree overlays
... that, like trees, are given by their identifier.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/artifact_description.cpp49
-rw-r--r--src/buildtool/common/artifact_description.hpp17
2 files changed, 60 insertions, 6 deletions
diff --git a/src/buildtool/common/artifact_description.cpp b/src/buildtool/common/artifact_description.cpp
index eecb8c01..2ae906d8 100644
--- a/src/buildtool/common/artifact_description.cpp
+++ b/src/buildtool/common/artifact_description.cpp
@@ -43,6 +43,9 @@ namespace {
[[nodiscard]] auto DescribeTreeArtifact(std::string const& tree_id)
-> nlohmann::json;
+[[nodiscard]] auto DescribeTreeOverlayArtifact(
+ std::string const& tree_overlay_id) -> nlohmann::json;
+
[[nodiscard]] auto CreateLocalArtifactDescription(nlohmann::json const& data)
-> std::optional<ArtifactDescription>;
@@ -55,6 +58,9 @@ namespace {
[[nodiscard]] auto CreateTreeArtifactDescription(nlohmann::json const& data)
-> std::optional<ArtifactDescription>;
+
+[[nodiscard]] auto CreateTreeOverlayArtifactDescription(
+ nlohmann::json const& data) -> std::optional<ArtifactDescription>;
} // namespace
auto ArtifactDescription::CreateLocal(std::filesystem::path path,
@@ -81,7 +87,12 @@ auto ArtifactDescription::CreateKnown(ArtifactDigest digest,
auto ArtifactDescription::CreateTree(std::string tree_id) noexcept
-> ArtifactDescription {
- return ArtifactDescription{std::move(tree_id)};
+ return ArtifactDescription{Tree{std::move(tree_id)}};
+}
+
+auto ArtifactDescription::CreateTreeOverlay(
+ std::string tree_overlay_id) noexcept -> ArtifactDescription {
+ return ArtifactDescription{TreeOverlay{std::move(tree_overlay_id)}};
}
auto ArtifactDescription::FromJson(HashFunction::Type hash_type,
@@ -121,9 +132,12 @@ auto ArtifactDescription::FromJson(HashFunction::Type hash_type,
if (*type == "TREE") {
return CreateTreeArtifactDescription(*data);
}
+ if (*type == "TREE_OVERLAY") {
+ return CreateTreeOverlayArtifactDescription(*data);
+ }
Logger::Log(LogLevel::Error,
R"(artifact type must be one of "LOCAL", "KNOWN",
- "ACTION", or "TREE")");
+ "ACTION", "TREE", or "TREE_OVERLAY")");
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error,
"Failed to parse artifact description from JSON with "
@@ -147,7 +161,11 @@ auto ArtifactDescription::ToJson() const -> nlohmann::json {
return DescribeActionArtifact(action_id, path);
}
if (std::holds_alternative<Tree>(data_)) {
- return DescribeTreeArtifact(std::get<Tree>(data_));
+ return DescribeTreeArtifact(std::get<Tree>(data_).tree);
+ }
+ if (std::holds_alternative<TreeOverlay>(data_)) {
+ return DescribeTreeOverlayArtifact(
+ std::get<TreeOverlay>(data_).tree_overlay);
}
Logger::Log(LogLevel::Error, "Internal error, unknown artifact type");
Ensures(false); // unreachable
@@ -165,7 +183,8 @@ auto ArtifactDescription::ToArtifact() const noexcept -> Artifact {
return Artifact::CreateKnownArtifact(id_, digest, file_type, repo);
}
if (std::holds_alternative<Action>(data_) or
- std::holds_alternative<Tree>(data_)) {
+ std::holds_alternative<Tree>(data_) or
+ std::holds_alternative<TreeOverlay>(data_)) {
return Artifact::CreateActionArtifact(id_);
}
Logger::Log(LogLevel::Error, "Internal error, unknown artifact type");
@@ -232,6 +251,11 @@ auto DescribeTreeArtifact(std::string const& tree_id) -> nlohmann::json {
return {{"type", "TREE"}, {"data", {{"id", tree_id}}}};
}
+auto DescribeTreeOverlayArtifact(std::string const& tree_overlay_id)
+ -> nlohmann::json {
+ return {{"type", "TREE_OVERLAY"}, {"data", {{"id", tree_overlay_id}}}};
+}
+
auto CreateLocalArtifactDescription(nlohmann::json const& data)
-> std::optional<ArtifactDescription> {
auto path =
@@ -333,4 +357,21 @@ auto CreateTreeArtifactDescription(nlohmann::json const& data)
}
return std::nullopt;
}
+
+auto CreateTreeOverlayArtifactDescription(nlohmann::json const& data)
+ -> std::optional<ArtifactDescription> {
+ auto tree_overlay_id =
+ ExtractValueAs<std::string>(data, "id", [](std::string const& error) {
+ Logger::Log(LogLevel::Error,
+ "{}\ncan not retrieve value for \"id\" from "
+ "TREE_OVERLAY artifact's data.",
+ error);
+ });
+
+ if (tree_overlay_id.has_value()) {
+ return ArtifactDescription::CreateTreeOverlay(
+ std::move(*tree_overlay_id));
+ }
+ return std::nullopt;
+}
} // namespace
diff --git a/src/buildtool/common/artifact_description.hpp b/src/buildtool/common/artifact_description.hpp
index 6a4b3b9e..0f600846 100644
--- a/src/buildtool/common/artifact_description.hpp
+++ b/src/buildtool/common/artifact_description.hpp
@@ -35,9 +35,15 @@ class ArtifactDescription final {
using Known =
std::tuple<ArtifactDigest, ObjectType, std::optional<std::string>>;
using Action = std::pair<std::string, std::filesystem::path>;
- using Tree = std::string;
public:
+ struct Tree {
+ std::string tree;
+ };
+ struct TreeOverlay {
+ std::string tree_overlay;
+ };
+
[[nodiscard]] static auto CreateLocal(std::filesystem::path path,
std::string repository) noexcept
-> ArtifactDescription;
@@ -55,6 +61,9 @@ class ArtifactDescription final {
[[nodiscard]] static auto CreateTree(std::string tree_id) noexcept
-> ArtifactDescription;
+ [[nodiscard]] static auto CreateTreeOverlay(
+ std::string tree_overlay_id) noexcept -> ArtifactDescription;
+
[[nodiscard]] auto Id() const& noexcept -> ArtifactIdentifier const& {
return id_;
}
@@ -70,6 +79,10 @@ class ArtifactDescription final {
return std::holds_alternative<Tree>(data_);
}
+ [[nodiscard]] auto IsTreeOverlay() const noexcept -> bool {
+ return std::holds_alternative<TreeOverlay>(data_);
+ }
+
[[nodiscard]] static auto FromJson(HashFunction::Type hash_type,
nlohmann::json const& json) noexcept
-> std::optional<ArtifactDescription>;
@@ -91,7 +104,7 @@ class ArtifactDescription final {
}
private:
- std::variant<Local, Known, Action, Tree> data_;
+ std::variant<Local, Known, Action, Tree, TreeOverlay> data_;
ArtifactIdentifier id_;
template <typename T>