#include "outputs-spec.hh" #include "nlohmann/json.hpp" #include namespace nix { std::pair parseOutputsSpec(const std::string & s) { static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))"); std::smatch match; if (!std::regex_match(s, match, regex)) return {s, DefaultOutputs()}; if (match[3].matched) return {match[1], AllOutputs()}; 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; } } }