From bf2cf8cd53361826e51e01c2904f6fb4cb7502dc Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 16 Aug 2019 22:39:07 +0300 Subject: Add support for default options files --- build2/b.cxx | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'build2/b.cxx') diff --git a/build2/b.cxx b/build2/b.cxx index 8965d64..15844dc 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -19,8 +19,9 @@ #include // terminate(), set_terminate(), terminate_handler #include -#include // stderr_fd(), fdterm() -#include // backtrace() +#include // stderr_fd(), fdterm() +#include // backtrace() +#include #include #include @@ -225,6 +226,18 @@ main (int argc, char* argv[]) // try { + // Note that the diagnostics verbosity level can only be calculated after + // default options are loaded and merged (see below). Thus, to trace the + // default options files search, we refer to the verbosity level specified + // on the command line. + // + auto verbosity = [] () + { + return ops.verbose_specified () + ? ops.verbose () + : ops.V () ? 3 : ops.v () ? 2 : ops.quiet () ? 0 : 1; + }; + // We want to be able to specify options, vars, and buildspecs in any // order (it is really handy to just add -v at the end of the command // line). @@ -349,6 +362,36 @@ main (int argc, char* argv[]) args += ')'; } + // Handle default options files. + // + if (!ops.no_default_options ()) // Command line option. + try + { + ops = merge_default_options ( + load_default_options ( + nullopt /* sys_dir */, + path::home_directory (), // The home variable is not assigned yet. + default_options_files {{path ("b.options")}, + nullopt /* start_dir */}, + [&trace, &verbosity] (const path& f, bool remote) + { + if (verbosity () >= 3) + trace << "loading " << (remote ? "remote " : "local ") << f; + }), + ops); + } + catch (const pair& e) + { + fail << "unable to load default options files: " << e.first << ": " + << e.second; + } + catch (const system_error& e) + { + fail << "unable to obtain home directory: " << e; + } + // Validate options. // if (ops.progress () && ops.no_progress ()) @@ -364,9 +407,7 @@ main (int argc, char* argv[]) // Initialize the diagnostics state. // - init_diag ((ops.verbose_specified () - ? ops.verbose () - : ops.V () ? 3 : ops.v () ? 2 : ops.quiet () ? 0 : 1), + init_diag (verbosity (), (ops.progress () ? optional (true) : ops.no_progress () ? optional (false) : nullopt), ops.no_line (), -- cgit v1.1