Merge pull request #7337 from Radvendii/why-depends-ca
Fix why-depends for CA derivations
This commit is contained in:
commit
bc9692a6b7
|
@ -83,20 +83,47 @@ struct CmdWhyDepends : SourceExprCommand
|
||||||
{
|
{
|
||||||
auto package = parseInstallable(store, _package);
|
auto package = parseInstallable(store, _package);
|
||||||
auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package);
|
auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package);
|
||||||
|
|
||||||
|
/* We don't need to build `dependency`. We try to get the store
|
||||||
|
* path if it's already known, and if not, then it's not a dependency.
|
||||||
|
*
|
||||||
|
* Why? If `package` does depends on `dependency`, then getting the
|
||||||
|
* store path of `package` above necessitated having the store path
|
||||||
|
* of `dependency`. The contrapositive is, if the store path of
|
||||||
|
* `dependency` is not already known at this point (i.e. it's a CA
|
||||||
|
* derivation which hasn't been built), then `package` did not need it
|
||||||
|
* to build.
|
||||||
|
*/
|
||||||
auto dependency = parseInstallable(store, _dependency);
|
auto dependency = parseInstallable(store, _dependency);
|
||||||
auto dependencyPath = Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency);
|
auto derivedDependency = dependency->toDerivedPath();
|
||||||
auto dependencyPathHash = dependencyPath.hashPart();
|
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());
|
||||||
|
|
||||||
StorePathSet closure;
|
StorePathSet closure;
|
||||||
store->computeFSClosure({packagePath}, closure, false, false);
|
store->computeFSClosure({packagePath}, closure, false, false);
|
||||||
|
|
||||||
if (!closure.count(dependencyPath)) {
|
if (!optDependencyPath.has_value() || !closure.count(*optDependencyPath)) {
|
||||||
printError("'%s' does not depend on '%s'",
|
printError("'%s' does not depend on '%s'", package->what(), dependency->what());
|
||||||
store->printStorePath(packagePath),
|
|
||||||
store->printStorePath(dependencyPath));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto dependencyPath = *optDependencyPath;
|
||||||
|
auto dependencyPathHash = dependencyPath.hashPart();
|
||||||
|
|
||||||
stopProgressBar(); // FIXME
|
stopProgressBar(); // FIXME
|
||||||
|
|
||||||
auto accessor = store->getFSAccessor();
|
auto accessor = store->getFSAccessor();
|
||||||
|
|
5
tests/ca/why-depends.sh
Normal file
5
tests/ca/why-depends.sh
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
export NIX_TESTS_CA_BY_DEFAULT=1
|
||||||
|
|
||||||
|
cd .. && source why-depends.sh
|
Loading…
Reference in a new issue