Skip to content
Merged
30 changes: 22 additions & 8 deletions src/libcmd/markdown.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#include "markdown.hh"
#include "util.hh"
#include "environment-variables.hh"
#include "error.hh"
#include "finally.hh"
#include "terminal.hh"

#if HAVE_LOWDOWN
# include <sys/queue.h>
# include <lowdown.h>
# include <sys/queue.h>
# include <lowdown.h>
#endif

namespace nix {

std::string renderMarkdownToTerminal(std::string_view markdown)
{
#if HAVE_LOWDOWN
static std::string doRenderMarkdownToTerminal(std::string_view markdown)
{
int windowWidth = getWindowSize().second;

struct lowdown_opts opts {
struct lowdown_opts opts
{
.type = LOWDOWN_TERM,
.maxdepth = 20,
.cols = (size_t) std::max(windowWidth - 5, 60),
Expand Down Expand Up @@ -51,9 +53,21 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
throw Error("allocation error while rendering Markdown");

return filterANSIEscapes(std::string(buf->data, buf->size), !isTTY());
}

std::string renderMarkdownToTerminal(std::string_view markdown)
{
if (auto e = getEnv("_NIX_TEST_RAW_MARKDOWN"); e && *e == "1")
return std::string(markdown);
else
return doRenderMarkdownToTerminal(markdown);
}

#else
std::string renderMarkdownToTerminal(std::string_view markdown)
{
return std::string(markdown);
#endif
}
#endif

}
} // namespace nix
9 changes: 8 additions & 1 deletion src/libcmd/markdown.hh
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#pragma once
///@file

#include "types.hh"
#include <string_view>

namespace nix {

/**
* Render the given Markdown text to the terminal.
*
* If Nix is compiled without Markdown support, this function will return the input text as-is.
*
* The renderer takes into account the terminal width, and wraps text accordingly.
*/
std::string renderMarkdownToTerminal(std::string_view markdown);

}
14 changes: 14 additions & 0 deletions src/libcmd/repl-interacter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" {
#include "repl-interacter.hh"
#include "file-system.hh"
#include "repl.hh"
#include "environment-variables.hh"

namespace nix {

Expand Down Expand Up @@ -175,10 +176,23 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT
return true;
}

// editline doesn't echo the input to the output when non-interactive, unlike readline
// this results in a different behavior when running tests. The echoing is
// quite useful for reading the test output, so we add it here.
if (auto e = getEnv("_NIX_TEST_REPL_ECHO"); s && e && *e == "1")
{
#ifndef USE_READLINE
// This is probably not right for multi-line input, but we don't use that
// in the characterisation tests, so it's fine.
std::cout << promptForType(promptType) << s << std::endl;
#endif
}

if (!s)
return false;
input += s;
input += '\n';

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ReplExitStatus NixRepl::mainLoop()
case ProcessLineResult::PromptAgain:
break;
default:
abort();
unreachable();
}
} catch (ParseError & e) {
if (e.msg().find("unexpected end of file") != std::string::npos) {
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/attr-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ std::pair<SourcePath, uint32_t> findPackageFilename(EvalState & state, Value & v
return {SourcePath{path.accessor, CanonPath(fn.substr(0, colon))}, lineno};
} catch (std::invalid_argument & e) {
fail();
abort();
unreachable();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libexpr/eval-gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ void fixupBoehmStackPointer(void ** sp_ptr, void * _pthread_id)
{
void *& sp = *sp_ptr;
auto pthread_id = reinterpret_cast<pthread_t>(_pthread_id);
# ifndef __APPLE__
pthread_attr_t pattr;
# endif
size_t osStackSize;
void * osStackLow;
void * osStackBase;
Expand Down
8 changes: 4 additions & 4 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ std::string_view showType(ValueType type, bool withArticle)
case nFloat: return WA("a", "float");
case nThunk: return WA("a", "thunk");
}
abort();
unreachable();
}


Expand Down Expand Up @@ -771,7 +771,7 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr &
case ReplExitStatus::Continue:
break;
default:
abort();
unreachable();
}
}
}
Expand Down Expand Up @@ -1140,7 +1140,7 @@ inline void EvalState::evalAttrs(Env & env, Expr * e, Value & v, const PosIdx po

void Expr::eval(EvalState & state, Env & env, Value & v)
{
abort();
unreachable();
}


Expand Down Expand Up @@ -1573,7 +1573,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
.withFrame(*fun.payload.lambda.env, lambda)
.debugThrow();
}
abort(); // can't happen
unreachable();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/nixexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::ostream & operator <<(std::ostream & str, const SymbolStr & symbol)

void Expr::show(const SymbolTable & symbols, std::ostream & str) const
{
abort();
unreachable();
}

void ExprInt::show(const SymbolTable & symbols, std::ostream & str) const
Expand Down Expand Up @@ -271,7 +271,7 @@ std::string showAttrPath(const SymbolTable & symbols, const AttrPath & attrPath)

void Expr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
{
abort();
unreachable();
}

void ExprInt::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static void prim_typeOf(EvalState & state, const PosIdx pos, Value * * args, Val
t = args[0]->external()->typeOf();
break;
case nFloat: t = "float"; break;
case nThunk: abort();
case nThunk: unreachable();
}
v.mkString(t);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/print-ambiguous.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void printAmbiguous(
break;
default:
printError("Nix evaluator internal error: printAmbiguous: invalid value type");
abort();
unreachable();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class Printer
else
output << "primop";
} else {
abort();
unreachable();
}

output << "»";
Expand Down Expand Up @@ -504,7 +504,7 @@ class Printer
if (options.ansiColors)
output << ANSI_NORMAL;
} else {
abort();
unreachable();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/symbol-table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "types.hh"
#include "chunked-vector.hh"
#include "error.hh"

namespace nix {

Expand Down Expand Up @@ -113,7 +114,7 @@ public:
SymbolStr operator[](Symbol s) const
{
if (s.id == 0 || s.id > store.size())
abort();
unreachable();
return SymbolStr(store[s.id - 1]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public:
if (invalidIsThunk)
return nThunk;
else
abort();
unreachable();
}

inline void finishValue(InternalType newType, Payload newPayload)
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/attrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ nlohmann::json attrsToJSON(const Attrs & attrs)
json[attr.first] = *v;
} else if (auto v = std::get_if<Explicit<bool>>(&attr.second)) {
json[attr.first] = v->t;
} else abort();
} else unreachable();
}
return json;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ std::map<std::string, std::string> attrsToQuery(const Attrs & attrs)
query.insert_or_assign(attr.first, *v);
} else if (auto v = std::get_if<Explicit<bool>>(&attr.second)) {
query.insert_or_assign(attr.first, v->t ? "1" : "0");
} else abort();
} else unreachable();
}
return query;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libmain/loggers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Logger * makeDefaultLogger() {
return logger;
}
default:
abort();
unreachable();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/drv-output-substitution-goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public:
Co init() override;
Co realisationFetched(std::shared_ptr<const Realisation> outputInfo, nix::ref<nix::Store> sub);

void timedOut(Error && ex) override { abort(); };
void timedOut(Error && ex) override { unreachable(); };

std::string key() override;

Expand Down
4 changes: 2 additions & 2 deletions src/libstore/build/goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ public:

virtual void handleChildOutput(Descriptor fd, std::string_view data)
{
abort();
unreachable();
}

virtual void handleEOF(Descriptor fd)
{
abort();
unreachable();
}

void trace(std::string_view s);
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/substitution-goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public:
PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
~PathSubstitutionGoal();

void timedOut(Error && ex) override { abort(); };
void timedOut(Error && ex) override { unreachable(); };

/**
* We prepend "a$" to the key name to ensure substitution goals
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/build/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void Worker::childStarted(GoalPtr goal, const std::set<MuxablePipePollState::Com
nrLocalBuilds++;
break;
default:
abort();
unreachable();
}
}
}
Expand All @@ -239,7 +239,7 @@ void Worker::childTerminated(Goal * goal, bool wakeSleepers)
nrLocalBuilds--;
break;
default:
abort();
unreachable();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Sink & operator << (Sink & sink, const Logger::Fields & fields)
sink << f.i;
else if (f.type == Logger::Field::tString)
sink << f.s;
else abort();
else unreachable();
}
return sink;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
non-blocking flag from the server socket, so
explicitly make it blocking. */
if (fcntl(fdClient.get(), F_SETFL, fcntl(fdClient.get(), F_GETFL) & ~O_NONBLOCK) == -1)
abort();
panic("Could not set non-blocking flag on client socket");

while (true) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ template<> std::string BaseSetting<SandboxMode>::to_string() const
if (value == smEnabled) return "true";
else if (value == smRelaxed) return "relaxed";
else if (value == smDisabled) return "false";
else abort();
else unreachable();
}

template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::string & category)
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/nar-info-disk-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
Cache & getCache(State & state, const std::string & uri)
{
auto i = state.caches.find(uri);
if (i == state.caches.end()) abort();
if (i == state.caches.end()) unreachable();
return i->second;
}

Expand Down Expand Up @@ -211,7 +211,7 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache

{
auto r(state->insertCache.use()(uri)(time(0))(storeDir)(wantMassQuery)(priority));
if (!r.next()) { abort(); }
if (!r.next()) { unreachable(); }
ret.id = (int) r.getInt(0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/unix/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void LocalDerivationGoal::killSandbox(bool getStats)
buildResult.cpuSystem = stats.cpuSystem;
}
#else
abort();
unreachable();
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/unix/pathlocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool lockFile(Descriptor desc, LockType lockType, bool wait)
if (lockType == ltRead) type = LOCK_SH;
else if (lockType == ltWrite) type = LOCK_EX;
else if (lockType == ltNone) type = LOCK_UN;
else abort();
else unreachable();

if (wait) {
while (flock(desc, type) != 0) {
Expand Down
Loading