summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/build_engine/expression/target_result.cpp4
-rw-r--r--src/buildtool/build_engine/target_map/built_in_rules.cpp11
-rw-r--r--src/buildtool/build_engine/target_map/target_map.cpp29
-rw-r--r--src/buildtool/common/artifact_description.cpp59
-rw-r--r--src/buildtool/common/artifact_description.hpp28
-rw-r--r--src/buildtool/common/artifact_factory.hpp13
-rw-r--r--src/buildtool/common/tree.hpp2
-rw-r--r--src/buildtool/execution_engine/dag/dag.cpp9
-rw-r--r--src/buildtool/file_system/file_root.hpp14
9 files changed, 99 insertions, 70 deletions
diff --git a/src/buildtool/build_engine/expression/target_result.cpp b/src/buildtool/build_engine/expression/target_result.cpp
index 3d2e2dda..c4f43f89 100644
--- a/src/buildtool/build_engine/expression/target_result.cpp
+++ b/src/buildtool/build_engine/expression/target_result.cpp
@@ -21,6 +21,7 @@
#include "gsl/gsl"
#include "src/buildtool/build_engine/expression/expression.hpp"
+#include "src/buildtool/common/artifact_description.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
@@ -40,7 +41,8 @@ namespace {
if (auto it = replacements.find(artifact);
it != replacements.end()) {
auto const& info = it->second;
- return ArtifactDescription{info.digest, info.type}.ToJson();
+ return ArtifactDescription::CreateKnown(info.digest, info.type)
+ .ToJson();
}
throw std::runtime_error{
"No replacement for non-known artifact found."};
diff --git a/src/buildtool/build_engine/target_map/built_in_rules.cpp b/src/buildtool/build_engine/target_map/built_in_rules.cpp
index 81f679e5..abcc9d40 100644
--- a/src/buildtool/build_engine/target_map/built_in_rules.cpp
+++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp
@@ -32,6 +32,7 @@
#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
#include "src/buildtool/build_engine/target_map/export.hpp"
#include "src/buildtool/build_engine/target_map/utils.hpp"
+#include "src/buildtool/common/artifact_description.hpp"
#include "src/buildtool/common/repository_config.hpp"
#include "src/utils/cpp/path.hpp"
#include "src/utils/cpp/vector.hpp"
@@ -268,9 +269,9 @@ void BlobGenRuleWithDeps(
auto stage = ExpressionPtr{Expression::map_t{
name_val->String(),
- ExpressionPtr{ArtifactDescription{
+ ExpressionPtr{ArtifactDescription::CreateKnown(
ArtifactDigest::Create<ObjectType::File>(data_val->String()),
- blob_type}}}};
+ blob_type)}}};
auto analysis_result = std::make_shared<AnalysedTarget const>(
TargetResult{.artifact_stage = stage,
@@ -511,7 +512,7 @@ void TreeRuleWithDeps(
std::vector<Tree::Ptr> trees{};
trees.emplace_back(std::move(tree));
auto result_stage = Expression::map_t::underlying_map_t{};
- result_stage.emplace(name, ArtifactDescription{tree_id});
+ result_stage.emplace(name, ArtifactDescription::CreateTree(tree_id));
auto result = ExpressionPtr{Expression::map_t{result_stage}};
auto analysis_result = std::make_shared<AnalysedTarget const>(
@@ -1351,8 +1352,8 @@ void GenericRuleWithDeps(
for (const auto& path : container) {
artifacts.emplace(
path,
- ExpressionPtr{ArtifactDescription{
- action_identifier, std::filesystem::path{path}}});
+ ExpressionPtr{ArtifactDescription::CreateAction(
+ action_identifier, std::filesystem::path{path})});
}
}
diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp
index 7bc74800..1c8d3743 100644
--- a/src/buildtool/build_engine/target_map/target_map.cpp
+++ b/src/buildtool/build_engine/target_map/target_map.cpp
@@ -37,6 +37,7 @@
#include "src/buildtool/build_engine/expression/function_map.hpp"
#include "src/buildtool/build_engine/target_map/built_in_rules.hpp"
#include "src/buildtool/build_engine/target_map/utils.hpp"
+#include "src/buildtool/common/artifact_description.hpp"
#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/logging/log_level.hpp"
@@ -706,14 +707,16 @@ void withDependencies(
auto action_id = action->Id();
actions.emplace_back(std::move(action));
for (auto const& out : outputs) {
- result.emplace(out,
- ExpressionPtr{ArtifactDescription{
- action_id, std::filesystem::path{out}}});
+ result.emplace(
+ out,
+ ExpressionPtr{ArtifactDescription::CreateAction(
+ action_id, std::filesystem::path{out})});
}
for (auto const& out : output_dirs) {
- result.emplace(out,
- ExpressionPtr{ArtifactDescription{
- action_id, std::filesystem::path{out}}});
+ result.emplace(
+ out,
+ ExpressionPtr{ArtifactDescription::CreateAction(
+ action_id, std::filesystem::path{out})});
}
return ExpressionPtr{Expression::map_t{result}};
@@ -727,9 +730,9 @@ void withDependencies(
data->ToString())};
}
blobs.emplace_back(data->String());
- return ExpressionPtr{ArtifactDescription{
+ return ExpressionPtr{ArtifactDescription::CreateKnown(
ArtifactDigest::Create<ObjectType::File>(data->String()),
- ObjectType::File}};
+ ObjectType::File)};
}},
{"SYMLINK",
@@ -747,9 +750,9 @@ void withDependencies(
}
blobs.emplace_back(data->String());
- return ExpressionPtr{ArtifactDescription{
+ return ExpressionPtr{ArtifactDescription::CreateKnown(
ArtifactDigest::Create<ObjectType::Symlink>(data->String()),
- ObjectType::Symlink}};
+ ObjectType::Symlink)};
}},
{"TREE",
@@ -783,7 +786,7 @@ void withDependencies(
auto tree = std::make_shared<Tree>(std::move(artifacts));
auto tree_id = tree->Id();
trees.emplace_back(std::move(tree));
- return ExpressionPtr{ArtifactDescription{tree_id}};
+ return ExpressionPtr{ArtifactDescription::CreateTree(tree_id)};
}},
{"VALUE_NODE",
[](auto&& eval, auto const& expr, auto const& env) {
@@ -1693,7 +1696,9 @@ void TreeTarget(
auto tree = std::make_shared<Tree>(std::move(artifacts));
auto tree_id = tree->Id();
auto tree_map = ExpressionPtr{Expression::map_t{
- name, ExpressionPtr{ArtifactDescription{tree_id}}}};
+ name,
+ ExpressionPtr{
+ ArtifactDescription::CreateTree(tree_id)}}};
auto analysis_result =
std::make_shared<AnalysedTarget const>(
TargetResult{.artifact_stage = tree_map,
diff --git a/src/buildtool/common/artifact_description.cpp b/src/buildtool/common/artifact_description.cpp
index 24c34944..73d0af05 100644
--- a/src/buildtool/common/artifact_description.cpp
+++ b/src/buildtool/common/artifact_description.cpp
@@ -52,22 +52,32 @@ namespace {
-> std::optional<ArtifactDescription>;
} // namespace
-ArtifactDescription::ArtifactDescription(std::filesystem::path path,
- std::string repository) noexcept
- : data_{std::make_pair(std::move(path), std::move(repository))} {}
+auto ArtifactDescription::CreateLocal(std::filesystem::path path,
+ std::string repository) noexcept
+ -> ArtifactDescription {
+ Local data{std::move(path), std::move(repository)};
+ return ArtifactDescription{std::move(data)};
+}
-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))} {}
+auto ArtifactDescription::CreateAction(std::string action_id,
+ std::filesystem::path path) noexcept
+ -> ArtifactDescription {
+ Action data{std::move(action_id), std::move(path)};
+ return ArtifactDescription{std::move(data)};
+}
-ArtifactDescription::ArtifactDescription(std::string action_id,
- std::filesystem::path path) noexcept
- : data_{std::make_pair(std::move(action_id), std::move(path))} {}
+auto ArtifactDescription::CreateKnown(ArtifactDigest digest,
+ ObjectType file_type,
+ std::optional<std::string> repo) noexcept
+ -> ArtifactDescription {
+ Known data{std::move(digest), file_type, std::move(repo)};
+ return ArtifactDescription{std::move(data)};
+}
-ArtifactDescription::ArtifactDescription(std::string tree_id) noexcept
- : data_{std::move(tree_id)} {}
+auto ArtifactDescription::CreateTree(std::string tree_id) noexcept
+ -> ArtifactDescription {
+ return ArtifactDescription{std::move(tree_id)};
+}
auto ArtifactDescription::FromJson(nlohmann::json const& json) noexcept
-> std::optional<ArtifactDescription> {
@@ -225,14 +235,14 @@ auto DescribeTreeArtifact(std::string const& tree_id) noexcept
auto CreateLocalArtifactDescription(nlohmann::json const& data)
-> std::optional<ArtifactDescription> {
- auto const path =
+ auto 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>(
+ auto repository = ExtractValueAs<std::string>(
data, "repository", [](std::string const& error) {
Logger::Log(LogLevel::Error,
"{}\ncan not retrieve value for \"path\" from "
@@ -240,7 +250,8 @@ auto CreateLocalArtifactDescription(nlohmann::json const& data)
error);
});
if (path.has_value() and repository.has_value()) {
- return ArtifactDescription{std::filesystem::path{*path}, *repository};
+ return ArtifactDescription::CreateLocal(std::move(*path),
+ std::move(*repository));
}
return std::nullopt;
}
@@ -271,16 +282,15 @@ auto CreateKnownArtifactDescription(nlohmann::json const& data)
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};
+ ArtifactDigest digest{*blob_id, *size, IsTreeObject(object_type)};
+ return ArtifactDescription::CreateKnown(std::move(digest), object_type);
}
return std::nullopt;
}
auto CreateActionArtifactDescription(nlohmann::json const& data)
-> std::optional<ArtifactDescription> {
- auto const action_id =
+ auto action_id =
ExtractValueAs<std::string>(data, "id", [](std::string const& error) {
Logger::Log(LogLevel::Error,
"{}\ncan not retrieve value for \"id\" from "
@@ -288,7 +298,7 @@ auto CreateActionArtifactDescription(nlohmann::json const& data)
error);
});
- auto const path =
+ auto path =
ExtractValueAs<std::string>(data, "path", [](std::string const& error) {
Logger::Log(LogLevel::Error,
"{}\ncan not retrieve value for \"path\" from "
@@ -296,14 +306,15 @@ auto CreateActionArtifactDescription(nlohmann::json const& data)
error);
});
if (action_id.has_value() and path.has_value()) {
- return ArtifactDescription{*action_id, std::filesystem::path{*path}};
+ return ArtifactDescription::CreateAction(std::move(*action_id),
+ std::move(*path));
}
return std::nullopt;
}
auto CreateTreeArtifactDescription(nlohmann::json const& data)
-> std::optional<ArtifactDescription> {
- auto const tree_id =
+ auto tree_id =
ExtractValueAs<std::string>(data, "id", [](std::string const& error) {
Logger::Log(LogLevel::Error,
"{}\ncan not retrieve value for \"id\" from "
@@ -312,7 +323,7 @@ auto CreateTreeArtifactDescription(nlohmann::json const& data)
});
if (tree_id.has_value()) {
- return ArtifactDescription{*tree_id};
+ return ArtifactDescription::CreateTree(std::move(*tree_id));
}
return std::nullopt;
}
diff --git a/src/buildtool/common/artifact_description.hpp b/src/buildtool/common/artifact_description.hpp
index dd312083..84845ed2 100644
--- a/src/buildtool/common/artifact_description.hpp
+++ b/src/buildtool/common/artifact_description.hpp
@@ -25,7 +25,7 @@
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/file_system/object_type.hpp"
-class ArtifactDescription {
+class ArtifactDescription final {
using Local = std::pair<std::filesystem::path, std::string>;
using Known =
std::tuple<ArtifactDigest, ObjectType, std::optional<std::string>>;
@@ -33,18 +33,22 @@ class ArtifactDescription {
using Tree = std::string;
public:
- explicit ArtifactDescription(std::filesystem::path path,
- std::string repository) noexcept;
+ [[nodiscard]] static auto CreateLocal(std::filesystem::path path,
+ std::string repository) noexcept
+ -> ArtifactDescription;
- ArtifactDescription(
+ [[nodiscard]] static auto CreateAction(std::string action_id,
+ std::filesystem::path path) noexcept
+ -> ArtifactDescription;
+
+ [[nodiscard]] static auto CreateKnown(
ArtifactDigest digest,
ObjectType file_type,
- std::optional<std::string> repo = std::nullopt) noexcept;
-
- ArtifactDescription(std::string action_id,
- std::filesystem::path path) noexcept;
+ std::optional<std::string> repo = std::nullopt) noexcept
+ -> ArtifactDescription;
- explicit ArtifactDescription(std::string tree_id) noexcept;
+ [[nodiscard]] static auto CreateTree(std::string tree_id) noexcept
+ -> ArtifactDescription;
[[nodiscard]] auto Id() const& noexcept -> ArtifactIdentifier const& {
return id_;
@@ -82,7 +86,11 @@ class ArtifactDescription {
private:
std::variant<Local, Known, Action, Tree> data_;
- ArtifactIdentifier id_{ComputeId(ToJson())};
+ ArtifactIdentifier id_;
+
+ template <typename T>
+ explicit ArtifactDescription(T data) noexcept
+ : data_{std::move(data)}, id_{ComputeId(ToJson())} {}
[[nodiscard]] static auto ComputeId(nlohmann::json const& desc) noexcept
-> ArtifactIdentifier;
diff --git a/src/buildtool/common/artifact_factory.hpp b/src/buildtool/common/artifact_factory.hpp
index e933a16e..0ab0efc3 100644
--- a/src/buildtool/common/artifact_factory.hpp
+++ b/src/buildtool/common/artifact_factory.hpp
@@ -26,6 +26,7 @@
#include "src/buildtool/common/action.hpp"
#include "src/buildtool/common/action_description.hpp"
#include "src/buildtool/common/artifact.hpp"
+#include "src/buildtool/common/artifact_description.hpp"
#include "src/buildtool/common/identifier.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/logger.hpp"
@@ -54,28 +55,30 @@ class ArtifactFactory {
[[nodiscard]] static auto DescribeLocalArtifact(
std::filesystem::path const& src_path,
std::string repository) noexcept -> nlohmann::json {
- return ArtifactDescription{src_path, std::move(repository)}.ToJson();
+ return ArtifactDescription::CreateLocal(src_path, std::move(repository))
+ .ToJson();
}
[[nodiscard]] static auto DescribeKnownArtifact(
std::string const& blob_id,
std::size_t size,
ObjectType type = ObjectType::File) noexcept -> nlohmann::json {
- return ArtifactDescription{
- ArtifactDigest{blob_id, size, IsTreeObject(type)}, type}
+ return ArtifactDescription::CreateKnown(
+ ArtifactDigest{blob_id, size, IsTreeObject(type)}, type)
.ToJson();
}
[[nodiscard]] static auto DescribeActionArtifact(
std::string const& action_id,
std::string const& out_path) noexcept -> nlohmann::json {
- return ArtifactDescription{action_id, std::filesystem::path{out_path}}
+ return ArtifactDescription::CreateAction(
+ action_id, std::filesystem::path{out_path})
.ToJson();
}
[[nodiscard]] static auto DescribeTreeArtifact(
std::string const& tree_id) noexcept -> nlohmann::json {
- return ArtifactDescription{tree_id}.ToJson();
+ return ArtifactDescription::CreateTree(tree_id).ToJson();
}
[[nodiscard]] static auto DescribeAction(
diff --git a/src/buildtool/common/tree.hpp b/src/buildtool/common/tree.hpp
index 6e066c75..e9d5ef84 100644
--- a/src/buildtool/common/tree.hpp
+++ b/src/buildtool/common/tree.hpp
@@ -51,7 +51,7 @@ class Tree {
}
[[nodiscard]] auto Output() const -> ArtifactDescription {
- return ArtifactDescription{id_};
+ return ArtifactDescription::CreateTree(id_);
}
[[nodiscard]] static auto FromJson(std::string const& id,
diff --git a/src/buildtool/execution_engine/dag/dag.cpp b/src/buildtool/execution_engine/dag/dag.cpp
index a3c25402..c36ec664 100644
--- a/src/buildtool/execution_engine/dag/dag.cpp
+++ b/src/buildtool/execution_engine/dag/dag.cpp
@@ -22,7 +22,7 @@ auto DependencyGraph::CreateOutputArtifactNodes(
-> std::pair<std::vector<DependencyGraph::NamedArtifactNodePtr>,
std::vector<DependencyGraph::NamedArtifactNodePtr>> {
if (is_tree_action) { // create tree artifact
- auto artifact = ArtifactDescription{action_id}.ToArtifact();
+ auto artifact = ArtifactDescription::CreateTree(action_id).ToArtifact();
auto const node_id = AddArtifact(std::move(artifact));
return std::make_pair(std::vector<NamedArtifactNodePtr>{},
std::vector<NamedArtifactNodePtr>{
@@ -32,10 +32,9 @@ auto DependencyGraph::CreateOutputArtifactNodes(
// create action artifacts
auto node_creator = [this, &action_id](auto* nodes, auto const& paths) {
for (auto const& artifact_path : paths) {
- auto artifact =
- ArtifactDescription{action_id,
- std::filesystem::path{artifact_path}}
- .ToArtifact();
+ auto artifact = ArtifactDescription::CreateAction(
+ action_id, std::filesystem::path{artifact_path})
+ .ToArtifact();
auto const node_id = AddArtifact(std::move(artifact));
nodes->emplace_back(NamedArtifactNodePtr{
artifact_path, &(*artifact_nodes_[node_id])});
diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp
index db7ff07d..8b85f5a9 100644
--- a/src/buildtool/file_system/file_root.hpp
+++ b/src/buildtool/file_system/file_root.hpp
@@ -230,10 +230,10 @@ class FileRoot {
if (auto id = data->Hash()) {
auto const& size = data->Size();
if (size) {
- return ArtifactDescription{
+ return ArtifactDescription::CreateKnown(
ArtifactDigest{*id, *size, /*is_tree=*/true},
ObjectType::Tree,
- repository};
+ repository);
}
}
} catch (...) {
@@ -575,23 +575,23 @@ class FileRoot {
if (Compatibility::IsCompatible()) {
auto compatible_hash = Compatibility::RegisterGitEntry(
entry->Hash(), *entry->Blob(), repository);
- return ArtifactDescription{
+ return ArtifactDescription::CreateKnown(
ArtifactDigest{compatible_hash,
*entry->Size(),
/*is_tree=*/false},
- entry->Type()};
+ entry->Type());
}
- return ArtifactDescription{
+ return ArtifactDescription::CreateKnown(
ArtifactDigest{
entry->Hash(), *entry->Size(), /*is_tree=*/false},
entry->Type(),
- repository};
+ repository);
}
}
return std::nullopt;
}
if (std::holds_alternative<fs_root_t>(root_)) {
- return ArtifactDescription{file_path, repository};
+ return ArtifactDescription::CreateLocal(file_path, repository);
}
return std::nullopt; // absent roots are neither LOCAL nor KNOWN
}