diff options
author | Ben Burdette <bburdette@gmail.com> | 2021-04-28 15:50:11 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2021-04-28 15:50:11 -0600 |
commit | f32c687f03e9764e55831d894b719fdf0104cf25 (patch) | |
tree | 245eb04a4d06180d33620211d2d8f352446315f4 | |
parent | 57c2dd5d8581f37392df369493b00794b619304e (diff) |
move repl.cc to libcmd for linkage
-rw-r--r-- | src/libcmd/command.cc | 37 | ||||
-rw-r--r-- | src/libcmd/local.mk | 6 | ||||
-rw-r--r-- | src/libcmd/repl.cc (renamed from src/nix/repl.cc) | 0 |
3 files changed, 40 insertions, 3 deletions
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<EvalState> EvalCommand::getEvalState() } return ref<EvalState>(evalState); } +*/ +EvalCommand::EvalCommand() +{ + addFlag({ + .longName = "debugger", + .description = "start an interactive environment if evaluation fails", + .handler = {&startReplOnEvalErrors, true}, + }); +} +// ref<EvalState> EvalCommand::getEvalState() +// { +// if (!evalState) +// evalState = std::make_shared<EvalState>(searchPath, getStore()); +// return ref<EvalState>(evalState); +// } +extern std::function<void(const Error & error, const std::map<std::string, Value *> & env)> debuggerHook; + +ref<EvalState> EvalCommand::getEvalState() +{ + if (!evalState) { + evalState = std::make_shared<EvalState>(searchPath, getStore()); + if (startReplOnEvalErrors) + debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const std::map<std::string, Value *> & 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>(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 index b1f250e73..b1f250e73 100644 --- a/src/nix/repl.cc +++ b/src/libcmd/repl.cc |