Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e31f3f91476c
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 490861eae077
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Nov 18, 2020

  1. Fix resetting the terminal with '-L'

    Using '-L' caused another call to setLogFormat(), which caused another
    ProgressBar to be created. But the ProgressBar should be a singleton.
    
    To do: remove LogFormat::barWithLogs. '-L' should be a setting of the
    ProgressBar, not a different log format.
    edolstra committed Nov 18, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    primeos Michael Weiss
    Copy the full SHA
    a663a2f View commit details
  2. Replace LogFormat::barWithLogs with a setting

    This will make it easier to add more settings to the progress bar.
    edolstra committed Nov 18, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    primeos Michael Weiss
    Copy the full SHA
    490861e View commit details
Showing with 35 additions and 37 deletions.
  1. +0 −4 src/libmain/loggers.cc
  2. +0 −1 src/libmain/loggers.hh
  3. +18 −22 src/libmain/progress-bar.cc
  4. +9 −3 src/libmain/progress-bar.hh
  5. +2 −1 src/nix-prefetch-url/nix-prefetch-url.cc
  6. +6 −6 src/nix/main.cc
4 changes: 0 additions & 4 deletions src/libmain/loggers.cc
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@ LogFormat parseLogFormat(const std::string & logFormatStr) {
return LogFormat::internalJSON;
else if (logFormatStr == "bar")
return LogFormat::bar;
else if (logFormatStr == "bar-with-logs")
return LogFormat::barWithLogs;
throw Error("option 'log-format' has an invalid value '%s'", logFormatStr);
}

@@ -30,8 +28,6 @@ Logger * makeDefaultLogger() {
return makeJSONLogger(*makeSimpleLogger(true));
case LogFormat::bar:
return makeProgressBar();
case LogFormat::barWithLogs:
return makeProgressBar(true);
default:
abort();
}
1 change: 0 additions & 1 deletion src/libmain/loggers.hh
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ enum class LogFormat {
rawWithLogs,
internalJSON,
bar,
barWithLogs,
};

void setLogFormat(const std::string & logFormatStr);
40 changes: 18 additions & 22 deletions src/libmain/progress-bar.cc
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@

namespace nix {

ProgressBarSettings progressBarSettings;

static GlobalConfig::Register rProgressBarSettings(&progressBarSettings);

static std::string getS(const std::vector<Logger::Field> & fields, size_t n)
{
assert(n < fields.size());
@@ -133,8 +137,6 @@ class ProgressBar : public Logger
bool active = true;
bool haveUpdate = true;

bool printBuildLogs;

std::map<LineId, std::string> statusLines;

/* How many lines need to be erased when redrawing. */
@@ -143,7 +145,7 @@ class ProgressBar : public Logger
bool helpShown = false;
};

bool isTTY;
const bool isTTY;

Sync<State> state_;

@@ -158,9 +160,9 @@ class ProgressBar : public Logger

public:

ProgressBar(bool printBuildLogs, bool isTTY)
ProgressBar(bool isTTY)
: isTTY(isTTY)
, state_({ .active = isTTY, .printBuildLogs = printBuildLogs })
, state_({ .active = isTTY })
{
state_.lock()->active = isTTY;

@@ -173,14 +175,9 @@ class ProgressBar : public Logger
draw(*state);
state.wait_for(quitCV, std::chrono::milliseconds(50));
}

if (savedTermAttrs) {
tcsetattr(STDIN_FILENO, TCSANOW, &*savedTermAttrs);
savedTermAttrs.reset();
}
});

if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) && isatty(STDERR_FILENO)) {
if (isTTY) {

struct termios term;
if (tcgetattr(STDIN_FILENO, &term))
@@ -229,10 +226,10 @@ class ProgressBar : public Logger
}
if (c == 'l') {
auto state(state_.lock());
state->printBuildLogs = !state->printBuildLogs;
progressBarSettings.printBuildLogs = !progressBarSettings.printBuildLogs;
updateStatusLine(*state);
draw(*state,
state->printBuildLogs
progressBarSettings.printBuildLogs
? ANSI_BOLD "Enabling build logs."
: ANSI_BOLD "Disabling build logs.");
}
@@ -291,14 +288,19 @@ class ProgressBar : public Logger
state->active = false;
updateCV.notify_one();
quitCV.notify_one();

if (savedTermAttrs) {
tcsetattr(STDIN_FILENO, TCSANOW, &*savedTermAttrs);
savedTermAttrs.reset();
}
}

updateThread.join();
}

bool isVerbose() override
{
return state_.lock()->printBuildLogs;
return progressBarSettings.printBuildLogs;
}

void log(Verbosity lvl, const FormatOrString & fs) override
@@ -470,7 +472,7 @@ class ProgressBar : public Logger
auto i = state->its.find(act);
assert(i != state->its.end());
i->second->lastLine = lastLine;
if (state->printBuildLogs) {
if (progressBarSettings.printBuildLogs) {
auto suffix = "> ";
if (type == resPostBuildLogLine) {
suffix = " (post)> ";
@@ -709,22 +711,16 @@ class ProgressBar : public Logger
}
};

Logger * makeProgressBar(bool printBuildLogs)
Logger * makeProgressBar()
{
return new ProgressBar(
printBuildLogs,
isatty(STDIN_FILENO)
&& isatty(STDOUT_FILENO)
&& isatty(STDERR_FILENO)
&& getEnv("TERM").value_or("dumb") != "dumb"
);
}

void startProgressBar(bool printBuildLogs)
{
logger = makeProgressBar(printBuildLogs);
}

void stopProgressBar()
{
auto progressBar = dynamic_cast<ProgressBar *>(logger);
12 changes: 9 additions & 3 deletions src/libmain/progress-bar.hh
Original file line number Diff line number Diff line change
@@ -4,10 +4,16 @@

namespace nix {

Logger * makeProgressBar(bool printBuildLogs = false);

void startProgressBar(bool printBuildLogs = false);
Logger * makeProgressBar();

void stopProgressBar();

struct ProgressBarSettings : Config
{
Setting<bool> printBuildLogs{this, false, "print-build-logs",
"Whether the progress bar should print full build logs or just the most recent line."};
};

extern ProgressBarSettings progressBarSettings;

}
3 changes: 2 additions & 1 deletion src/nix-prefetch-url/nix-prefetch-url.cc
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
#include "../nix/legacy.hh"
#include "progress-bar.hh"
#include "tarfile.hh"
#include "loggers.hh"

#include <iostream>

@@ -103,7 +104,7 @@ static int main_nix_prefetch_url(int argc, char * * argv)
Finally f([]() { stopProgressBar(); });

if (isatty(STDERR_FILENO))
startProgressBar();
setLogFormat(LogFormat::bar);

auto store = openStore();
auto state = std::make_unique<EvalState>(myArgs.searchPath, store);
12 changes: 6 additions & 6 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
#include "filetransfer.hh"
#include "finally.hh"
#include "loggers.hh"
#include "progress-bar.hh"

#include <sys/types.h>
#include <sys/socket.h>
@@ -55,7 +56,6 @@ std::string programPath;

struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
{
bool printBuildLogs = false;
bool useNet = true;
bool refresh = false;

@@ -92,7 +92,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
.longName = "print-build-logs",
.shortName = 'L',
.description = "print full build logs on stderr",
.handler = {[&]() {setLogFormat(LogFormat::barWithLogs); }},
.handler = {[&]() { progressBarSettings.printBuildLogs = true; }},
});

addFlag({
@@ -173,10 +173,6 @@ void mainWrapped(int argc, char * * argv)
settings.verboseBuild = false;
evalSettings.pureEval = true;

setLogFormat("bar");

Finally f([] { logger->stop(); });

NixArgs args;

if (argc == 2 && std::string(argv[1]) == "__dump-args") {
@@ -220,6 +216,10 @@ void mainWrapped(int argc, char * * argv)

if (completions) return;

setLogFormat(LogFormat::bar);

Finally f([] { logger->stop(); });

initPlugins();

if (!args.command) args.showHelpAndExit();