Merge pull request #1968 from EliRibble/pull-1818
Add --quiet option that suppresses status updates. (rework pull 1818)
diff --git a/misc/output_test.py b/misc/output_test.py
index b63520f..6858e21 100755
--- a/misc/output_test.py
+++ b/misc/output_test.py
@@ -48,6 +48,15 @@
@unittest.skipIf(platform.system() == 'Windows', 'These test methods do not work on Windows')
class Output(unittest.TestCase):
+ BUILD_SIMPLE_ECHO = '\n'.join((
+ 'rule echo',
+ ' command = printf "do thing"',
+ ' description = echo $out',
+ '',
+ 'build a: echo',
+ '',
+ ))
+
def test_issue_1418(self):
self.assertEqual(run(
'''rule echo
@@ -111,5 +120,14 @@
def test_status(self):
self.assertEqual(run(''), 'ninja: no work to do.\n')
+ def test_ninja_status_default(self):
+ 'Do we show the default status by default?'
+ self.assertEqual(run(Output.BUILD_SIMPLE_ECHO), '[1/1] echo a\x1b[K\ndo thing\n')
+
+ def test_ninja_status_quiet(self):
+ 'Do we suppress the status information when --quiet is specified?'
+ output = run(Output.BUILD_SIMPLE_ECHO, flags='--quiet')
+ self.assertEqual(output, 'do thing\n')
+
if __name__ == '__main__':
unittest.main()
diff --git a/src/build.h b/src/build.h
index 06823c2..d697dfb 100644
--- a/src/build.h
+++ b/src/build.h
@@ -159,8 +159,9 @@
failures_allowed(1), max_load_average(-0.0f) {}
enum Verbosity {
- NORMAL,
QUIET, // No output -- used when testing.
+ NO_STATUS_UPDATE, // just regular output but suppress status update
+ NORMAL, // regular output and status update
VERBOSE
};
Verbosity verbosity;
diff --git a/src/ninja.cc b/src/ninja.cc
index 56e31e0..c7182df 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -217,6 +217,7 @@
"options:\n"
" --version print ninja version (\"%s\")\n"
" -v, --verbose show all command lines while building\n"
+" --quiet don't show progress status, just command output\n"
"\n"
" -C DIR change to DIR before doing anything else\n"
" -f FILE specify input build file [default=build.ninja]\n"
@@ -1307,11 +1308,12 @@
Options* options, BuildConfig* config) {
config->parallelism = GuessParallelism();
- enum { OPT_VERSION = 1 };
+ enum { OPT_VERSION = 1, OPT_QUIET = 2 };
const option kLongOptions[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, OPT_VERSION },
{ "verbose", no_argument, NULL, 'v' },
+ { "quiet", no_argument, NULL, OPT_QUIET },
{ NULL, 0, NULL, 0 }
};
@@ -1369,6 +1371,9 @@
case 'v':
config->verbosity = BuildConfig::VERBOSE;
break;
+ case OPT_QUIET:
+ config->verbosity = BuildConfig::NO_STATUS_UPDATE;
+ break;
case 'w':
if (!WarningEnable(optarg, options))
return 1;
@@ -1414,7 +1419,7 @@
// subsequent commands.
// Don't print this if a tool is being used, so that tool output
// can be piped into a file without this string showing up.
- if (!options.tool)
+ if (!options.tool && config.verbosity != BuildConfig::NO_STATUS_UPDATE)
status->Info("Entering directory `%s'", options.working_dir);
if (chdir(options.working_dir) < 0) {
Fatal("chdir to '%s' - %s", options.working_dir, strerror(errno));
diff --git a/src/status.cc b/src/status.cc
index 171cbeb..88b7781 100644
--- a/src/status.cc
+++ b/src/status.cc
@@ -228,7 +228,8 @@
}
void StatusPrinter::PrintStatus(const Edge* edge, int64_t time_millis) {
- if (config_.verbosity == BuildConfig::QUIET)
+ if (config_.verbosity == BuildConfig::QUIET
+ || config_.verbosity == BuildConfig::NO_STATUS_UPDATE)
return;
bool force_full_command = config_.verbosity == BuildConfig::VERBOSE;