summaryrefslogtreecommitdiff
path: root/src/buildtool/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/common')
-rw-r--r--src/buildtool/common/action_description.hpp8
-rw-r--r--src/buildtool/common/tree.hpp12
2 files changed, 12 insertions, 8 deletions
diff --git a/src/buildtool/common/action_description.hpp b/src/buildtool/common/action_description.hpp
index 9b3469c1..f830eb82 100644
--- a/src/buildtool/common/action_description.hpp
+++ b/src/buildtool/common/action_description.hpp
@@ -2,6 +2,7 @@
#define INCLUDED_SRC_BUILDTOOL_COMMON_ACTION_DESCRIPTION_HPP
#include <map>
+#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
@@ -15,6 +16,7 @@ class ActionDescription {
public:
using outputs_t = std::vector<std::string>;
using inputs_t = std::unordered_map<std::string, ArtifactDescription>;
+ using Ptr = std::shared_ptr<ActionDescription>;
ActionDescription(outputs_t output_files,
outputs_t output_dirs,
@@ -27,7 +29,7 @@ class ActionDescription {
[[nodiscard]] static auto FromJson(std::string const& id,
nlohmann::json const& desc) noexcept
- -> std::optional<ActionDescription> {
+ -> std::optional<ActionDescription::Ptr> {
try {
auto outputs =
ExtractValueAs<std::vector<std::string>>(desc, "output");
@@ -113,11 +115,11 @@ class ActionDescription {
no_cache = *no_cache_it;
}
- return ActionDescription{
+ return std::make_shared<ActionDescription>(
std::move(*outputs),
std::move(*output_dirs),
Action{id, std::move(*command), env, may_fail, no_cache},
- inputs};
+ inputs);
} catch (std::exception const& ex) {
Logger::Log(
LogLevel::Error,
diff --git a/src/buildtool/common/tree.hpp b/src/buildtool/common/tree.hpp
index 512eda86..6b76f8f1 100644
--- a/src/buildtool/common/tree.hpp
+++ b/src/buildtool/common/tree.hpp
@@ -1,6 +1,7 @@
#ifndef INCLUDED_SRC_BUILDTOOL_COMMON_TREE_HPP
#define INCLUDED_SRC_BUILDTOOL_COMMON_TREE_HPP
+#include <memory>
#include <string>
#include <unordered_map>
@@ -13,6 +14,7 @@ class Tree {
using inputs_t = ActionDescription::inputs_t;
public:
+ using Ptr = std::shared_ptr<Tree>;
explicit Tree(inputs_t&& inputs)
: id_{ComputeId(inputs)}, inputs_{std::move(inputs)} {}
@@ -36,7 +38,7 @@ class Tree {
[[nodiscard]] static auto FromJson(std::string const& id,
nlohmann::json const& json)
- -> std::optional<Tree> {
+ -> std::optional<Tree::Ptr> {
auto inputs = inputs_t{};
inputs.reserve(json.size());
for (auto const& [path, artifact] : json.items()) {
@@ -46,16 +48,16 @@ class Tree {
}
inputs.emplace(path, std::move(*artifact_desc));
}
- return Tree{id, std::move(inputs)};
+ return std::make_shared<Tree>(id, std::move(inputs));
}
+ Tree(std::string id, inputs_t&& inputs)
+ : id_{std::move(id)}, inputs_{std::move(inputs)} {}
+
private:
std::string id_;
inputs_t inputs_;
- Tree(std::string id, inputs_t&& inputs)
- : id_{std::move(id)}, inputs_{std::move(inputs)} {}
-
static auto ComputeDescription(inputs_t const& inputs) -> nlohmann::json {
auto json = nlohmann::json::object();
for (auto const& [path, artifact] : inputs) {