mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 02:36:16 +02:00
MacOS built: add workaround for missing view() member of std::ostringstream
This commit is contained in:
parent
caf3b55891
commit
e21c7895eb
11 changed files with 39 additions and 19 deletions
|
@ -645,7 +645,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||||
|
|
||||||
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
||||||
} else if (fallbackPos) {
|
} else if (fallbackPos) {
|
||||||
std::stringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Attribute `" << fallbackName << "`\n\n";
|
ss << "Attribute `" << fallbackName << "`\n\n";
|
||||||
ss << " … defined at " << state->positions[fallbackPos] << "\n\n";
|
ss << " … defined at " << state->positions[fallbackPos] << "\n\n";
|
||||||
if (fallbackDoc) {
|
if (fallbackDoc) {
|
||||||
|
@ -654,7 +654,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||||
ss << "No documentation found.\n\n";
|
ss << "No documentation found.\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto markdown = ss.view();
|
auto markdown = toView(ss);
|
||||||
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -539,7 +539,7 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
||||||
if (v.isLambda()) {
|
if (v.isLambda()) {
|
||||||
auto exprLambda = v.payload.lambda.fun;
|
auto exprLambda = v.payload.lambda.fun;
|
||||||
|
|
||||||
std::stringstream s(std::ios_base::out);
|
std::ostringstream s(std::ios_base::out);
|
||||||
std::string name;
|
std::string name;
|
||||||
auto pos = positions[exprLambda->getPos()];
|
auto pos = positions[exprLambda->getPos()];
|
||||||
std::string docStr;
|
std::string docStr;
|
||||||
|
@ -578,7 +578,7 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
||||||
.name = name,
|
.name = name,
|
||||||
.arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though...
|
.arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though...
|
||||||
.args = {},
|
.args = {},
|
||||||
.doc = makeImmutableString(s.view()), // NOTE: memory leak when compiled without GC
|
.doc = makeImmutableString(toView(s)), // NOTE: memory leak when compiled without GC
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (isFunctor(v)) {
|
if (isFunctor(v)) {
|
||||||
|
@ -1804,7 +1804,7 @@ void ExprAssert::eval(EvalState & state, Env & env, Value & v)
|
||||||
if (!state.evalBool(env, cond, pos, "in the condition of the assert statement")) {
|
if (!state.evalBool(env, cond, pos, "in the condition of the assert statement")) {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
cond->show(state.symbols, out);
|
cond->show(state.symbols, out);
|
||||||
auto exprStr = out.view();
|
auto exprStr = toView(out);
|
||||||
|
|
||||||
if (auto eq = dynamic_cast<ExprOpEq *>(cond)) {
|
if (auto eq = dynamic_cast<ExprOpEq *>(cond)) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2136,7 +2136,7 @@ static void prim_toXML(EvalState & state, const PosIdx pos, Value * * args, Valu
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
printValueAsXML(state, true, false, *args[0], out, context, pos);
|
printValueAsXML(state, true, false, *args[0], out, context, pos);
|
||||||
v.mkString(out.view(), context);
|
v.mkString(toView(out), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_toXML({
|
static RegisterPrimOp primop_toXML({
|
||||||
|
@ -2244,7 +2244,7 @@ static void prim_toJSON(EvalState & state, const PosIdx pos, Value * * args, Val
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
printValueAsJSON(state, true, *args[0], pos, out, context);
|
printValueAsJSON(state, true, *args[0], pos, out, context);
|
||||||
v.mkString(out.view(), context);
|
v.mkString(toView(out), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_toJSON({
|
static RegisterPrimOp primop_toJSON({
|
||||||
|
|
|
@ -66,7 +66,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
attrs.alloc("_type").mkString("timestamp");
|
attrs.alloc("_type").mkString("timestamp");
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << t;
|
s << t;
|
||||||
attrs.alloc("value").mkString(s.view());
|
attrs.alloc("value").mkString(toView(s));
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("Dates and times are not supported");
|
throw std::runtime_error("Dates and times are not supported");
|
||||||
|
|
|
@ -460,7 +460,7 @@ private:
|
||||||
|
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << state.positions[v.payload.lambda.fun->pos];
|
s << state.positions[v.payload.lambda.fun->pos];
|
||||||
output << " @ " << filterANSIEscapes(s.view());
|
output << " @ " << filterANSIEscapes(toView(s));
|
||||||
}
|
}
|
||||||
} else if (v.isPrimOp()) {
|
} else if (v.isPrimOp()) {
|
||||||
if (v.primOp())
|
if (v.primOp())
|
||||||
|
|
|
@ -94,7 +94,7 @@ struct TunnelLogger : public Logger
|
||||||
showErrorInfo(oss, ei, false);
|
showErrorInfo(oss, ei, false);
|
||||||
|
|
||||||
StringSink buf;
|
StringSink buf;
|
||||||
buf << STDERR_NEXT << oss.view();
|
buf << STDERR_NEXT << toView(oss);
|
||||||
enqueueMsg(buf.s);
|
enqueueMsg(buf.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,21 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
struct view_stringbuf : public std::stringbuf
|
||||||
|
{
|
||||||
|
inline std::string_view toView()
|
||||||
|
{
|
||||||
|
auto begin = pbase();
|
||||||
|
return {begin, begin + pubseekoff(0, std::ios_base::cur, std::ios_base::out)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string_view toView(const std::ostringstream & os)
|
||||||
|
{
|
||||||
|
auto buf = static_cast<view_stringbuf *>(os.rdbuf());
|
||||||
|
return buf->toView();
|
||||||
|
}
|
||||||
|
|
||||||
template std::list<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
template std::list<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
||||||
template std::set<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
template std::set<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
||||||
template std::vector<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
template std::vector<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
||||||
|
|
|
@ -8,6 +8,11 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* workaround for unavailable view() method (C++20) of std::ostringstream under MacOS with clang-16
|
||||||
|
*/
|
||||||
|
std::string_view toView(const std::ostringstream & os);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String tokenizer.
|
* String tokenizer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -260,9 +260,9 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
// read the shebang to understand which packages to read from. Since
|
// read the shebang to understand which packages to read from. Since
|
||||||
// this is handled via nix-shell -p, we wrap our ruby script execution
|
// this is handled via nix-shell -p, we wrap our ruby script execution
|
||||||
// in ruby -e 'load' which ignores the shebangs.
|
// in ruby -e 'load' which ignores the shebangs.
|
||||||
envCommand = fmt("exec %1% %2% -e 'load(ARGV.shift)' -- %3% %4%", execArgs, interpreter, shellEscape(script), joined.view());
|
envCommand = fmt("exec %1% %2% -e 'load(ARGV.shift)' -- %3% %4%", execArgs, interpreter, shellEscape(script), toView(joined));
|
||||||
} else {
|
} else {
|
||||||
envCommand = fmt("exec %1% %2% %3% %4%", execArgs, interpreter, shellEscape(script), joined.view());
|
envCommand = fmt("exec %1% %2% %3% %4%", execArgs, interpreter, shellEscape(script), toView(joined));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ bool createUserEnv(EvalState & state, PackageInfos & elems,
|
||||||
auto manifestFile = ({
|
auto manifestFile = ({
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
printAmbiguous(manifest, state.symbols, str, nullptr, std::numeric_limits<int>::max());
|
printAmbiguous(manifest, state.symbols, str, nullptr, std::numeric_limits<int>::max());
|
||||||
StringSource source { str.view() };
|
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);
|
||||||
});
|
});
|
||||||
|
|
|
@ -87,11 +87,11 @@ struct CmdConfigCheck : StoreCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirs.size() != 1) {
|
if (dirs.size() != 1) {
|
||||||
std::stringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Multiple versions of nix found in PATH:\n";
|
ss << "Multiple versions of nix found in PATH:\n";
|
||||||
for (auto & dir : dirs)
|
for (auto & dir : dirs)
|
||||||
ss << " " << dir << "\n";
|
ss << " " << dir << "\n";
|
||||||
return checkFail(ss.view());
|
return checkFail(toView(ss));
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkPass("PATH contains only one nix version.");
|
return checkPass("PATH contains only one nix version.");
|
||||||
|
@ -125,14 +125,14 @@ struct CmdConfigCheck : StoreCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dirs.empty()) {
|
if (!dirs.empty()) {
|
||||||
std::stringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Found profiles outside of " << settings.nixStateDir << "/profiles.\n"
|
ss << "Found profiles outside of " << settings.nixStateDir << "/profiles.\n"
|
||||||
<< "The generation this profile points to might not have a gcroot and could be\n"
|
<< "The generation this profile points to might not have a gcroot and could be\n"
|
||||||
<< "garbage collected, resulting in broken symlinks.\n\n";
|
<< "garbage collected, resulting in broken symlinks.\n\n";
|
||||||
for (auto & dir : dirs)
|
for (auto & dir : dirs)
|
||||||
ss << " " << dir << "\n";
|
ss << " " << dir << "\n";
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
return checkFail(ss.view());
|
return checkFail(toView(ss));
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkPass("All profiles are gcroots.");
|
return checkPass("All profiles are gcroots.");
|
||||||
|
@ -145,13 +145,13 @@ struct CmdConfigCheck : StoreCommand
|
||||||
: PROTOCOL_VERSION;
|
: PROTOCOL_VERSION;
|
||||||
|
|
||||||
if (clientProto != storeProto) {
|
if (clientProto != storeProto) {
|
||||||
std::stringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Warning: protocol version of this client does not match the store.\n"
|
ss << "Warning: protocol version of this client does not match the store.\n"
|
||||||
<< "While this is not necessarily a problem it's recommended to keep the client in\n"
|
<< "While this is not necessarily a problem it's recommended to keep the client in\n"
|
||||||
<< "sync with the daemon.\n\n"
|
<< "sync with the daemon.\n\n"
|
||||||
<< "Client protocol: " << formatProtocol(clientProto) << "\n"
|
<< "Client protocol: " << formatProtocol(clientProto) << "\n"
|
||||||
<< "Store protocol: " << formatProtocol(storeProto) << "\n\n";
|
<< "Store protocol: " << formatProtocol(storeProto) << "\n\n";
|
||||||
return checkFail(ss.view());
|
return checkFail(toView(ss));
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkPass("Client protocol matches store protocol.");
|
return checkPass("Client protocol matches store protocol.");
|
||||||
|
|
Loading…
Reference in a new issue