diff options
Diffstat (limited to 'bpkg/utility.txx')
-rw-r--r-- | bpkg/utility.txx | 138 |
1 files changed, 95 insertions, 43 deletions
diff --git a/bpkg/utility.txx b/bpkg/utility.txx index b2c2a3c..33bb711 100644 --- a/bpkg/utility.txx +++ b/bpkg/utility.txx @@ -7,6 +7,88 @@ namespace bpkg { // *_b() // + template <typename V> + void + map_verb_b (const common_options& co, verb_b v, V& ops, string& verb_arg) + { + // Map verbosity level. If we are running quiet or at level 1, + // then run build2 quiet. Otherwise, run it at the same level + // as us. + // + bool progress (co.progress ()); + bool no_progress (co.no_progress ()); + + if (verb == 0) + { + ops.push_back ("-q"); + no_progress = false; // Already suppressed with -q. + } + else if (verb == 1) + { + // NOTE: search for verb_b usage if changing anything here. + // + if (v != verb_b::normal) + { + ops.push_back ("-q"); + + if (!no_progress) + { + if (v == verb_b::progress && stderr_term) + { + ops.push_back ("--progress"); + progress = false; // The option is already added. + } + } + else + no_progress = false; // Already suppressed with -q. + } + } + else if (verb == 2) + ops.push_back ("-v"); + else + { + verb_arg = to_string (verb); + ops.push_back ("--verbose"); + ops.push_back (verb_arg.c_str ()); + } + + if (progress) + ops.push_back ("--progress"); + + if (no_progress) + ops.push_back ("--no-progress"); + } + + template <typename... A> + void + print_b (const common_options& co, verb_b v, A&&... args) + { + process_path pp (search_b (co)); + + small_vector<const char*, 1> ops; + + // As in start_b() below. + // + string verb_arg; + map_verb_b (co, v, ops, verb_arg); + + if (co.diag_color ()) + ops.push_back ("--diag-color"); + + if (co.no_diag_color ()) + ops.push_back ("--no-diag-color"); + + process_print_callback ( + [] (const char* const args[], size_t n) + { + print_process (args, n); + }, + pp, + ops, + co.build_option (), + forward<A> (args)...); + } + template <typename O, typename E, typename... A> process start_b (const common_options& co, @@ -15,57 +97,27 @@ namespace bpkg verb_b v, A&&... args) { - const char* b (name_b (co)); + process_path pp (search_b (co)); try { - // Use our executable directory as a fallback search since normally the - // entire toolchain is installed into one directory. This way, for - // example, if we installed into /opt/build2 and run bpkg with absolute - // path (and without PATH), then bpkg will be able to find "its" b. - // - process_path pp (process::path_search (b, exec_dir)); - small_vector<const char*, 1> ops; - // Map verbosity level. If we are running quiet or at level 1, - // then run build2 quiet. Otherwise, run it at the same level - // as us. + // NOTE: see print_b() above if changing anything here. // - string vl; - bool no_progress (co.no_progress ()); + // NOTE: see custom versions in system_package_manager* if adding + // anything new here (search for search_b()). - if (verb == 0) - { - ops.push_back ("-q"); - no_progress = false; // Already suppressed with -q. - } - else if (verb == 1) - { - if (v != verb_b::normal) - { - ops.push_back ("-q"); + string verb_arg; + map_verb_b (co, v, ops, verb_arg); - if (!no_progress) - { - if (v == verb_b::progress && stderr_term) - ops.push_back ("--progress"); - } - else - no_progress = false; // Already suppressed with -q. - } - } - else if (verb == 2) - ops.push_back ("-v"); - else - { - vl = to_string (verb); - ops.push_back ("--verbose"); - ops.push_back (vl.c_str ()); - } + // Forward our --[no]diag-color options. + // + if (co.diag_color ()) + ops.push_back ("--diag-color"); - if (no_progress) - ops.push_back ("--no-progress"); + if (co.no_diag_color ()) + ops.push_back ("--no-diag-color"); return process_start_callback ( [] (const char* const args[], size_t n) @@ -83,7 +135,7 @@ namespace bpkg } catch (const process_error& e) { - fail << "unable to execute " << b << ": " << e << endf; + fail << "unable to execute " << pp.recall_string () << ": " << e << endf; } } |