From df1ef68cd8e8582724ce1192bfc202e0b9aeaf0c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 28 Sep 2021 19:24:31 +0300 Subject: Get rid of C++ modules related code and rename *.mxx files to *.hxx --- libbutl/b.hxx | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 libbutl/b.hxx (limited to 'libbutl/b.hxx') diff --git a/libbutl/b.hxx b/libbutl/b.hxx new file mode 100644 index 0000000..cc3a309 --- /dev/null +++ b/libbutl/b.hxx @@ -0,0 +1,130 @@ +// file : libbutl/b.hxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#pragma once + +#include +#include +#include // move() +#include // size_tu +#include // uint16_t +#include // runtime_error +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace butl +{ + class LIBBUTL_SYMEXPORT b_error: public std::runtime_error + { + public: + // Build system program exit information. May be absent if the error + // occured before the process has been started. + // + // Can be used by the caller to decide if to print the error message to + // stderr. Normally, it is not required if the process exited normally + // with non-zero code, since presumably it has issued diagnostics. Note + // that the normal() function can be used to check for this. + // + optional exit; + + // Return true if the build2 process exited normally with non-zero code. + // + bool + normal () const {return exit && exit->normal () && !*exit;} + + explicit + b_error (const std::string& description, optional = nullopt); + }; + + // Run `b info: ...` command and parse and return (via argument + // to allow appending and for error position; see below) the build2 projects + // information it prints to stdout. Return the empty list if the specified + // project list is empty. Throw b_error on error. Note that the size of the + // result vector can be used to determine which project information caused + // the error. + // + // Unless you need information that may come from external modules + // (operations, meta-operations, etc), pass false as the ext_mods argument, + // which results in passing --no-external-modules to the build2 program and + // speeds up its execution. + // + // You can also specify the build2 verbosity level, command line callback + // (see process_run_callback() for details), build program search details, + // and additional options. + // + // Note that version_string is only parsed to standard_version if a project + // uses the version module. Otherwise, standard_version is empty. + // + struct b_project_info + { + using url_type = butl::url; + + struct subproject + { + project_name name; // Empty if anonymous. + dir_path path; // Relative to the project root. + }; + + project_name project; + std::string version_string; + standard_version version; + std::string summary; + url_type url; + + dir_path src_root; + dir_path out_root; + + dir_path amalgamation; // Relative to project root and + // empty if not amalgmated. + std::vector subprojects; + + std::vector operations; + std::vector meta_operations; + + std::vector modules; + }; + + using b_callback = void (const char* const args[], std::size_t n); + + LIBBUTL_SYMEXPORT void + b_info (std::vector& result, + const std::vector& projects, + bool ext_mods, + std::uint16_t verb = 1, + const std::function& cmd_callback = {}, + const path& program = path ("b"), + const dir_path& search_fallback = {}, + const std::vector& options = {}); + + // As above but retrieve information for a single project. + // + inline b_project_info + b_info (const dir_path& project, + bool ext_mods, + std::uint16_t verb = 1, + const std::function& cmd_callback = {}, + const path& program = path ("b"), + const dir_path& search_fallback = {}, + const std::vector& options = {}) + { + std::vector r; + b_info (r, + std::vector ({project}), + ext_mods, + verb, + cmd_callback, + program, + search_fallback, + options); + + return std::move (r[0]); + } +} -- cgit v1.1