Remove support for old lockfiles and the epoch/uri attributes

This commit is contained in:
Eelco Dolstra 2020-05-06 17:48:18 +02:00
parent b0e9b07e80
commit 1ad71bc62c
3 changed files with 28 additions and 62 deletions

View file

@ -3,7 +3,7 @@
edition = 201909; # FIXME: remove edition = 201909; # FIXME: remove
inputs.nixpkgs.uri = "nixpkgs/nixos-20.03-small"; inputs.nixpkgs.url = "nixpkgs/nixos-20.03-small";
outputs = { self, nixpkgs }: outputs = { self, nixpkgs }:

View file

@ -129,7 +129,6 @@ static FlakeInput parseFlakeInput(EvalState & state,
auto sInputs = state.symbols.create("inputs"); auto sInputs = state.symbols.create("inputs");
auto sUrl = state.symbols.create("url"); auto sUrl = state.symbols.create("url");
auto sUri = state.symbols.create("uri"); // FIXME: remove soon
auto sFlake = state.symbols.create("flake"); auto sFlake = state.symbols.create("flake");
auto sFollows = state.symbols.create("follows"); auto sFollows = state.symbols.create("follows");
@ -138,7 +137,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
for (nix::Attr attr : *(value->attrs)) { for (nix::Attr attr : *(value->attrs)) {
try { try {
if (attr.name == sUrl || attr.name == sUri) { if (attr.name == sUrl) {
expectType(state, tString, *attr.value, *attr.pos); expectType(state, tString, *attr.value, *attr.pos);
url = attr.value->string.s; url = attr.value->string.s;
attrs.emplace("url", *url); attrs.emplace("url", *url);
@ -232,14 +231,10 @@ static Flake getFlake(
expectType(state, tAttrs, vInfo, Pos(state.symbols.create(flakeFile), 0, 0)); expectType(state, tAttrs, vInfo, Pos(state.symbols.create(flakeFile), 0, 0));
auto sEdition = state.symbols.create("edition"); // FIXME: remove soon auto sEdition = state.symbols.create("edition"); // FIXME: remove soon
auto sEpoch = state.symbols.create("epoch"); // FIXME: remove soon
if (vInfo.attrs->get(sEdition)) if (vInfo.attrs->get(sEdition))
warn("flake '%s' has deprecated attribute 'edition'", lockedRef); warn("flake '%s' has deprecated attribute 'edition'", lockedRef);
if (vInfo.attrs->get(sEpoch))
warn("flake '%s' has deprecated attribute 'epoch'", lockedRef);
if (auto description = vInfo.attrs->get(state.sDescription)) { if (auto description = vInfo.attrs->get(state.sDescription)) {
expectType(state, tString, *description->value, *description->pos); expectType(state, tString, *description->value, *description->pos);
flake.description = description->value->string.s; flake.description = description->value->string.s;
@ -270,7 +265,6 @@ static Flake getFlake(
for (auto & attr : *vInfo.attrs) { for (auto & attr : *vInfo.attrs) {
if (attr.name != sEdition && if (attr.name != sEdition &&
attr.name != sEpoch &&
attr.name != state.sDescription && attr.name != state.sDescription &&
attr.name != sInputs && attr.name != sInputs &&
attr.name != sOutputs) attr.name != sOutputs)

View file

@ -12,29 +12,18 @@ FlakeRef flakeRefFromJson(const nlohmann::json & json)
FlakeRef getFlakeRef( FlakeRef getFlakeRef(
const nlohmann::json & json, const nlohmann::json & json,
const char * version3Attr1, const char * attr)
const char * version3Attr2,
const char * version4Attr)
{ {
auto i = json.find(version4Attr); auto i = json.find(attr);
if (i != json.end()) if (i != json.end())
return flakeRefFromJson(*i); return flakeRefFromJson(*i);
// FIXME: remove these. throw Error("attribute '%s' missing in lock file", attr);
i = json.find(version3Attr1);
if (i != json.end())
return parseFlakeRef(*i);
i = json.find(version3Attr2);
if (i != json.end())
return parseFlakeRef(*i);
throw Error("attribute '%s' missing in lock file", version4Attr);
} }
LockedNode::LockedNode(const nlohmann::json & json) LockedNode::LockedNode(const nlohmann::json & json)
: lockedRef(getFlakeRef(json, "url", "uri", "locked")) : lockedRef(getFlakeRef(json, "locked"))
, originalRef(getFlakeRef(json, "originalUrl", "originalUri", "original")) , originalRef(getFlakeRef(json, "original"))
, info(TreeInfo::fromJson(json)) , info(TreeInfo::fromJson(json))
, isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true) , isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true)
{ {
@ -64,49 +53,32 @@ std::shared_ptr<Node> Node::findInput(const InputPath & path)
LockFile::LockFile(const nlohmann::json & json, const Path & path) LockFile::LockFile(const nlohmann::json & json, const Path & path)
{ {
auto version = json.value("version", 0); auto version = json.value("version", 0);
if (version < 3 || version > 5) if (version != 5)
throw Error("lock file '%s' has unsupported version %d", path, version); throw Error("lock file '%s' has unsupported version %d", path, version);
if (version < 5) { std::unordered_map<std::string, std::shared_ptr<Node>> nodeMap;
std::function<void(Node & node, const nlohmann::json & json)> getInputs;
getInputs = [&](Node & node, const nlohmann::json & json) std::function<void(Node & node, const nlohmann::json & jsonNode)> getInputs;
{
for (auto & i : json["inputs"].items()) { getInputs = [&](Node & node, const nlohmann::json & jsonNode)
auto input = std::make_shared<LockedNode>(i.value()); {
getInputs(*input, i.value()); if (jsonNode.find("inputs") == jsonNode.end()) return;
node.inputs.insert_or_assign(i.key(), input); for (auto & i : jsonNode["inputs"].items()) {
std::string inputKey = i.value();
auto k = nodeMap.find(inputKey);
if (k == nodeMap.end()) {
auto jsonNode2 = json["nodes"][inputKey];
auto input = std::make_shared<LockedNode>(jsonNode2);
k = nodeMap.insert_or_assign(inputKey, input).first;
getInputs(*input, jsonNode2);
} }
}; node.inputs.insert_or_assign(i.key(), k->second);
}
};
getInputs(*root, json); std::string rootKey = json["root"];
} nodeMap.insert_or_assign(rootKey, root);
getInputs(*root, json["nodes"][rootKey]);
else {
std::unordered_map<std::string, std::shared_ptr<Node>> nodeMap;
std::function<void(Node & node, const nlohmann::json & jsonNode)> getInputs;
getInputs = [&](Node & node, const nlohmann::json & jsonNode)
{
if (jsonNode.find("inputs") == jsonNode.end()) return;
for (auto & i : jsonNode["inputs"].items()) {
std::string inputKey = i.value();
auto k = nodeMap.find(inputKey);
if (k == nodeMap.end()) {
auto jsonNode2 = json["nodes"][inputKey];
auto input = std::make_shared<LockedNode>(jsonNode2);
k = nodeMap.insert_or_assign(inputKey, input).first;
getInputs(*input, jsonNode2);
}
node.inputs.insert_or_assign(i.key(), k->second);
}
};
std::string rootKey = json["root"];
nodeMap.insert_or_assign(rootKey, root);
getInputs(*root, json["nodes"][rootKey]);
}
} }
nlohmann::json LockFile::toJson() const nlohmann::json LockFile::toJson() const