diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-01-11 16:32:30 -0500 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2023-01-11 19:08:19 -0500 |
commit | 5ba6e5d0d9bed2806ddb59c8a3305b3cb5784d53 (patch) | |
tree | 065e7eccec8a228a4045a434c4d5a1de5aa0cf3b /src/libstore | |
parent | 114a6e2b09eda7f23e7776e1cdf77715044e073e (diff) |
Remove default constructor from `OutputsSpec`
This forces us to be explicit.
It also requires to rework how `from_json` works. A `JSON_IMPL` is added
to assist with this.
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/build/entry-points.cc | 7 | ||||
-rw-r--r-- | src/libstore/legacy-ssh-store.cc | 7 | ||||
-rw-r--r-- | src/libstore/outputs-spec.cc | 53 | ||||
-rw-r--r-- | src/libstore/outputs-spec.hh | 15 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 7 |
5 files changed, 50 insertions, 39 deletions
diff --git a/src/libstore/build/entry-points.cc b/src/libstore/build/entry-points.cc index df7722733..2925fe3ca 100644 --- a/src/libstore/build/entry-points.cc +++ b/src/libstore/build/entry-points.cc @@ -80,7 +80,7 @@ BuildResult Store::buildDerivation(const StorePath & drvPath, const BasicDerivat BuildMode buildMode) { Worker worker(*this, *this); - auto goal = worker.makeBasicDerivationGoal(drvPath, drv, {}, buildMode); + auto goal = worker.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All {}, buildMode); try { worker.run(Goals{goal}); @@ -89,7 +89,10 @@ BuildResult Store::buildDerivation(const StorePath & drvPath, const BasicDerivat return BuildResult { .status = BuildResult::MiscFailure, .errorMsg = e.msg(), - .path = DerivedPath::Built { .drvPath = drvPath }, + .path = DerivedPath::Built { + .drvPath = drvPath, + .outputs = OutputsSpec::All { }, + }, }; }; } diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 4d398b21d..e1a4e13a3 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -279,7 +279,12 @@ public: conn->to.flush(); - BuildResult status { .path = DerivedPath::Built { .drvPath = drvPath } }; + BuildResult status { + .path = DerivedPath::Built { + .drvPath = drvPath, + .outputs = OutputsSpec::All { }, + }, + }; status.status = (BuildResult::Status) readInt(conn->from); conn->from >> status.errorMsg; diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc index 891252990..1eeab1aa8 100644 --- a/src/libstore/outputs-spec.cc +++ b/src/libstore/outputs-spec.cc @@ -110,9 +110,21 @@ bool OutputsSpec::merge(const OutputsSpec & that) }, raw()); } +} -void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec) -{ +namespace nlohmann { + +using namespace nix; + +OutputsSpec adl_serializer<OutputsSpec>::from_json(const json & json) { + auto names = json.get<StringSet>(); + if (names == StringSet({"*"})) + return OutputsSpec::All {}; + else + return OutputsSpec::Names { std::move(names) }; +} + +void adl_serializer<OutputsSpec>::to_json(json & json, OutputsSpec t) { std::visit(overloaded { [&](const OutputsSpec::All &) { json = std::vector<std::string>({"*"}); @@ -120,40 +132,27 @@ void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec) [&](const OutputsSpec::Names & names) { json = names; }, - }, outputsSpec); + }, t); } -void to_json(nlohmann::json & json, const ExtendedOutputsSpec & extendedOutputsSpec) -{ +ExtendedOutputsSpec adl_serializer<ExtendedOutputsSpec>::from_json(const json & json) { + if (json.is_null()) + return ExtendedOutputsSpec::Default {}; + else { + return ExtendedOutputsSpec::Explicit { json.get<OutputsSpec>() }; + } +} + +void adl_serializer<ExtendedOutputsSpec>::to_json(json & json, ExtendedOutputsSpec t) { std::visit(overloaded { [&](const ExtendedOutputsSpec::Default &) { json = nullptr; }, [&](const ExtendedOutputsSpec::Explicit & e) { - to_json(json, e); + adl_serializer<OutputsSpec>::to_json(json, e); }, - }, extendedOutputsSpec); -} - - -void from_json(const nlohmann::json & json, OutputsSpec & outputsSpec) -{ - auto names = json.get<StringSet>(); - if (names == StringSet({"*"})) - outputsSpec = OutputsSpec::All {}; - else - outputsSpec = OutputsSpec::Names { std::move(names) }; -} - - -void from_json(const nlohmann::json & json, ExtendedOutputsSpec & extendedOutputsSpec) -{ - if (json.is_null()) - extendedOutputsSpec = ExtendedOutputsSpec::Default {}; - else { - extendedOutputsSpec = ExtendedOutputsSpec::Explicit { json.get<OutputsSpec>() }; - } + }, t); } } diff --git a/src/libstore/outputs-spec.hh b/src/libstore/outputs-spec.hh index 9c477ee2b..babf29d16 100644 --- a/src/libstore/outputs-spec.hh +++ b/src/libstore/outputs-spec.hh @@ -4,7 +4,7 @@ #include <set> #include <variant> -#include "nlohmann/json_fwd.hpp" +#include "json-impls.hh" namespace nix { @@ -35,6 +35,9 @@ struct OutputsSpec : _OutputsSpecRaw { using Raw = _OutputsSpecRaw; using Raw::Raw; + /* Force choosing a variant */ + OutputsSpec() = delete; + using Names = OutputNames; using All = AllOutputs; @@ -85,11 +88,7 @@ struct ExtendedOutputsSpec : _ExtendedOutputsSpecRaw { std::string to_string() const; }; - -void to_json(nlohmann::json &, const OutputsSpec &); -void from_json(const nlohmann::json &, OutputsSpec &); - -void to_json(nlohmann::json &, const ExtendedOutputsSpec &); -void from_json(const nlohmann::json &, ExtendedOutputsSpec &); - } + +JSON_IMPL(OutputsSpec) +JSON_IMPL(ExtendedOutputsSpec) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 832be08f7..ff57a77ca 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -910,7 +910,12 @@ BuildResult RemoteStore::buildDerivation(const StorePath & drvPath, const BasicD writeDerivation(conn->to, *this, drv); conn->to << buildMode; conn.processStderr(); - BuildResult res { .path = DerivedPath::Built { .drvPath = drvPath } }; + BuildResult res { + .path = DerivedPath::Built { + .drvPath = drvPath, + .outputs = OutputsSpec::All { }, + }, + }; res.status = (BuildResult::Status) readInt(conn->from); conn->from >> res.errorMsg; if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 29) { |