diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-10-25 09:38:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-10-25 09:38:40 +0200 |
commit | 73fd1a275b7ed039ef3ca18a3706692e9e95177a (patch) | |
tree | 1565fca68586c4c23ac6ceedc507f8aed93e7d13 | |
parent | aca0c7906724b2c0b648c06604e60fc3164e6f6a (diff) |
Add --silent, remap verbosity 0 to 1 while building modules unless silent
Failed that, we may have long periods of seemingly nothing happening (e.g.,
during implicit bdep sync) while we quietly update the module, which may look
like things have hung up.
-rw-r--r-- | build2/b-options.cxx | 31 | ||||
-rw-r--r-- | build2/b-options.hxx | 4 | ||||
-rw-r--r-- | build2/b-options.ixx | 6 | ||||
-rw-r--r-- | build2/b.cli | 20 | ||||
-rw-r--r-- | build2/b.cxx | 14 | ||||
-rw-r--r-- | libbuild2/diagnostics.cxx | 6 | ||||
-rw-r--r-- | libbuild2/diagnostics.hxx | 8 | ||||
-rw-r--r-- | libbuild2/module.cxx | 15 | ||||
-rw-r--r-- | libbuild2/utility.hxx | 6 |
9 files changed, 90 insertions, 20 deletions
diff --git a/build2/b-options.cxx b/build2/b-options.cxx index 878eb25..dc6b939 100644 --- a/build2/b-options.cxx +++ b/build2/b-options.cxx @@ -650,6 +650,7 @@ namespace build2 : v_ (), V_ (), quiet_ (), + silent_ (), verbose_ (1), verbose_specified_ (false), stat_ (), @@ -777,6 +778,12 @@ namespace build2 this->quiet_, a.quiet_); } + if (a.silent_) + { + ::build2::cl::parser< bool>::merge ( + this->silent_, a.silent_); + } + if (a.verbose_specified_) { ::build2::cl::parser< uint16_t>::merge ( @@ -957,20 +964,28 @@ namespace build2 os << "\033[1mOPTIONS\033[0m" << ::std::endl; os << std::endl - << "\033[1m-v\033[0m Print actual commands being executed. This is equivalent" << ::std::endl - << " to \033[1m--verbose 2\033[0m." << ::std::endl; + << "\033[1m-v\033[0m Print actual commands being executed. This options is" << ::std::endl + << " equivalent to \033[1m--verbose 2\033[0m." << ::std::endl; + + os << std::endl + << "\033[1m-V\033[0m Print all underlying commands being executed. This" << ::std::endl + << " options is equivalent to \033[1m--verbose 3\033[0m." << ::std::endl; os << std::endl - << "\033[1m-V\033[0m Print all underlying commands being executed. This is" << ::std::endl - << " equivalent to \033[1m--verbose 3\033[0m." << ::std::endl; + << "\033[1m--quiet\033[0m|\033[1m-q\033[0m Run quietly, only printing error messages in most" << ::std::endl + << " contexts. In certain contexts (for example, while" << ::std::endl + << " updating build system modules) this verbosity level may" << ::std::endl + << " be ignored. Use --silent\033[0m to run quietly in all contexts." << ::std::endl + << " This option is equivalent to \033[1m--verbose 0\033[0m." << ::std::endl; os << std::endl - << "\033[1m--quiet\033[0m|\033[1m-q\033[0m Run quietly, only printing error messages. This is" << ::std::endl - << " equivalent to \033[1m--verbose 0\033[0m." << ::std::endl; + << "\033[1m--silent\033[0m Run quietly, only printing error messages in all" << ::std::endl + << " contexts." << ::std::endl; os << std::endl << "\033[1m--verbose\033[0m \033[4mlevel\033[0m Set the diagnostics verbosity to \033[4mlevel\033[0m between 0 and 6." << ::std::endl - << " Level 0 disables any non-error messages while level 6" << ::std::endl + << " Level 0 disables any non-error messages (but see the" << ::std::endl + << " difference between --quiet\033[0m and --silent\033[0m) while level 6" << ::std::endl << " produces lots of information, with level 1 being the" << ::std::endl << " default. The following additional types of diagnostics" << ::std::endl << " are produced at each level:" << ::std::endl @@ -1168,6 +1183,8 @@ namespace build2 &::build2::cl::thunk< options, bool, &options::quiet_ >; _cli_options_map_["-q"] = &::build2::cl::thunk< options, bool, &options::quiet_ >; + _cli_options_map_["--silent"] = + &::build2::cl::thunk< options, bool, &options::silent_ >; _cli_options_map_["--verbose"] = &::build2::cl::thunk< options, uint16_t, &options::verbose_, &options::verbose_specified_ >; diff --git a/build2/b-options.hxx b/build2/b-options.hxx index 8fea395..4b1852b 100644 --- a/build2/b-options.hxx +++ b/build2/b-options.hxx @@ -439,6 +439,9 @@ namespace build2 const bool& quiet () const; + const bool& + silent () const; + const uint16_t& verbose () const; @@ -575,6 +578,7 @@ namespace build2 bool v_; bool V_; bool quiet_; + bool silent_; uint16_t verbose_; bool verbose_specified_; bool stat_; diff --git a/build2/b-options.ixx b/build2/b-options.ixx index 3433d79..b8d7198 100644 --- a/build2/b-options.ixx +++ b/build2/b-options.ixx @@ -278,6 +278,12 @@ namespace build2 return this->quiet_; } + inline const bool& options:: + silent () const + { + return this->silent_; + } + inline const uint16_t& options:: verbose () const { diff --git a/build2/b.cli b/build2/b.cli index bf3bf4d..dff707f 100644 --- a/build2/b.cli +++ b/build2/b.cli @@ -391,27 +391,35 @@ namespace build2 bool -v { - "Print actual commands being executed. This is equivalent to + "Print actual commands being executed. This options is equivalent to \cb{--verbose 2}." } bool -V { - "Print all underlying commands being executed. This is equivalent to - \cb{--verbose 3}." + "Print all underlying commands being executed. This options is + equivalent to \cb{--verbose 3}." } bool --quiet|-q { - "Run quietly, only printing error messages. This is equivalent to - \cb{--verbose 0}." + "Run quietly, only printing error messages in most contexts. In certain + contexts (for example, while updating build system modules) this + verbosity level may be ignored. Use \c{--silent} to run quietly in all + contexts. This option is equivalent to \cb{--verbose 0}." + } + + bool --silent + { + "Run quietly, only printing error messages in all contexts." } uint16_t --verbose = 1 { "<level>", "Set the diagnostics verbosity to <level> between 0 and 6. Level 0 - disables any non-error messages while level 6 produces lots of + disables any non-error messages (but see the difference between + \c{--quiet} and \c{--silent}) while level 6 produces lots of information, with level 1 being the default. The following additional types of diagnostics are produced at each level: diff --git a/build2/b.cxx b/build2/b.cxx index e093641..4571567 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -237,9 +237,16 @@ main (int argc, char* argv[]) // auto verbosity = [] () { - return ops.verbose_specified () - ? ops.verbose () - : ops.V () ? 3 : ops.v () ? 2 : ops.quiet () ? 0 : 1; + uint16_t v ( + ops.verbose_specified () + ? ops.verbose () + : ops.V () ? 3 : ops.v () ? 2 : ops.quiet () || ops.silent () ? 0 : 1); + + if (ops.silent () && v != 0) + fail << "specified with -v, -V, or --verbose verbosity level " << v + << " is incompatible with --silent"; + + return v; }; // We want to be able to specify options, vars, and buildspecs in any @@ -423,6 +430,7 @@ main (int argc, char* argv[]) // Initialize the diagnostics state. // init_diag (verbosity (), + ops.silent (), (ops.progress () ? optional<bool> (true) : ops.no_progress () ? optional<bool> (false) : nullopt), ops.no_line (), diff --git a/libbuild2/diagnostics.cxx b/libbuild2/diagnostics.cxx index 71f3d48..f1b8f74 100644 --- a/libbuild2/diagnostics.cxx +++ b/libbuild2/diagnostics.cxx @@ -21,6 +21,7 @@ namespace build2 // set from options. // uint16_t verb = 0; + bool silent = true; optional<bool> diag_progress_option; @@ -30,9 +31,12 @@ namespace build2 bool stderr_term = false; void - init_diag (uint16_t v, optional<bool> p, bool nl, bool nc, bool st) + init_diag (uint16_t v, bool s, optional<bool> p, bool nl, bool nc, bool st) { + assert (!s || v == 0); + verb = v; + silent = s; diag_progress_option = p; diag_no_line = nl; diag_no_column = nc; diff --git a/libbuild2/diagnostics.hxx b/libbuild2/diagnostics.hxx index 5d69132..26f602a 100644 --- a/libbuild2/diagnostics.hxx +++ b/libbuild2/diagnostics.hxx @@ -49,7 +49,7 @@ namespace build2 print_process (args.data (), n != 0 ? n : args.size ()); } - // Program verbosity level (-v/--verbose). + // Program verbosity level (-v/--verbose plus --silent). // // 0 - disabled // 1 - high-level information messages @@ -59,13 +59,17 @@ namespace build2 // 5 - information helpful to the developer // 6 - even more detailed information // + // If silent is true, then the level must be 0 (silent is level 0 that + // cannot be relaxed in certain contexts). + // // While uint8 is more than enough, use uint16 for the ease of printing. // // Forward-declarated in <libbuild2/utility.hxx>. // + // const uint16_t verb_never = 7; // extern uint16_t verb; - // const uint16_t verb_never = 7; + // extern bool silent; template <typename F> inline void l1 (const F& f) {if (verb >= 1) f ();} template <typename F> inline void l2 (const F& f) {if (verb >= 2) f ();} diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx index b73ddb3..50c6d53 100644 --- a/libbuild2/module.cxx +++ b/libbuild2/module.cxx @@ -262,6 +262,21 @@ namespace build2 ? scheduler::tune_guard (ctx.sched, 0) : scheduler::tune_guard ()); + // Remap verbosity level 0 to 1 unless we were requested to be + // silent. Failed that, we may have long periods of seemingly + // nothing happening while we quietly update the module, which + // may look like things have hung up. + // + // @@ CTX: modifying global verbosity level won't work if we have + // multiple top-level contexts running in parallel. + // + auto verbg = make_guard ( + [z = !silent && verb == 0 ? (verb = 1, true) : false] () + { + if (z) + verb = 0; + }); + // Note that for now we suppress progress since it would clash with // the progress of what we are already doing (maybe in the future we // can do save/restore but then we would need some sort of diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx index 536898e..1d5c7bb 100644 --- a/libbuild2/utility.hxx +++ b/libbuild2/utility.hxx @@ -97,15 +97,19 @@ namespace build2 // Initialize the diagnostics state. Should be called once early in main(). // Default values are for unit tests. // + // If silent is true, verbosity should be 0. + // LIBBUILD2_SYMEXPORT void init_diag (uint16_t verbosity, + bool silent = false, optional<bool> progress = nullopt, bool no_lines = false, bool no_columns = false, bool stderr_term = false); - LIBBUILD2_SYMEXPORT extern uint16_t verb; const uint16_t verb_never = 7; + LIBBUILD2_SYMEXPORT extern uint16_t verb; + LIBBUILD2_SYMEXPORT extern bool silent; // --[no-]progress // |