diff options
author | Jan Niklas Hasse <jhasse@bixense.com> | 2021-05-08 17:40:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-08 17:40:03 (GMT) |
commit | 0a632d11eb1e8b7becbd9756c3e3439777924f6d (patch) | |
tree | a7f5b523b9bfb2bd2a2a1b27ba3082732ba2e34a | |
parent | ce700488e01af33bc478bc986e261e306180b993 (diff) | |
parent | f926cd4503f8d70d116752c3f5f3db9ea3d47eca (diff) | |
download | Ninja-0a632d11eb1e8b7becbd9756c3e3439777924f6d.zip Ninja-0a632d11eb1e8b7becbd9756c3e3439777924f6d.tar.gz Ninja-0a632d11eb1e8b7becbd9756c3e3439777924f6d.tar.bz2 |
Merge pull request #1968 from EliRibble/pull-1818
Add --quiet option that suppresses status updates. (rework pull 1818)
-rwxr-xr-x | misc/output_test.py | 18 | ||||
-rw-r--r-- | src/build.h | 3 | ||||
-rw-r--r-- | src/ninja.cc | 9 | ||||
-rw-r--r-- | src/status.cc | 3 |
4 files changed, 29 insertions, 4 deletions
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 @@ def run(build_ninja, flags='', pipe=False, env=default_env): @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 @@ red 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 @@ struct BuildConfig { 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 @@ void Usage(const BuildConfig& config) { "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 @@ int ReadFlags(int* argc, char*** argv, 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 @@ int ReadFlags(int* argc, char*** argv, 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 @@ NORETURN void real_main(int argc, char** argv) { // 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 @@ string StatusPrinter::FormatProgressStatus(const char* progress_status_format, } 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; |