From 4c7b3f9500c668aa99328e419f6d09c722814f97 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 29 Mar 2018 14:02:18 +0200 Subject: Improve pkg-checkout progress diagnostics at verbosity level 1 --- bpkg/bpkg.cxx | 2 ++ bpkg/cfg-create.cxx | 2 +- bpkg/pkg-checkout.cxx | 19 ++++++++++++++----- bpkg/pkg-command.cxx | 2 +- bpkg/pkg-configure.cxx | 2 +- bpkg/pkg-disfigure.cxx | 2 +- bpkg/utility.cxx | 19 ++++++++++++++++--- bpkg/utility.hxx | 15 ++++++++++++++- 8 files changed, 50 insertions(+), 13 deletions(-) (limited to 'bpkg') diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index ece9046..c82c92d 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -47,6 +47,7 @@ #include using namespace std; +using namespace butl; using namespace bpkg; // Get -d|--directory value if the option class O has it and empty path @@ -139,6 +140,7 @@ try { using namespace cli; + stderr_term = fdterm (stderr_fd ()); exec_dir = path (argv[0]).directory (); // This is a little hack to make our baseutils for Windows work when called diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx index 9b56cad..b62163e 100644 --- a/bpkg/cfg-create.cxx +++ b/bpkg/cfg-create.cxx @@ -77,7 +77,7 @@ namespace bpkg run_b (o, c, "create('" + c.representation () + "'" + mods + ")", - true, + verb_b::quiet, vars); // Create .bpkg/ and its subdirectories. diff --git a/bpkg/pkg-checkout.cxx b/bpkg/pkg-checkout.cxx index c53e545..faa1099 100644 --- a/bpkg/pkg-checkout.cxx +++ b/bpkg/pkg-checkout.cxx @@ -156,18 +156,27 @@ namespace bpkg // Distribute. // - // Note that on failure the package stays in the existing (working) state. + // Note that on failure the package stays in the existing (working) + // state. // // At first it may seem we have a problem: an existing package with the // same name will cause a conflict since we now have multiple package - // locations for the same package name. We are luck, however: subprojects - // are only loaded if used and since we don't support dependency cycles, - // the existing project should never be loaded by any of our dependencies. + // locations for the same package name. We are lucky, however: + // subprojects are only loaded if used and since we don't support + // dependency cycles, the existing project should never be loaded by any + // of our dependencies. // + + // At verbosity level 1 we want our (nicer) progress header but the + // build system's actual progress. + // + if (verb == 1) + text << "distributing " << n << '/' << v; + run_b (o, c, bspec, - false /* quiet */, + verb_b::progress, strings ({"config.dist.root=" + c.representation ()})); mc = sha256 (o, d / manifest_file); diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index a4260a8..4475ea7 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -39,7 +39,7 @@ namespace bpkg { bspec += ')'; l4 ([&]{trace << "buildspec: " << bspec;}); - run_b (o, c, bspec, false, vars, cvars); + run_b (o, c, bspec, verb_b::normal, vars, cvars); bspec.clear (); } }; diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index a7e1a17..7aa4183 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -162,7 +162,7 @@ namespace bpkg // try { - run_b (o, c, bspec, true, vars); // Run quiet. + run_b (o, c, bspec, verb_b::quiet, vars); } catch (const failed&) { diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx index 0e1f8a6..4a0bd72 100644 --- a/bpkg/pkg-disfigure.cxx +++ b/bpkg/pkg-disfigure.cxx @@ -126,7 +126,7 @@ namespace bpkg if (clean && p->external ()) rm_r (out_root); else - run_b (o, c, bspec, true); // Run quiet. + run_b (o, c, bspec, verb_b::quiet); } // Make sure the out directory is gone unless it is the same as src, diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx index 652cd46..f48d96d 100644 --- a/bpkg/utility.cxx +++ b/bpkg/utility.cxx @@ -82,6 +82,8 @@ namespace bpkg } } + bool stderr_term; + bool yn_prompt (const char* prompt, char def) { @@ -323,7 +325,7 @@ namespace bpkg run_b (const common_options& co, const dir_path& c, const string& bspec, - bool quiet, + verb_b v, const strings& pvars, const strings& cvars) { @@ -334,11 +336,22 @@ namespace bpkg // as us. // string vl; - if (verb <= (quiet ? 1 : 0)) + + if (verb == 0) args.push_back ("-q"); + else if (verb == 1) + { + if (v != verb_b::normal) + { + args.push_back ("-q"); + + if (v == verb_b::progress && stderr_term) + args.push_back ("--progress"); + } + } else if (verb == 2) args.push_back ("-v"); - else if (verb > 2) + else { vl = to_string (verb); args.push_back ("--verbose"); diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx index 5c370ef..c347bda 100644 --- a/bpkg/utility.hxx +++ b/bpkg/utility.hxx @@ -79,6 +79,10 @@ namespace bpkg void clean_tmp (bool ignore_errors); + // Progress. + // + extern bool stderr_term; // True if stderr is a terminal. + // Y/N prompt. The def argument, if specified, should be either 'y' // or 'n'. It is used as the default answer, in case the user just // hits enter. Issue diagnostics and throw failed if no answer could @@ -157,11 +161,20 @@ namespace bpkg const char* name_b (const common_options&); + // Verbosity level 1 mapping. + // + enum class verb_b + { + quiet, // Run quiet. + progress, // Run quiet but (potentially) with progress. + normal // Run normally (at verbosity 1). + }; + void run_b (const common_options&, const dir_path& configuration, const string& buildspec, - bool quiet = false, + verb_b = verb_b::normal, const strings& pvars = strings (), const strings& cvars = strings ()); } -- cgit v1.1