Skip to content

Commit

Permalink
Clean up app.cc (#9201)
Browse files Browse the repository at this point in the history
- Rename `expected` to `expectedType`

- Use early `return` and `continue` to reduce nesting
  • Loading branch information
trofkm committed Oct 22, 2023
1 parent edc0758 commit 201a4af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ nix-rust/target

result

# IDE
.vscode/
.idea/

# clangd and possibly more
.cache/
40 changes: 22 additions & 18 deletions src/nix/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ StringPairs resolveRewrites(
const std::vector<BuiltPathWithResult> & dependencies)
{
StringPairs res;
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
for (auto & dep : dependencies) {
if (auto drvDep = std::get_if<BuiltPathBuilt>(&dep.path)) {
for (auto & [ outputName, outputPath ] : drvDep->outputs) {
res.emplace(
DownstreamPlaceholder::fromSingleDerivedPathBuilt(
SingleDerivedPath::Built {
.drvPath = make_ref<SingleDerivedPath>(drvDep->drvPath->discardOutputPath()),
.output = outputName,
}).render(),
store.printStorePath(outputPath)
);
}
}
if (!experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
return res;
}
for (auto &dep: dependencies) {
auto drvDep = std::get_if<BuiltPathBuilt>(&dep.path);
if (!drvDep) {
continue;
}

for (const auto & [ outputName, outputPath ] : drvDep->outputs) {
res.emplace(
DownstreamPlaceholder::fromSingleDerivedPathBuilt(
SingleDerivedPath::Built {
.drvPath = make_ref<SingleDerivedPath>(drvDep->drvPath->discardOutputPath()),
.output = outputName,
}).render(),
store.printStorePath(outputPath)
);
}
}
return res;
Expand All @@ -58,11 +62,11 @@ UnresolvedApp InstallableValue::toApp(EvalState & state)

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")
? "app" : "derivation";
if (type != expected)
throw Error("attribute '%s' should have type '%s'", cursor->getAttrPathStr(), expected);
if (type != expectedType)
throw Error("attribute '%s' should have type '%s'", cursor->getAttrPathStr(), expectedType);

if (type == "app") {
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
Expand Down Expand Up @@ -91,7 +95,7 @@ UnresolvedApp InstallableValue::toApp(EvalState & state)
}, c.raw));
}

return UnresolvedApp{App {
return UnresolvedApp { App {
.context = std::move(context2),
.program = program,
}};
Expand Down

0 comments on commit 201a4af

Please sign in to comment.