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