diff options
author | Max Siling <root@goldstein.rs> | 2024-08-07 21:48:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@localhost> | 2024-08-07 21:48:01 +0000 |
commit | 6fdb47f0b259a9ffbe4bdb349d6aaf03a0144092 (patch) | |
tree | d6d0d5011d5dae3061f086293c47cbb450c89689 | |
parent | 0800a81a9506463fd46fd8a22b9996488fc268a3 (diff) | |
parent | 9adfd9b8ad48f631c935d5a146bbf98a3cf603cb (diff) |
Merge "src/libcmd/repl.cc: allow :log /path/to/store.drv" into main
-rw-r--r-- | doc/manual/rl-next/repl-log-drv.md | 9 | ||||
-rw-r--r-- | src/libcmd/repl.cc | 74 | ||||
-rw-r--r-- | tests/functional/repl.sh | 5 |
3 files changed, 58 insertions, 30 deletions
diff --git a/doc/manual/rl-next/repl-log-drv.md b/doc/manual/rl-next/repl-log-drv.md new file mode 100644 index 000000000..37d6f5cb2 --- /dev/null +++ b/doc/manual/rl-next/repl-log-drv.md @@ -0,0 +1,9 @@ +--- +synopsis: "`:log` in repl now works on derivation paths" +issues: [fj#51] +cls: [1716] +category: Improvements +credits: [goldstein] +--- + +`:log` can now accept store derivation paths in addition to derivation expressions. diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc index 5086e9999..b8bfc25eb 100644 --- a/src/libcmd/repl.cc +++ b/src/libcmd/repl.cc @@ -536,7 +536,7 @@ ProcessLineResult NixRepl::processLine(std::string line) << " :t <expr> Describe result of evaluation\n" << " :u <expr> Build derivation, then start nix-shell\n" << " :doc <expr> Show documentation for the provided function (experimental lambda support)\n" - << " :log <expr> Show logs for a derivation\n" + << " :log <expr | .drv path> Show logs for a derivation\n" << " :te, :trace-enable [bool] Enable, disable or toggle showing traces for\n" << " errors\n" << " :?, :help Brings up this help menu\n" @@ -676,7 +676,49 @@ ProcessLineResult NixRepl::processLine(std::string line) runNix("nix-shell", {state->store->printStorePath(drvPath)}); } - else if (command == ":b" || command == ":bl" || command == ":i" || command == ":sh" || command == ":log") { + else if (command == ":log") { + StorePath drvPath = ([&] { + auto maybeDrvPath = state->store->maybeParseStorePath(arg); + if (maybeDrvPath && maybeDrvPath->isDerivation()) { + return std::move(*maybeDrvPath); + } else { + Value v; + evalString(arg, v); + return getDerivationPath(v); + } + })(); + Path drvPathRaw = state->store->printStorePath(drvPath); + + settings.readOnlyMode = true; + Finally roModeReset([&]() { + settings.readOnlyMode = false; + }); + auto subs = getDefaultSubstituters(); + + subs.push_front(state->store); + + bool foundLog = false; + RunPager pager; + for (auto & sub : subs) { + auto * logSubP = dynamic_cast<LogStore *>(&*sub); + if (!logSubP) { + printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri()); + continue; + } + auto & logSub = *logSubP; + + auto log = logSub.getBuildLog(drvPath); + if (log) { + printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.getUri()); + logger->writeToStdout(*log); + foundLog = true; + break; + } + } + if (!foundLog) throw Error("build log of '%s' is not available", drvPathRaw); + } + + else if (command == ":b" || command == ":bl" || command == ":i" || command == ":sh") { Value v; evalString(arg, v); StorePath drvPath = getDerivationPath(v); @@ -712,34 +754,6 @@ ProcessLineResult NixRepl::processLine(std::string line) } } else if (command == ":i") { runNix("nix-env", {"-i", drvPathRaw}); - } else if (command == ":log") { - settings.readOnlyMode = true; - Finally roModeReset([&]() { - settings.readOnlyMode = false; - }); - auto subs = getDefaultSubstituters(); - - subs.push_front(state->store); - - bool foundLog = false; - RunPager pager; - for (auto & sub : subs) { - auto * logSubP = dynamic_cast<LogStore *>(&*sub); - if (!logSubP) { - printInfo("Skipped '%s' which does not support retrieving build logs", sub->getUri()); - continue; - } - auto & logSub = *logSubP; - - auto log = logSub.getBuildLog(drvPath); - if (log) { - printInfo("got build log for '%s' from '%s'", drvPathRaw, logSub.getUri()); - logger->writeToStdout(*log); - foundLog = true; - break; - } - } - if (!foundLog) throw Error("build log of '%s' is not available", drvPathRaw); } else { runNix("nix-shell", {drvPathRaw}); } diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh index 22c69e20b..1f2c2e93f 100644 --- a/tests/functional/repl.sh +++ b/tests/functional/repl.sh @@ -271,3 +271,8 @@ a = ''test string that we'll grep later'' :e identity a " "undefined variable" + +# Test :log with derivation paths. +simple_path="$(nix-instantiate "$testDir/simple.nix")" +# `PATH=` is a part of build log. +testReplResponseNoRegex ":log ${simple_path}" "PATH=" |