diff options
Diffstat (limited to 'bpkg/utility.hxx')
-rw-r--r-- | bpkg/utility.hxx | 126 |
1 files changed, 97 insertions, 29 deletions
diff --git a/bpkg/utility.hxx b/bpkg/utility.hxx index 4360118..7a51948 100644 --- a/bpkg/utility.hxx +++ b/bpkg/utility.hxx @@ -4,20 +4,21 @@ #ifndef BPKG_UTILITY_HXX #define BPKG_UTILITY_HXX +#include <map> #include <memory> // make_shared() #include <string> // to_string() #include <cstring> // strcmp(), strchr() #include <utility> // move(), forward(), declval(), make_pair() #include <cassert> // assert() -#include <iterator> // make_move_iterator() +#include <iterator> // make_move_iterator(), back_inserter() #include <algorithm> // * #include <libbutl/ft/lang.hxx> -#include <libbutl/utility.mxx> // icasecmp(), reverse_iterate(), etc -#include <libbutl/process.mxx> -#include <libbutl/filesystem.mxx> -#include <libbutl/default-options.mxx> +#include <libbutl/utility.hxx> // icasecmp(), reverse_iterate(), etc +#include <libbutl/process.hxx> +#include <libbutl/filesystem.hxx> +#include <libbutl/default-options.hxx> #include <bpkg/types.hxx> #include <bpkg/version.hxx> @@ -32,16 +33,27 @@ namespace bpkg using std::make_pair; using std::make_shared; using std::make_move_iterator; + using std::back_inserter; using std::to_string; using std::strcmp; using std::strchr; - // <libbutl/utility.mxx> + // <libbutl/utility.hxx> // using butl::icasecmp; using butl::reverse_iterate; + using butl::alpha; + using butl::alnum; + using butl::digit; + using butl::xdigit; + + using butl::trim; + using butl::trim_left; + using butl::trim_right; + using butl::next_word; + using butl::make_guard; using butl::make_exception_guard; @@ -49,16 +61,19 @@ namespace bpkg using butl::setenv; using butl::unsetenv; - // <libbutl/process.mxx> + using butl::eof; + + // <libbutl/process.hxx> // using butl::process_start_callback; + using butl::process_print_callback; - // <libbutl/filesystem.mxx> + // <libbutl/filesystem.hxx> // using butl::auto_rmfile; using butl::auto_rmdir; - // <libbutl/default-options.mxx> + // <libbutl/default-options.hxx> // using butl::load_default_options; using butl::merge_default_options; @@ -71,26 +86,46 @@ namespace bpkg // Widely-used paths. // - extern const dir_path bpkg_dir; // .bpkg/ - extern const dir_path certs_dir; // .bpkg/certs/ - extern const dir_path repos_dir; // .bpkg/repos/ - extern const dir_path current_dir; // ./ + extern const dir_path bpkg_dir; // .bpkg/ + extern const dir_path certs_dir; // .bpkg/certs/ + extern const dir_path repos_dir; // .bpkg/repos/ + + extern const dir_path std_build_dir; // build/ + extern const dir_path std_config_dir; // build/config/ + extern const path std_bootstrap_file; // build/bootstrap.build + extern const path std_root_file; // build/root.build + extern const string std_build_ext; // build + + extern const dir_path alt_build_dir; // build2/ + extern const dir_path alt_config_dir; // build2/config/ + extern const path alt_bootstrap_file; // build2/bootstrap.build2 + extern const path alt_root_file; // build2/root.build2 + extern const string alt_build_ext; // build2 + + extern const dir_path current_dir; // ./ + + // Host target triplet for which we were built. + // + extern const target_triplet host_triplet; // Temporary directory facility. // - // This is normally .bpkg/tmp/ but can also be some system-wide directory - // (e.g., /tmp/bpkg-XXX/) if there is no bpkg configuration. This directory - // is automatically created and cleaned up for most commands in main() so - // you don't need to call init_tmp() explicitly except for certain special - // commands (like cfg-create). + // An entry normally maps <cfg-dir> to <cfg-dir>/.bpkg/tmp/ but can also map + // an empty directory to some system-wide directory (e.g., /tmp/bpkg-XXX/) + // if there is no bpkg configuration. The temporary directory for the + // current configuration is automatically created and cleaned up for most + // commands in main(), so you don't need to call init_tmp() explicitly + // except for certain special commands (like cfg-create). // - extern dir_path temp_dir; + extern std::map<dir_path, dir_path> tmp_dirs; + + extern bool keep_tmp; // --keep-tmp auto_rmfile - tmp_file (const string& prefix); + tmp_file (const dir_path& cfg, const string& prefix); auto_rmdir - tmp_dir (const string& prefix); + tmp_dir (const dir_path& cfg, const string& prefix); void init_tmp (const dir_path& cfg); @@ -123,9 +158,20 @@ namespace bpkg return move (normalize (r, what)); } - // Progress. + dir_path + current_directory (); + + // Diagnostics. + // + // If stderr is not a terminal, then the value is absent (so can be used as + // bool). Otherwise, it is the value of the TERM environment variable (which + // can be NULL). + // + extern optional<const char*> stderr_term; + + // True if the color can be used on the stderr terminal. // - extern bool stderr_term; // True if stderr is a terminal. + extern bool stderr_term_color; // Y/N prompt. See butl::yn_prompt() for details (this is a thin wrapper). // @@ -163,8 +209,13 @@ namespace bpkg uint16_t verbosity = 3, rm_error_mode = rm_error_mode::fail); - void - mv (const dir_path& from, const dir_path& to); + // Note that if ignore_error is true, the diagnostics is still issued. + // + bool + mv (const dir_path& from, const dir_path& to, bool ignore_errors = false); + + bool + mv (const path& from, const path& to, bool ignore_errors = false); // Set (with diagnostics at verbosity level 3 or higher) the new and return // the previous working directory. @@ -185,11 +236,8 @@ namespace bpkg // extern dir_path exec_dir; - // Run build2, mapping verbosity levels. If quiet is true, then run build2 - // quiet if our verbosity level is 1. + // Run build2, mapping verbosity levels. // - const char* - name_b (const common_options&); // Verbosity level 1 mapping. // @@ -200,6 +248,20 @@ namespace bpkg normal // Run normally (at verbosity 1). }; + template <typename V> + void + map_verb_b (const common_options&, verb_b, V& args, string& verb_arg); + + const char* + name_b (const common_options&); + + process_path + search_b (const common_options&); + + template <typename... A> + void + print_b (const common_options&, verb_b, A&&... args); + template <typename O, typename E, typename... A> process start_b (const common_options&, O&& out, E&& err, verb_b, A&&... args); @@ -207,6 +269,12 @@ namespace bpkg template <typename... A> void run_b (const common_options&, verb_b, A&&... args); + + // Read out the data from the specified file descriptor and dump it to + // stderr. Throw io_error on the underlying OS errors. + // + void + dump_stderr (auto_fd&&); } #include <bpkg/utility.txx> |