From f32c687f03e9764e55831d894b719fdf0104cf25 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 28 Apr 2021 15:50:11 -0600 Subject: [PATCH] move repl.cc to libcmd for linkage --- src/libcmd/command.cc | 37 +++++++++++++++++++++++++++++++++++++ src/libcmd/local.mk | 6 +++--- src/{nix => libcmd}/repl.cc | 0 3 files changed, 40 insertions(+), 3 deletions(-) rename src/{nix => libcmd}/repl.cc (100%) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index 644c9c3b0..d790bb51d 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -54,6 +54,7 @@ void StoreCommand::run() run(getStore()); } +/* EvalCommand::EvalCommand() { addFlag({ @@ -77,6 +78,42 @@ ref EvalCommand::getEvalState() } return ref(evalState); } +*/ +EvalCommand::EvalCommand() +{ + addFlag({ + .longName = "debugger", + .description = "start an interactive environment if evaluation fails", + .handler = {&startReplOnEvalErrors, true}, + }); +} +// ref EvalCommand::getEvalState() +// { +// if (!evalState) +// evalState = std::make_shared(searchPath, getStore()); +// return ref(evalState); +// } +extern std::function & env)> debuggerHook; + +ref EvalCommand::getEvalState() +{ + if (!evalState) { + evalState = std::make_shared(searchPath, getStore()); + if (startReplOnEvalErrors) + debuggerHook = [evalState{ref(evalState)}](const Error & error, const std::map & env) { + printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what()); + runRepl(evalState, env); + }; + } + return ref(evalState); +} + +EvalCommand::~EvalCommand() +{ + if (evalState) + evalState->printStats(); +} + RealisedPathsCommand::RealisedPathsCommand(bool recursive) : recursive(recursive) diff --git a/src/libcmd/local.mk b/src/libcmd/local.mk index ab0e0e43d..c282499b1 100644 --- a/src/libcmd/local.mk +++ b/src/libcmd/local.mk @@ -6,10 +6,10 @@ libcmd_DIR := $(d) libcmd_SOURCES := $(wildcard $(d)/*.cc) -libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers +libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers -I src/nix -libcmd_LDFLAGS = -llowdown +libcmd_LDFLAGS = $(EDITLINE_LIBS) -llowdown -libcmd_LIBS = libstore libutil libexpr libmain libfetchers +libcmd_LIBS = libstore libutil libexpr libmain libfetchers libnix libwut $(eval $(call install-file-in, $(d)/nix-cmd.pc, $(prefix)/lib/pkgconfig, 0644)) diff --git a/src/nix/repl.cc b/src/libcmd/repl.cc similarity index 100% rename from src/nix/repl.cc rename to src/libcmd/repl.cc