aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/realisation.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-02-25 21:58:41 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-02-25 21:58:41 +0000
commit90d76fa399de4e207ea14ec4c0dd65434f60c152 (patch)
tree3c52e982cba5bcf7b91c99d1b63ba967b4ea8b92 /src/libstore/realisation.cc
parent4636cc9a1f6de70947abbfb17a0ad91981d1cad7 (diff)
parentca0994819d68aee26a2906c37a47ae609ac46c4c (diff)
Merge remote-tracking branch 'obsidian/path-info' into ca-drv-exotic
Diffstat (limited to 'src/libstore/realisation.cc')
-rw-r--r--src/libstore/realisation.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/libstore/realisation.cc b/src/libstore/realisation.cc
new file mode 100644
index 000000000..cd74af4ee
--- /dev/null
+++ b/src/libstore/realisation.cc
@@ -0,0 +1,80 @@
+#include "realisation.hh"
+#include "store-api.hh"
+#include <nlohmann/json.hpp>
+
+namespace nix {
+
+MakeError(InvalidDerivationOutputId, Error);
+
+DrvOutput DrvOutput::parse(const std::string &strRep) {
+ size_t n = strRep.find("!");
+ if (n == strRep.npos)
+ throw InvalidDerivationOutputId("Invalid derivation output id %s", strRep);
+
+ return DrvOutput{
+ .drvHash = Hash::parseAnyPrefixed(strRep.substr(0, n)),
+ .outputName = strRep.substr(n+1),
+ };
+}
+
+std::string DrvOutput::to_string() const {
+ return strHash() + "!" + outputName;
+}
+
+nlohmann::json Realisation::toJSON() const {
+ return nlohmann::json{
+ {"id", id.to_string()},
+ {"outPath", outPath.to_string()},
+ };
+}
+
+Realisation Realisation::fromJSON(
+ const nlohmann::json& json,
+ const std::string& whence) {
+ auto getField = [&](std::string fieldName) -> std::string {
+ auto fieldIterator = json.find(fieldName);
+ if (fieldIterator == json.end())
+ throw Error(
+ "Drv output info file '%1%' is corrupt, missing field %2%",
+ whence, fieldName);
+ return *fieldIterator;
+ };
+
+ return Realisation{
+ .id = DrvOutput::parse(getField("id")),
+ .outPath = StorePath(getField("outPath")),
+ };
+}
+
+StorePath RealisedPath::path() const {
+ return std::visit([](auto && arg) { return arg.getPath(); }, raw);
+}
+
+void RealisedPath::closure(
+ Store& store,
+ const RealisedPath::Set& startPaths,
+ RealisedPath::Set& ret)
+{
+ // FIXME: This only builds the store-path closure, not the real realisation
+ // closure
+ StorePathSet initialStorePaths, pathsClosure;
+ for (auto& path : startPaths)
+ initialStorePaths.insert(path.path());
+ store.computeFSClosure(initialStorePaths, pathsClosure);
+ ret.insert(startPaths.begin(), startPaths.end());
+ ret.insert(pathsClosure.begin(), pathsClosure.end());
+}
+
+void RealisedPath::closure(Store& store, RealisedPath::Set & ret) const
+{
+ RealisedPath::closure(store, {*this}, ret);
+}
+
+RealisedPath::Set RealisedPath::closure(Store& store) const
+{
+ RealisedPath::Set ret;
+ closure(store, ret);
+ return ret;
+}
+
+} // namespace nix