forked from lix-project/lix
Merge pull request #7539 from tweag/fix-nix-why-depends--derivation
Fix `nix why-depends --derivation`
This commit is contained in:
commit
0fe2b222d5
|
@ -931,10 +931,7 @@ std::vector<std::pair<std::shared_ptr<Installable>, BuiltPathWithResult>> Instal
|
|||
DrvOutput outputId { *outputHash, output };
|
||||
auto realisation = store->queryRealisation(outputId);
|
||||
if (!realisation)
|
||||
throw Error(
|
||||
"cannot operate on an output of the "
|
||||
"unbuilt derivation '%s'",
|
||||
outputId.to_string());
|
||||
throw MissingRealisation(outputId);
|
||||
outputs.insert_or_assign(output, realisation->outPath);
|
||||
} else {
|
||||
// If ca-derivations isn't enabled, assume that
|
||||
|
|
|
@ -93,4 +93,14 @@ struct RealisedPath {
|
|||
GENERATE_CMP(RealisedPath, me->raw);
|
||||
};
|
||||
|
||||
class MissingRealisation : public Error
|
||||
{
|
||||
public:
|
||||
MissingRealisation(DrvOutput & outputId)
|
||||
: Error( "cannot operate on an output of the "
|
||||
"unbuilt derivation '%s'",
|
||||
outputId.to_string())
|
||||
{}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -879,10 +879,7 @@ std::vector<BuildResult> RemoteStore::buildPathsWithResults(
|
|||
auto realisation =
|
||||
queryRealisation(outputId);
|
||||
if (!realisation)
|
||||
throw Error(
|
||||
"cannot operate on an output of unbuilt "
|
||||
"content-addressed derivation '%s'",
|
||||
outputId.to_string());
|
||||
throw MissingRealisation(outputId);
|
||||
res.builtOutputs.emplace(realisation->id, *realisation);
|
||||
} else {
|
||||
// If ca-derivations isn't enabled, assume that
|
||||
|
|
|
@ -95,23 +95,13 @@ struct CmdWhyDepends : SourceExprCommand
|
|||
* to build.
|
||||
*/
|
||||
auto dependency = parseInstallable(store, _dependency);
|
||||
auto derivedDependency = dependency->toDerivedPath();
|
||||
auto optDependencyPath = std::visit(overloaded {
|
||||
[](const DerivedPath::Opaque & nodrv) -> std::optional<StorePath> {
|
||||
return { nodrv.path };
|
||||
},
|
||||
[&](const DerivedPath::Built & hasdrv) -> std::optional<StorePath> {
|
||||
if (hasdrv.outputs.size() != 1) {
|
||||
throw Error("argument '%s' should evaluate to one store path", dependency->what());
|
||||
}
|
||||
auto outputMap = store->queryPartialDerivationOutputMap(hasdrv.drvPath);
|
||||
auto maybePath = outputMap.find(*hasdrv.outputs.begin());
|
||||
if (maybePath == outputMap.end()) {
|
||||
throw Error("unexpected end of iterator");
|
||||
}
|
||||
return maybePath->second;
|
||||
},
|
||||
}, derivedDependency.raw());
|
||||
auto optDependencyPath = [&]() -> std::optional<StorePath> {
|
||||
try {
|
||||
return {Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency)};
|
||||
} catch (MissingRealisation &) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}();
|
||||
|
||||
StorePathSet closure;
|
||||
store->computeFSClosure({packagePath}, closure, false, false);
|
||||
|
|
|
@ -92,6 +92,7 @@ nix_tests = \
|
|||
fmt.sh \
|
||||
eval-store.sh \
|
||||
why-depends.sh \
|
||||
ca/why-depends.sh \
|
||||
import-derivation.sh \
|
||||
ca/import-derivation.sh \
|
||||
nix_path.sh \
|
||||
|
|
|
@ -6,6 +6,9 @@ cp ./dependencies.nix ./dependencies.builder0.sh ./config.nix $TEST_HOME
|
|||
|
||||
cd $TEST_HOME
|
||||
|
||||
nix why-depends --derivation --file ./dependencies.nix input2_drv input1_drv
|
||||
nix why-depends --file ./dependencies.nix input2_drv input1_drv
|
||||
|
||||
nix-build ./dependencies.nix -A input0_drv -o dep
|
||||
nix-build ./dependencies.nix -o toplevel
|
||||
|
||||
|
|
Loading…
Reference in a new issue