From d8fa7517fad4272e20ff9b9b740c91158bc685e2 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 5 Apr 2021 10:33:28 -0400 Subject: buildable.{cc,hh} -> derived-path.{cc,hh} --- src/libcmd/installables.hh | 2 +- src/libmain/shared.hh | 2 +- src/libstore/buildable.cc | 77 ------------------------------------- src/libstore/buildable.hh | 81 --------------------------------------- src/libstore/derived-path.cc | 77 +++++++++++++++++++++++++++++++++++++ src/libstore/derived-path.hh | 81 +++++++++++++++++++++++++++++++++++++++ src/libstore/path-with-outputs.hh | 2 +- src/libstore/store-api.hh | 2 +- 8 files changed, 162 insertions(+), 162 deletions(-) delete mode 100644 src/libstore/buildable.cc delete mode 100644 src/libstore/buildable.hh create mode 100644 src/libstore/derived-path.cc create mode 100644 src/libstore/derived-path.hh diff --git a/src/libcmd/installables.hh b/src/libcmd/installables.hh index 0bc932b52..403403c07 100644 --- a/src/libcmd/installables.hh +++ b/src/libcmd/installables.hh @@ -3,7 +3,7 @@ #include "util.hh" #include "path.hh" #include "path-with-outputs.hh" -#include "buildable.hh" +#include "derived-path.hh" #include "eval.hh" #include "flake/flake.hh" diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index 9cb9e6da2..05277d90a 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -4,7 +4,7 @@ #include "args.hh" #include "common-args.hh" #include "path.hh" -#include "buildable.hh" +#include "derived-path.hh" #include diff --git a/src/libstore/buildable.cc b/src/libstore/buildable.cc deleted file mode 100644 index eee38ba10..000000000 --- a/src/libstore/buildable.cc +++ /dev/null @@ -1,77 +0,0 @@ -#include "buildable.hh" -#include "store-api.hh" - -#include - -namespace nix { - -nlohmann::json DerivedPath::Opaque::toJSON(ref store) const { - nlohmann::json res; - res["path"] = store->printStorePath(path); - return res; -} - -nlohmann::json DerivedPathWithHints::Built::toJSON(ref store) const { - nlohmann::json res; - res["drvPath"] = store->printStorePath(drvPath); - for (const auto& [output, path] : outputs) { - res["outputs"][output] = path ? store->printStorePath(*path) : ""; - } - return res; -} - -nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref store) { - auto res = nlohmann::json::array(); - for (const DerivedPathWithHints & buildable : buildables) { - std::visit([&res, store](const auto & buildable) { - res.push_back(buildable.toJSON(store)); - }, buildable.raw()); - } - return res; -} - - -std::string DerivedPath::Opaque::to_string(const Store & store) const { - return store.printStorePath(path); -} - -std::string DerivedPath::Built::to_string(const Store & store) const { - return store.printStorePath(drvPath) - + "!" - + (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs)); -} - -std::string DerivedPath::to_string(const Store & store) const -{ - return std::visit( - [&](const auto & req) { return req.to_string(store); }, - this->raw()); -} - - -DerivedPath::Opaque DerivedPath::Opaque::parse(const Store & store, std::string_view s) -{ - return {store.parseStorePath(s)}; -} - -DerivedPath::Built DerivedPath::Built::parse(const Store & store, std::string_view s) -{ - size_t n = s.find("!"); - assert(n != s.npos); - auto drvPath = store.parseStorePath(s.substr(0, n)); - auto outputsS = s.substr(n + 1); - std::set outputs; - if (outputsS != "*") - outputs = tokenizeString>(outputsS); - return {drvPath, outputs}; -} - -DerivedPath DerivedPath::parse(const Store & store, std::string_view s) -{ - size_t n = s.find("!"); - return n == s.npos - ? (DerivedPath) DerivedPath::Opaque::parse(store, s) - : (DerivedPath) DerivedPath::Built::parse(store, s); -} - -} diff --git a/src/libstore/buildable.hh b/src/libstore/buildable.hh deleted file mode 100644 index ce5ae5fc0..000000000 --- a/src/libstore/buildable.hh +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include "util.hh" -#include "path.hh" -#include "path.hh" - -#include - -#include - -namespace nix { - -class Store; - -struct DerivedPathOpaque { - StorePath path; - - nlohmann::json toJSON(ref store) const; - std::string to_string(const Store & store) const; - static DerivedPathOpaque parse(const Store & store, std::string_view); -}; - -struct DerivedPathBuilt { - StorePath drvPath; - std::set outputs; - - std::string to_string(const Store & store) const; - static DerivedPathBuilt parse(const Store & store, std::string_view); -}; - -using _DerivedPathRaw = std::variant< - DerivedPathOpaque, - DerivedPathBuilt ->; - -struct DerivedPath : _DerivedPathRaw { - using Raw = _DerivedPathRaw; - using Raw::Raw; - - using Opaque = DerivedPathOpaque; - using Built = DerivedPathBuilt; - - inline const Raw & raw() const { - return static_cast(*this); - } - - std::string to_string(const Store & store) const; - static DerivedPath parse(const Store & store, std::string_view); -}; - -struct DerivedPathWithHintsBuilt { - StorePath drvPath; - std::map> outputs; - - nlohmann::json toJSON(ref store) const; - static DerivedPathWithHintsBuilt parse(const Store & store, std::string_view); -}; - -using _DerivedPathWithHintsRaw = std::variant< - DerivedPath::Opaque, - DerivedPathWithHintsBuilt ->; - -struct DerivedPathWithHints : _DerivedPathWithHintsRaw { - using Raw = _DerivedPathWithHintsRaw; - using Raw::Raw; - - using Opaque = DerivedPathOpaque; - using Built = DerivedPathWithHintsBuilt; - - inline const Raw & raw() const { - return static_cast(*this); - } - -}; - -typedef std::vector DerivedPathsWithHints; - -nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref store); - -} diff --git a/src/libstore/derived-path.cc b/src/libstore/derived-path.cc new file mode 100644 index 000000000..13833c58e --- /dev/null +++ b/src/libstore/derived-path.cc @@ -0,0 +1,77 @@ +#include "derived-path.hh" +#include "store-api.hh" + +#include + +namespace nix { + +nlohmann::json DerivedPath::Opaque::toJSON(ref store) const { + nlohmann::json res; + res["path"] = store->printStorePath(path); + return res; +} + +nlohmann::json DerivedPathWithHints::Built::toJSON(ref store) const { + nlohmann::json res; + res["drvPath"] = store->printStorePath(drvPath); + for (const auto& [output, path] : outputs) { + res["outputs"][output] = path ? store->printStorePath(*path) : ""; + } + return res; +} + +nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref store) { + auto res = nlohmann::json::array(); + for (const DerivedPathWithHints & buildable : buildables) { + std::visit([&res, store](const auto & buildable) { + res.push_back(buildable.toJSON(store)); + }, buildable.raw()); + } + return res; +} + + +std::string DerivedPath::Opaque::to_string(const Store & store) const { + return store.printStorePath(path); +} + +std::string DerivedPath::Built::to_string(const Store & store) const { + return store.printStorePath(drvPath) + + "!" + + (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs)); +} + +std::string DerivedPath::to_string(const Store & store) const +{ + return std::visit( + [&](const auto & req) { return req.to_string(store); }, + this->raw()); +} + + +DerivedPath::Opaque DerivedPath::Opaque::parse(const Store & store, std::string_view s) +{ + return {store.parseStorePath(s)}; +} + +DerivedPath::Built DerivedPath::Built::parse(const Store & store, std::string_view s) +{ + size_t n = s.find("!"); + assert(n != s.npos); + auto drvPath = store.parseStorePath(s.substr(0, n)); + auto outputsS = s.substr(n + 1); + std::set outputs; + if (outputsS != "*") + outputs = tokenizeString>(outputsS); + return {drvPath, outputs}; +} + +DerivedPath DerivedPath::parse(const Store & store, std::string_view s) +{ + size_t n = s.find("!"); + return n == s.npos + ? (DerivedPath) DerivedPath::Opaque::parse(store, s) + : (DerivedPath) DerivedPath::Built::parse(store, s); +} + +} diff --git a/src/libstore/derived-path.hh b/src/libstore/derived-path.hh new file mode 100644 index 000000000..ce5ae5fc0 --- /dev/null +++ b/src/libstore/derived-path.hh @@ -0,0 +1,81 @@ +#pragma once + +#include "util.hh" +#include "path.hh" +#include "path.hh" + +#include + +#include + +namespace nix { + +class Store; + +struct DerivedPathOpaque { + StorePath path; + + nlohmann::json toJSON(ref store) const; + std::string to_string(const Store & store) const; + static DerivedPathOpaque parse(const Store & store, std::string_view); +}; + +struct DerivedPathBuilt { + StorePath drvPath; + std::set outputs; + + std::string to_string(const Store & store) const; + static DerivedPathBuilt parse(const Store & store, std::string_view); +}; + +using _DerivedPathRaw = std::variant< + DerivedPathOpaque, + DerivedPathBuilt +>; + +struct DerivedPath : _DerivedPathRaw { + using Raw = _DerivedPathRaw; + using Raw::Raw; + + using Opaque = DerivedPathOpaque; + using Built = DerivedPathBuilt; + + inline const Raw & raw() const { + return static_cast(*this); + } + + std::string to_string(const Store & store) const; + static DerivedPath parse(const Store & store, std::string_view); +}; + +struct DerivedPathWithHintsBuilt { + StorePath drvPath; + std::map> outputs; + + nlohmann::json toJSON(ref store) const; + static DerivedPathWithHintsBuilt parse(const Store & store, std::string_view); +}; + +using _DerivedPathWithHintsRaw = std::variant< + DerivedPath::Opaque, + DerivedPathWithHintsBuilt +>; + +struct DerivedPathWithHints : _DerivedPathWithHintsRaw { + using Raw = _DerivedPathWithHintsRaw; + using Raw::Raw; + + using Opaque = DerivedPathOpaque; + using Built = DerivedPathWithHintsBuilt; + + inline const Raw & raw() const { + return static_cast(*this); + } + +}; + +typedef std::vector DerivedPathsWithHints; + +nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref store); + +} diff --git a/src/libstore/path-with-outputs.hh b/src/libstore/path-with-outputs.hh index 749348398..4c4023dcb 100644 --- a/src/libstore/path-with-outputs.hh +++ b/src/libstore/path-with-outputs.hh @@ -3,7 +3,7 @@ #include #include "path.hh" -#include "buildable.hh" +#include "derived-path.hh" namespace nix { diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 483f3c5fa..f66298991 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -2,7 +2,7 @@ #include "realisation.hh" #include "path.hh" -#include "buildable.hh" +#include "derived-path.hh" #include "hash.hh" #include "content-address.hh" #include "serialise.hh" -- cgit v1.2.3