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