forked from lix-project/lix
34 lines
880 B
C++
34 lines
880 B
C++
|
#include "buildable.hh"
|
||
|
#include "store-api.hh"
|
||
|
|
||
|
#include <nlohmann/json.hpp>
|
||
|
|
||
|
namespace nix {
|
||
|
|
||
|
nlohmann::json BuildableOpaque::toJSON(ref<Store> store) const {
|
||
|
nlohmann::json res;
|
||
|
res["path"] = store->printStorePath(path);
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
nlohmann::json BuildableFromDrv::toJSON(ref<Store> 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 buildablesToJSON(const Buildables & buildables, ref<Store> store) {
|
||
|
auto res = nlohmann::json::array();
|
||
|
for (const Buildable & buildable : buildables) {
|
||
|
std::visit([&res, store](const auto & buildable) {
|
||
|
res.push_back(buildable.toJSON(store));
|
||
|
}, buildable);
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
}
|