mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
Fix printAmbiguous() / printValueAsJSON()
This commit is contained in:
parent
fa5cb62604
commit
f058567e9a
5 changed files with 27 additions and 18 deletions
|
@ -15,10 +15,10 @@ namespace nix {
|
|||
* See: https://github.com/NixOS/nix/issues/9730
|
||||
*/
|
||||
void printAmbiguous(
|
||||
Value &v,
|
||||
const SymbolTable &symbols,
|
||||
std::ostream &str,
|
||||
std::set<const void *> *seen,
|
||||
EvalState & state,
|
||||
Value & v,
|
||||
std::ostream & str,
|
||||
std::set<const void *> * seen,
|
||||
int depth);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ namespace nix {
|
|||
|
||||
// See: https://github.com/NixOS/nix/issues/9730
|
||||
void printAmbiguous(
|
||||
Value &v,
|
||||
const SymbolTable &symbols,
|
||||
std::ostream &str,
|
||||
std::set<const void *> *seen,
|
||||
EvalState & state,
|
||||
Value & v,
|
||||
std::ostream & str,
|
||||
std::set<const void *> * seen,
|
||||
int depth)
|
||||
{
|
||||
checkInterrupt();
|
||||
|
@ -26,9 +26,13 @@ void printAmbiguous(
|
|||
case nBool:
|
||||
printLiteralBool(str, v.boolean());
|
||||
break;
|
||||
case nString:
|
||||
printLiteralString(str, v.string_view());
|
||||
case nString: {
|
||||
NixStringContext context;
|
||||
copyContext(v, context);
|
||||
// FIXME: make devirtualization configurable?
|
||||
printLiteralString(str, state.devirtualize(v.string_view(), context));
|
||||
break;
|
||||
}
|
||||
case nPath:
|
||||
str << v.path().to_string(); // !!! escaping?
|
||||
break;
|
||||
|
@ -40,9 +44,9 @@ void printAmbiguous(
|
|||
str << "«repeated»";
|
||||
else {
|
||||
str << "{ ";
|
||||
for (auto & i : v.attrs()->lexicographicOrder(symbols)) {
|
||||
str << symbols[i->name] << " = ";
|
||||
printAmbiguous(*i->value, symbols, str, seen, depth - 1);
|
||||
for (auto & i : v.attrs()->lexicographicOrder(state.symbols)) {
|
||||
str << state.symbols[i->name] << " = ";
|
||||
printAmbiguous(state, *i->value, str, seen, depth - 1);
|
||||
str << "; ";
|
||||
}
|
||||
str << "}";
|
||||
|
@ -56,7 +60,7 @@ void printAmbiguous(
|
|||
str << "[ ";
|
||||
for (auto v2 : v.listItems()) {
|
||||
if (v2)
|
||||
printAmbiguous(*v2, symbols, str, seen, depth - 1);
|
||||
printAmbiguous(state, *v2, str, seen, depth - 1);
|
||||
else
|
||||
str << "(nullptr)";
|
||||
str << " ";
|
||||
|
|
|
@ -31,7 +31,9 @@ json printValueAsJSON(EvalState & state, bool strict,
|
|||
|
||||
case nString:
|
||||
copyContext(v, context);
|
||||
out = v.c_str();
|
||||
// FIXME: only use the context from `v`.
|
||||
// FIXME: make devirtualization configurable?
|
||||
out = state.devirtualize(v.c_str(), context);
|
||||
break;
|
||||
|
||||
case nPath:
|
||||
|
|
|
@ -110,7 +110,7 @@ bool createUserEnv(EvalState & state, PackageInfos & elems,
|
|||
environment. */
|
||||
auto manifestFile = ({
|
||||
std::ostringstream str;
|
||||
printAmbiguous(manifest, state.symbols, str, nullptr, std::numeric_limits<int>::max());
|
||||
printAmbiguous(state, manifest, str, nullptr, std::numeric_limits<int>::max());
|
||||
StringSource source { toView(str) };
|
||||
state.store->addToStoreFromDump(
|
||||
source, "env-manifest.nix", FileSerialisationMethod::Flat, ContentAddressMethod::Raw::Text, HashAlgorithm::SHA256, references);
|
||||
|
|
|
@ -52,7 +52,10 @@ void processExpr(EvalState & state, const Strings & attrPaths,
|
|||
else
|
||||
state.autoCallFunction(autoArgs, v, vRes);
|
||||
if (output == okRaw)
|
||||
std::cout << *state.coerceToString(noPos, vRes, context, "while generating the nix-instantiate output");
|
||||
std::cout <<
|
||||
state.devirtualize(
|
||||
*state.coerceToString(noPos, vRes, context, "while generating the nix-instantiate output"),
|
||||
context);
|
||||
// We intentionally don't output a newline here. The default PS1 for Bash in NixOS starts with a newline
|
||||
// and other interactive shells like Zsh are smart enough to print a missing newline before the prompt.
|
||||
else if (output == okXML)
|
||||
|
@ -63,7 +66,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
|
|||
} else {
|
||||
if (strict) state.forceValueDeep(vRes);
|
||||
std::set<const void *> seen;
|
||||
printAmbiguous(vRes, state.symbols, std::cout, &seen, std::numeric_limits<int>::max());
|
||||
printAmbiguous(state, vRes, std::cout, &seen, std::numeric_limits<int>::max());
|
||||
std::cout << std::endl;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue