From a3c6c5b1c745a72a6a46bdf1a1de7a51a53f76b0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 May 2022 14:37:28 +0200 Subject: nix profile: Support overriding outputs --- src/libstore/path-with-outputs.cc | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/libstore/path-with-outputs.cc') diff --git a/src/libstore/path-with-outputs.cc b/src/libstore/path-with-outputs.cc index 7d180a0f6..d6d67ea05 100644 --- a/src/libstore/path-with-outputs.cc +++ b/src/libstore/path-with-outputs.cc @@ -1,5 +1,6 @@ #include "path-with-outputs.hh" #include "store-api.hh" +#include "nlohmann/json.hpp" #include @@ -84,4 +85,43 @@ std::pair parseOutputsSpec(const std::string & s) return {match[1], tokenizeString(match[4].str(), ",")}; } +std::string printOutputsSpec(const OutputsSpec & outputsSpec) +{ + if (std::get_if(&outputsSpec)) + return ""; + + if (std::get_if(&outputsSpec)) + return "^*"; + + if (auto outputNames = std::get_if(&outputsSpec)) + return "^" + concatStringsSep(",", *outputNames); + + assert(false); +} + +void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec) +{ + if (std::get_if(&outputsSpec)) + json = nullptr; + + else if (std::get_if(&outputsSpec)) + json = std::vector({"*"}); + + else if (auto outputNames = std::get_if(&outputsSpec)) + json = *outputNames; +} + +void from_json(const nlohmann::json & json, OutputsSpec & outputsSpec) +{ + if (json.is_null()) + outputsSpec = DefaultOutputs(); + else { + auto names = json.get(); + if (names == OutputNames({"*"})) + outputsSpec = AllOutputs(); + else + outputsSpec = names; + } +} + } -- cgit v1.2.3