mirror of
https://github.com/NixOS/nix
synced 2025-06-29 02:11:15 +02:00
Add EvalState::coerceToStorePath() helper
This is useful whenever we want to evaluate something to a store path (e.g. in get-drvs.cc). Extracted from the lazy-trees branch (where we can require that a store path must come from a store source tree accessor).
This commit is contained in:
parent
3e3d0711d4
commit
b55d79728c
13 changed files with 123 additions and 101 deletions
|
@ -211,7 +211,7 @@ static long comparePriorities(EvalState & state, DrvInfo & drv1, DrvInfo & drv2)
|
|||
// at a time.
|
||||
static bool isPrebuilt(EvalState & state, DrvInfo & elem)
|
||||
{
|
||||
auto path = state.store->parseStorePath(elem.queryOutPath());
|
||||
auto path = elem.queryOutPath();
|
||||
if (state.store->isValidPath(path)) return true;
|
||||
return state.store->querySubstitutablePaths({path}).count(path);
|
||||
}
|
||||
|
@ -429,14 +429,15 @@ static void queryInstSources(EvalState & state,
|
|||
elem.setName(name);
|
||||
|
||||
if (path.isDerivation()) {
|
||||
elem.setDrvPath(state.store->printStorePath(path));
|
||||
elem.setDrvPath(path);
|
||||
auto outputs = state.store->queryDerivationOutputMap(path);
|
||||
elem.setOutPath(state.store->printStorePath(outputs.at("out")));
|
||||
elem.setOutPath(outputs.at("out"));
|
||||
if (name.size() >= drvExtension.size() &&
|
||||
std::string(name, name.size() - drvExtension.size()) == drvExtension)
|
||||
name = name.substr(0, name.size() - drvExtension.size());
|
||||
}
|
||||
else elem.setOutPath(state.store->printStorePath(path));
|
||||
else
|
||||
elem.setOutPath(path);
|
||||
|
||||
elems.push_back(elem);
|
||||
}
|
||||
|
@ -470,13 +471,11 @@ static void queryInstSources(EvalState & state,
|
|||
static void printMissing(EvalState & state, DrvInfos & elems)
|
||||
{
|
||||
std::vector<DerivedPath> targets;
|
||||
for (auto & i : elems) {
|
||||
Path drvPath = i.queryDrvPath();
|
||||
if (drvPath != "")
|
||||
targets.push_back(DerivedPath::Built{state.store->parseStorePath(drvPath)});
|
||||
for (auto & i : elems)
|
||||
if (auto drvPath = i.queryDrvPath())
|
||||
targets.push_back(DerivedPath::Built{*drvPath});
|
||||
else
|
||||
targets.push_back(DerivedPath::Opaque{state.store->parseStorePath(i.queryOutPath())});
|
||||
}
|
||||
targets.push_back(DerivedPath::Opaque{i.queryOutPath()});
|
||||
|
||||
printMissing(state.store, targets);
|
||||
}
|
||||
|
@ -744,14 +743,11 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
if (globals.forceName != "")
|
||||
drv.setName(globals.forceName);
|
||||
|
||||
auto drvPath = drv.queryDrvPath();
|
||||
std::vector<DerivedPath> paths {
|
||||
(drv.queryDrvPath() != "")
|
||||
? (DerivedPath) (DerivedPath::Built {
|
||||
globals.state->store->parseStorePath(drv.queryDrvPath())
|
||||
})
|
||||
: (DerivedPath) (DerivedPath::Opaque {
|
||||
globals.state->store->parseStorePath(drv.queryOutPath())
|
||||
}),
|
||||
drvPath
|
||||
? (DerivedPath) (DerivedPath::Built { *drvPath })
|
||||
: (DerivedPath) (DerivedPath::Opaque { drv.queryOutPath() }),
|
||||
};
|
||||
printMissing(globals.state->store, paths);
|
||||
if (globals.dryRun) return;
|
||||
|
@ -759,8 +755,9 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
|
||||
debug(format("switching to new user environment"));
|
||||
Path generation = createGeneration(
|
||||
ref<LocalFSStore>(store2), globals.profile,
|
||||
store2->parseStorePath(drv.queryOutPath()));
|
||||
ref<LocalFSStore>(store2),
|
||||
globals.profile,
|
||||
drv.queryOutPath());
|
||||
switchLink(globals.profile, generation);
|
||||
}
|
||||
|
||||
|
@ -780,7 +777,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors,
|
|||
split = std::partition(
|
||||
workingElems.begin(), workingElems.end(),
|
||||
[&selectorStorePath, globals](auto &elem) {
|
||||
return selectorStorePath != globals.state->store->parseStorePath(elem.queryOutPath());
|
||||
return selectorStorePath != elem.queryOutPath();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
|
@ -925,9 +922,8 @@ static void queryJSON(Globals & globals, std::vector<DrvInfo> & elems, bool prin
|
|||
if (printOutPath) {
|
||||
DrvInfo::Outputs outputs = i.queryOutputs();
|
||||
JSONObject outputObj = pkgObj.object("outputs");
|
||||
for (auto & j : outputs) {
|
||||
outputObj.attr(j.first, j.second);
|
||||
}
|
||||
for (auto & j : outputs)
|
||||
outputObj.attr(j.first, globals.state->store->printStorePath(j.second));
|
||||
}
|
||||
|
||||
if (printMeta) {
|
||||
|
@ -957,6 +953,8 @@ static void queryJSON(Globals & globals, std::vector<DrvInfo> & elems, bool prin
|
|||
|
||||
static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
auto & store(*globals.state->store);
|
||||
|
||||
Strings remaining;
|
||||
std::string attrPath;
|
||||
|
||||
|
@ -1027,12 +1025,11 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
|
||||
/* We only need to know the installed paths when we are querying
|
||||
the status of the derivation. */
|
||||
PathSet installed; /* installed paths */
|
||||
StorePathSet installed; /* installed paths */
|
||||
|
||||
if (printStatus) {
|
||||
if (printStatus)
|
||||
for (auto & i : installedElems)
|
||||
installed.insert(i.queryOutPath());
|
||||
}
|
||||
|
||||
|
||||
/* Query which paths have substitutes. */
|
||||
|
@ -1042,13 +1039,13 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
StorePathSet paths;
|
||||
for (auto & i : elems)
|
||||
try {
|
||||
paths.insert(globals.state->store->parseStorePath(i.queryOutPath()));
|
||||
paths.insert(i.queryOutPath());
|
||||
} catch (AssertionError & e) {
|
||||
printMsg(lvlTalkative, "skipping derivation named '%s' which gives an assertion failure", i.queryName());
|
||||
i.setFailed();
|
||||
}
|
||||
validPaths = globals.state->store->queryValidPaths(paths);
|
||||
substitutablePaths = globals.state->store->querySubstitutablePaths(paths);
|
||||
validPaths = store.queryValidPaths(paths);
|
||||
substitutablePaths = store.querySubstitutablePaths(paths);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1073,8 +1070,8 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
//Activity act(*logger, lvlDebug, format("outputting query result '%1%'") % i.attrPath);
|
||||
|
||||
if (globals.prebuiltOnly &&
|
||||
!validPaths.count(globals.state->store->parseStorePath(i.queryOutPath())) &&
|
||||
!substitutablePaths.count(globals.state->store->parseStorePath(i.queryOutPath())))
|
||||
!validPaths.count(i.queryOutPath()) &&
|
||||
!substitutablePaths.count(i.queryOutPath()))
|
||||
continue;
|
||||
|
||||
/* For table output. */
|
||||
|
@ -1084,10 +1081,10 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
XMLAttrs attrs;
|
||||
|
||||
if (printStatus) {
|
||||
Path outPath = i.queryOutPath();
|
||||
bool hasSubs = substitutablePaths.count(globals.state->store->parseStorePath(outPath));
|
||||
bool isInstalled = installed.find(outPath) != installed.end();
|
||||
bool isValid = validPaths.count(globals.state->store->parseStorePath(outPath));
|
||||
auto outPath = i.queryOutPath();
|
||||
bool hasSubs = substitutablePaths.count(outPath);
|
||||
bool isInstalled = installed.count(outPath);
|
||||
bool isValid = validPaths.count(outPath);
|
||||
if (xmlOutput) {
|
||||
attrs["installed"] = isInstalled ? "1" : "0";
|
||||
attrs["valid"] = isValid ? "1" : "0";
|
||||
|
@ -1152,9 +1149,9 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
if (printDrvPath) {
|
||||
auto drvPath = i.queryDrvPath();
|
||||
if (xmlOutput) {
|
||||
if (drvPath != "") attrs["drvPath"] = drvPath;
|
||||
if (drvPath) attrs["drvPath"] = store.printStorePath(*drvPath);
|
||||
} else
|
||||
columns.push_back(drvPath == "" ? "-" : drvPath);
|
||||
columns.push_back(drvPath ? store.printStorePath(*drvPath) : "-");
|
||||
}
|
||||
|
||||
if (printOutPath && !xmlOutput) {
|
||||
|
@ -1163,7 +1160,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
for (auto & j : outputs) {
|
||||
if (!s.empty()) s += ';';
|
||||
if (j.first != "out") { s += j.first; s += "="; }
|
||||
s += j.second;
|
||||
s += store.printStorePath(j.second);
|
||||
}
|
||||
columns.push_back(s);
|
||||
}
|
||||
|
@ -1184,7 +1181,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
for (auto & j : outputs) {
|
||||
XMLAttrs attrs2;
|
||||
attrs2["name"] = j.first;
|
||||
attrs2["path"] = j.second;
|
||||
attrs2["path"] = store.printStorePath(j.second);
|
||||
xml.writeEmptyElement("output", attrs2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
exist already. */
|
||||
std::vector<StorePathWithOutputs> drvsToBuild;
|
||||
for (auto & i : elems)
|
||||
if (i.queryDrvPath() != "")
|
||||
drvsToBuild.push_back({state.store->parseStorePath(i.queryDrvPath())});
|
||||
if (auto drvPath = i.queryDrvPath())
|
||||
drvsToBuild.push_back({*drvPath});
|
||||
|
||||
debug(format("building user environment dependencies"));
|
||||
state.store->buildPaths(
|
||||
|
@ -55,7 +55,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
/* Create a pseudo-derivation containing the name, system,
|
||||
output paths, and optionally the derivation path, as well
|
||||
as the meta attributes. */
|
||||
Path drvPath = keepDerivations ? i.queryDrvPath() : "";
|
||||
std::optional<StorePath> drvPath = keepDerivations ? i.queryDrvPath() : std::nullopt;
|
||||
DrvInfo::Outputs outputs = i.queryOutputs(true);
|
||||
StringSet metaNames = i.queryMetaNames();
|
||||
|
||||
|
@ -66,9 +66,9 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
auto system = i.querySystem();
|
||||
if (!system.empty())
|
||||
attrs.alloc(state.sSystem).mkString(system);
|
||||
attrs.alloc(state.sOutPath).mkString(i.queryOutPath());
|
||||
if (drvPath != "")
|
||||
attrs.alloc(state.sDrvPath).mkString(i.queryDrvPath());
|
||||
attrs.alloc(state.sOutPath).mkString(state.store->printStorePath(i.queryOutPath()));
|
||||
if (drvPath)
|
||||
attrs.alloc(state.sDrvPath).mkString(state.store->printStorePath(*drvPath));
|
||||
|
||||
// Copy each output meant for installation.
|
||||
auto & vOutputs = attrs.alloc(state.sOutputs);
|
||||
|
@ -76,15 +76,15 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
for (const auto & [m, j] : enumerate(outputs)) {
|
||||
(vOutputs.listElems()[m] = state.allocValue())->mkString(j.first);
|
||||
auto outputAttrs = state.buildBindings(2);
|
||||
outputAttrs.alloc(state.sOutPath).mkString(j.second);
|
||||
outputAttrs.alloc(state.sOutPath).mkString(state.store->printStorePath(j.second));
|
||||
attrs.alloc(j.first).mkAttrs(outputAttrs);
|
||||
|
||||
/* This is only necessary when installing store paths, e.g.,
|
||||
`nix-env -i /nix/store/abcd...-foo'. */
|
||||
state.store->addTempRoot(state.store->parseStorePath(j.second));
|
||||
state.store->ensurePath(state.store->parseStorePath(j.second));
|
||||
state.store->addTempRoot(j.second);
|
||||
state.store->ensurePath(j.second);
|
||||
|
||||
references.insert(state.store->parseStorePath(j.second));
|
||||
references.insert(j.second);
|
||||
}
|
||||
|
||||
// Copy the meta attributes.
|
||||
|
@ -99,7 +99,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
|
||||
(manifest.listElems()[n++] = state.allocValue())->mkAttrs(attrs);
|
||||
|
||||
if (drvPath != "") references.insert(state.store->parseStorePath(drvPath));
|
||||
if (drvPath) references.insert(*drvPath);
|
||||
}
|
||||
|
||||
/* Also write a copy of the list of user environment elements to
|
||||
|
@ -132,9 +132,9 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
state.forceValue(topLevel, [&]() { return topLevel.determinePos(noPos); });
|
||||
PathSet context;
|
||||
Attr & aDrvPath(*topLevel.attrs->find(state.sDrvPath));
|
||||
auto topLevelDrv = state.store->parseStorePath(state.coerceToPath(*aDrvPath.pos, *aDrvPath.value, context));
|
||||
auto topLevelDrv = state.coerceToStorePath(*aDrvPath.pos, *aDrvPath.value, context);
|
||||
Attr & aOutPath(*topLevel.attrs->find(state.sOutPath));
|
||||
Path topLevelOut = state.coerceToPath(*aOutPath.pos, *aOutPath.value, context);
|
||||
auto topLevelOut = state.coerceToStorePath(*aOutPath.pos, *aOutPath.value, context);
|
||||
|
||||
/* Realise the resulting store expression. */
|
||||
debug("building user environment");
|
||||
|
@ -158,8 +158,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
}
|
||||
|
||||
debug(format("switching to new user environment"));
|
||||
Path generation = createGeneration(ref<LocalFSStore>(store2), profile,
|
||||
store2->parseStorePath(topLevelOut));
|
||||
Path generation = createGeneration(ref<LocalFSStore>(store2), profile, topLevelOut);
|
||||
switchLink(profile, generation);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue