From 78be8e1604f183b28527159047bab69a5cbe9232 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 14 Jan 2019 22:00:36 +0300 Subject: Add b_info() that runs `b info` command and parses and returns build2 project info --- libbutl/b.mxx | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 libbutl/b.mxx (limited to 'libbutl/b.mxx') diff --git a/libbutl/b.mxx b/libbutl/b.mxx new file mode 100644 index 0000000..cd574f0 --- /dev/null +++ b/libbutl/b.mxx @@ -0,0 +1,110 @@ +// file : libbutl/b.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef __cpp_modules +#pragma once +#endif + +// C includes. + +#ifndef __cpp_lib_modules +#include +#include +#include // size_tu +#include // uint16_t +#include // runtime_error +#include +#endif + +// Other includes. + +#ifdef __cpp_modules +export module butl.b; +#ifdef __cpp_lib_modules +import std.core; +#endif +import butl.url; +import butl.path; +import butl.process; +import butl.optional; +import butl.project_name; +import butl.standard_version; +#else +#include +#include +#include +#include +#include +#include +#endif + +#include + +LIBBUTL_MODEXPORT 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 the build2 + // project information it prints to stdout. Throw b_error on error. + // + // You can also specify the build2 verbosity level, command line callback + // (see process_run_callback() for details), build program search details + // and additional options. + // + 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; + 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; + }; + + using b_callback = void (const char* const args[], std::size_t n); + + LIBBUTL_SYMEXPORT b_project_info + b_info (const dir_path& project, + std::uint16_t verb = 1, + const std::function& cmd_callback = {}, + const path& program = path ("b"), + const dir_path& search_fallback = {}, + const std::vector& options = {}); +} -- cgit v1.1