diff options
-rw-r--r-- | build2/b.cxx | 18 | ||||
-rw-r--r-- | build2/utility | 6 | ||||
-rw-r--r-- | build2/utility.cxx | 19 |
3 files changed, 29 insertions, 14 deletions
diff --git a/build2/b.cxx b/build2/b.cxx index d16a406..d800605 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -2,7 +2,6 @@ // copyright : Copyright (c) 2014-2016 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#include <time.h> // tzset() #include <string.h> // strerror() #include <stdlib.h> // getenv() _putenv()(_WIN32) @@ -160,11 +159,11 @@ main (int argc, char* argv[]) fail << e; } - // Diagnostics verbosity. + // Global initializations. // - verb = ops.verbose_specified () - ? ops.verbose () - : ops.V () ? 3 : ops.v () ? 2 : ops.q () ? 0 : 1; + init (ops.verbose_specified () + ? ops.verbose () + : ops.V () ? 3 : ops.v () ? 2 : ops.q () ? 0 : 1); // Version. // @@ -205,10 +204,6 @@ main (int argc, char* argv[]) } } - // Initialize time conversion data that is used by localtime_r(). - // - tzset (); - // Register builtin modules. // { @@ -248,11 +243,6 @@ main (int argc, char* argv[]) bm["cli"] = mf {nullptr, &cli::init}; } - // Figure out work and home directories. - // - work = dir_path::current (); - home = dir_path::home (); - if (verb >= 5) { const char* p (getenv ("PATH")); diff --git a/build2/utility b/build2/utility index 2625d51..1499def 100644 --- a/build2/utility +++ b/build2/utility @@ -469,6 +469,12 @@ namespace build2 const std::string& find (const std::string& s) {return *emplace (s).first;} }; + + // Initialize build2 global state (verbosity, home/work dirrectories, etc). + // Should be called early in main() once. + // + void + init (uint16_t verbosity); } #include <build2/utility.ixx> diff --git a/build2/utility.cxx b/build2/utility.cxx index 43a5370..0e97020 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -4,6 +4,8 @@ #include <build2/utility> +#include <time.h> // tzset() + #include <cstring> // strlen(), str[n]cmp() #include <cstdlib> // strtol() #include <iostream> // cerr @@ -498,4 +500,21 @@ namespace build2 } bool exception_unwinding_dtor = false; + + void + init (uint16_t v) + { + // Diagnostics verbosity. + // + verb = v; + + // Initialize time conversion data that is used by localtime_r(). + // + tzset (); + + // Figure out work and home directories. + // + work = dir_path::current (); + home = dir_path::home (); + } } |