aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-02-21 06:24:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-02-21 06:24:27 +0200
commita7a3cf206851b5896d938efa34a142aa1f0649b0 (patch)
tree9a4f09fb7fc764ddef284e5d011afc27a9b4fe4c /libbuild2
parent24adee85717a9bc61013b6b12fd81135d856d33d (diff)
Factor additional logic to parse_cmdline()
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/cmdline.cxx76
-rw-r--r--libbuild2/cmdline.hxx19
2 files changed, 90 insertions, 5 deletions
diff --git a/libbuild2/cmdline.cxx b/libbuild2/cmdline.cxx
index a5f9616..e022762 100644
--- a/libbuild2/cmdline.cxx
+++ b/libbuild2/cmdline.cxx
@@ -9,6 +9,7 @@
#include <libbutl/default-options.hxx>
#include <libbuild2/b-options.hxx>
+#include <libbuild2/scheduler.hxx>
#include <libbuild2/diagnostics.hxx>
using namespace std;
@@ -19,18 +20,24 @@ namespace cli = build2::build::cli;
namespace build2
{
cmdline
- parse_cmdline (tracer& trace, int argc, char* argv[], options& ops)
+ parse_cmdline (tracer& trace,
+ int argc, char* argv[],
+ options& ops,
+ uint16_t def_verb,
+ size_t def_jobs)
{
// Note that the diagnostics verbosity level can only be calculated after
// default options are loaded and merged (see below). Thus, until then we
// refer to the verbosity level specified on the command line.
//
- auto verbosity = [&ops] ()
+ auto verbosity = [&ops, def_verb] ()
{
uint16_t v (
ops.verbose_specified ()
? ops.verbose ()
- : ops.V () ? 3 : ops.v () ? 2 : ops.quiet () || ops.silent () ? 0 : 1);
+ : (ops.V () ? 3 :
+ ops.v () ? 2 :
+ ops.quiet () || ops.silent () ? 0 : def_verb));
return v;
};
@@ -397,12 +404,75 @@ namespace build2
fail << e;
}
+ if (ops.help () || ops.version ())
+ return r;
+
r.verbosity = verbosity ();
if (ops.silent () && r.verbosity != 0)
fail << "specified with -v, -V, or --verbose verbosity level "
<< r.verbosity << " is incompatible with --silent";
+ r.progress = (ops.progress () ? optional<bool> (true) :
+ ops.no_progress () ? optional<bool> (false) : nullopt);
+
+ r.mtime_check = (ops.mtime_check () ? optional<bool> (true) :
+ ops.no_mtime_check () ? optional<bool> (false) : nullopt);
+
+
+ r.config_sub = (ops.config_sub_specified ()
+ ? optional<path> (ops.config_sub ())
+ : nullopt);
+
+ r.config_guess = (ops.config_guess_specified ()
+ ? optional<path> (ops.config_guess ())
+ : nullopt);
+
+ if (ops.jobs_specified ())
+ r.jobs = ops.jobs ();
+ else if (ops.serial_stop ())
+ r.jobs = 1;
+
+ if (def_jobs != 0)
+ r.jobs = def_jobs;
+ else
+ {
+ if (r.jobs == 0)
+ r.jobs = scheduler::hardware_concurrency ();
+
+ if (r.jobs == 0)
+ {
+ warn << "unable to determine the number of hardware threads" <<
+ info << "falling back to serial execution" <<
+ info << "use --jobs|-j to override";
+
+ r.jobs = 1;
+ }
+ }
+
+ if (ops.max_jobs_specified ())
+ {
+ r.max_jobs = ops.max_jobs ();
+
+ if (r.max_jobs != 0 && r.max_jobs < r.jobs)
+ fail << "invalid --max-jobs|-J value";
+ }
+
+ r.max_stack = (ops.max_stack_specified ()
+ ? optional<size_t> (ops.max_stack () * 1024)
+ : nullopt);
+
+ if (ops.file_cache_specified ())
+ {
+ const string& v (ops.file_cache ());
+ if (v == "noop" || v == "none")
+ r.fcache_compress = false;
+ else if (v == "sync-lz4")
+ r.fcache_compress = true;
+ else
+ fail << "invalid --file-cache value '" << v << "'";
+ }
+
return r;
}
}
diff --git a/libbuild2/cmdline.hxx b/libbuild2/cmdline.hxx
index 7bf41c2..56e9510 100644
--- a/libbuild2/cmdline.hxx
+++ b/libbuild2/cmdline.hxx
@@ -19,11 +19,26 @@ namespace build2
{
strings cmd_vars;
string buildspec;
- uint16_t verbosity;
+
+ // Processed/meged option values (unless --help or --version specified).
+ //
+ uint16_t verbosity = 1;
+ optional<bool> progress;
+ optional<bool> mtime_check;
+ optional<path> config_sub;
+ optional<path> config_guess;
+ size_t jobs = 0;
+ size_t max_jobs = 0;
+ optional<size_t> max_stack;
+ bool fcache_compress = true;
};
LIBBUILD2_SYMEXPORT cmdline
- parse_cmdline (tracer&, int argc, char* argv[], options&);
+ parse_cmdline (tracer&,
+ int argc, char* argv[],
+ options&,
+ uint16_t default_verbosity = 1,
+ size_t default_jobs = 0);
}
#endif // LIBBUILD2_CMDLINE_HXX