2021-04-05 17:33:28 +03:00
|
|
|
#include "derived-path.hh"
|
2021-03-01 07:48:01 +02:00
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
nlohmann::json DerivedPath::Opaque::toJSON(ref<Store> store) const {
|
2021-03-01 07:48:01 +02:00
|
|
|
nlohmann::json res;
|
|
|
|
res["path"] = store->printStorePath(path);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-04-05 17:05:21 +03:00
|
|
|
nlohmann::json DerivedPathWithHints::Built::toJSON(ref<Store> store) const {
|
2021-03-01 07:48:01 +02:00
|
|
|
nlohmann::json res;
|
|
|
|
res["drvPath"] = store->printStorePath(drvPath);
|
|
|
|
for (const auto& [output, path] : outputs) {
|
|
|
|
res["outputs"][output] = path ? store->printStorePath(*path) : "";
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store) {
|
2021-03-01 07:48:01 +02:00
|
|
|
auto res = nlohmann::json::array();
|
2021-04-05 16:48:18 +03:00
|
|
|
for (const DerivedPathWithHints & buildable : buildables) {
|
2021-03-01 07:48:01 +02:00
|
|
|
std::visit([&res, store](const auto & buildable) {
|
|
|
|
res.push_back(buildable.toJSON(store));
|
2021-04-05 17:05:21 +03:00
|
|
|
}, buildable.raw());
|
2021-03-01 07:48:01 +02:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-03-02 05:50:41 +02:00
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
std::string DerivedPath::Opaque::to_string(const Store & store) const {
|
2021-03-02 05:50:41 +02:00
|
|
|
return store.printStorePath(path);
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
std::string DerivedPath::Built::to_string(const Store & store) const {
|
2021-03-02 05:50:41 +02:00
|
|
|
return store.printStorePath(drvPath)
|
|
|
|
+ "!"
|
|
|
|
+ (outputs.empty() ? std::string { "*" } : concatStringsSep(",", outputs));
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
std::string DerivedPath::to_string(const Store & store) const
|
2021-03-02 05:50:41 +02:00
|
|
|
{
|
|
|
|
return std::visit(
|
|
|
|
[&](const auto & req) { return req.to_string(store); },
|
2021-04-05 16:24:42 +03:00
|
|
|
this->raw());
|
2021-03-02 05:50:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
DerivedPath::Opaque DerivedPath::Opaque::parse(const Store & store, std::string_view s)
|
2021-03-02 05:50:41 +02:00
|
|
|
{
|
|
|
|
return {store.parseStorePath(s)};
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
DerivedPath::Built DerivedPath::Built::parse(const Store & store, std::string_view s)
|
2021-03-02 05:50:41 +02:00
|
|
|
{
|
|
|
|
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<string> outputs;
|
|
|
|
if (outputsS != "*")
|
|
|
|
outputs = tokenizeString<std::set<string>>(outputsS);
|
|
|
|
return {drvPath, outputs};
|
|
|
|
}
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
DerivedPath DerivedPath::parse(const Store & store, std::string_view s)
|
2021-03-02 05:50:41 +02:00
|
|
|
{
|
|
|
|
size_t n = s.find("!");
|
|
|
|
return n == s.npos
|
2021-04-05 16:48:18 +03:00
|
|
|
? (DerivedPath) DerivedPath::Opaque::parse(store, s)
|
|
|
|
: (DerivedPath) DerivedPath::Built::parse(store, s);
|
2021-03-02 05:50:41 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 07:48:01 +02:00
|
|
|
}
|