Clean up app.cc (#9201)

- Rename `expected` to `expectedType`

- Use early `return` and `continue` to reduce nesting
This commit is contained in:
Кирилл Трофимов 2023-10-23 01:56:46 +03:00 committed by GitHub
parent edc07588ec
commit 201a4af9a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 18 deletions

2
.gitignore vendored
View file

@ -138,7 +138,9 @@ nix-rust/target
result result
# IDE
.vscode/ .vscode/
.idea/
# clangd and possibly more # clangd and possibly more
.cache/ .cache/

View file

@ -20,10 +20,16 @@ StringPairs resolveRewrites(
const std::vector<BuiltPathWithResult> & dependencies) const std::vector<BuiltPathWithResult> & dependencies)
{ {
StringPairs res; StringPairs res;
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) { if (!experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
return res;
}
for (auto &dep: dependencies) { for (auto &dep: dependencies) {
if (auto drvDep = std::get_if<BuiltPathBuilt>(&dep.path)) { auto drvDep = std::get_if<BuiltPathBuilt>(&dep.path);
for (auto & [ outputName, outputPath ] : drvDep->outputs) { if (!drvDep) {
continue;
}
for (const auto & [ outputName, outputPath ] : drvDep->outputs) {
res.emplace( res.emplace(
DownstreamPlaceholder::fromSingleDerivedPathBuilt( DownstreamPlaceholder::fromSingleDerivedPathBuilt(
SingleDerivedPath::Built { SingleDerivedPath::Built {
@ -34,8 +40,6 @@ StringPairs resolveRewrites(
); );
} }
} }
}
}
return res; return res;
} }
@ -58,11 +62,11 @@ UnresolvedApp InstallableValue::toApp(EvalState & state)
auto type = cursor->getAttr("type")->getString(); auto type = cursor->getAttr("type")->getString();
std::string expected = !attrPath.empty() && std::string expectedType = !attrPath.empty() &&
(state.symbols[attrPath[0]] == "apps" || state.symbols[attrPath[0]] == "defaultApp") (state.symbols[attrPath[0]] == "apps" || state.symbols[attrPath[0]] == "defaultApp")
? "app" : "derivation"; ? "app" : "derivation";
if (type != expected) if (type != expectedType)
throw Error("attribute '%s' should have type '%s'", cursor->getAttrPathStr(), expected); throw Error("attribute '%s' should have type '%s'", cursor->getAttrPathStr(), expectedType);
if (type == "app") { if (type == "app") {
auto [program, context] = cursor->getAttr("program")->getStringWithContext(); auto [program, context] = cursor->getAttr("program")->getStringWithContext();