From 8cc86445437e7afc583dee18b36c0e8ba4b6fe12 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 12 Dec 2022 18:35:08 +0300 Subject: Add support for omitting sub-projects from b_info() result --- libbutl/b.cxx | 27 ++++++++++++++++++--------- libbutl/b.hxx | 36 ++++++++++++++++++++++++++++-------- libbutl/b.ixx | 31 +++++++++++++++++++++++++++++++ libbutl/filesystem.ixx | 26 -------------------------- libbutl/path-pattern.ixx | 26 ++++++++++++++++++++++++++ tests/b-info/driver.cxx | 15 ++++++++------- 6 files changed, 111 insertions(+), 50 deletions(-) create mode 100644 libbutl/b.ixx diff --git a/libbutl/b.cxx b/libbutl/b.cxx index ee5c8a5..3d78803 100644 --- a/libbutl/b.cxx +++ b/libbutl/b.cxx @@ -35,7 +35,7 @@ namespace butl void b_info (std::vector& r, const vector& projects, - bool ext_mods, + b_info_flags fl, uint16_t verb, const function& cmd_callback, const path& program, @@ -81,13 +81,20 @@ namespace butl else vops.push_back ("-q"); - vector ps; - ps.reserve (projects.size ()); + string spec ("info("); - // Note that quoting is essential here. - // - for (const dir_path& p: projects) - ps.push_back ('\'' + p.representation () + '\''); + for (size_t i (0); i != projects.size(); ++i) + { + if (i != 0) + spec += ' '; + + spec += '\'' + projects[i].representation () + '\''; + } + + if ((fl & b_info_flags::subprojects) == b_info_flags::none) + spec += ",no_subprojects"; + + spec += ')'; pr = process_start_callback ( cmd_callback ? cmd_callback : [] (const char* const*, size_t) {}, @@ -96,10 +103,12 @@ namespace butl 2 /* stderr */, pp, vops, - ext_mods ? nullptr : "--no-external-modules", + ((fl & b_info_flags::ext_mods) == b_info_flags::none + ? "--no-external-modules" + : nullptr), "-s", ops, - "info:", ps); + spec); pipe.out.close (); ifdstream is (move (pipe.in), fdstream_mode::skip, ifdstream::badbit); diff --git a/libbutl/b.hxx b/libbutl/b.hxx index cc3a309..d3fd2bf 100644 --- a/libbutl/b.hxx +++ b/libbutl/b.hxx @@ -51,11 +51,6 @@ namespace butl // 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. @@ -92,12 +87,35 @@ namespace butl std::vector modules; }; + enum class b_info_flags: std::uint16_t + { + // Retrieve information that may come from external modules (operations, + // meta-operations, etc). Omitting this flag results in passing + // --no-external-modules to the build2 program and speeds up its + // execution. + // + ext_mods = 0x1, + + // Discover subprojects. Omitting this flag results in passing + // no_subprojects info meta-operation parameter to the build2 program and + // speeds up its execution. + // + subprojects = 0x2, + + none = 0 + }; + + inline b_info_flags operator& (b_info_flags, b_info_flags); + inline b_info_flags operator| (b_info_flags, b_info_flags); + inline b_info_flags operator&= (b_info_flags&, b_info_flags); + inline b_info_flags operator|= (b_info_flags&, b_info_flags); + 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, + b_info_flags, std::uint16_t verb = 1, const std::function& cmd_callback = {}, const path& program = path ("b"), @@ -108,7 +126,7 @@ namespace butl // inline b_project_info b_info (const dir_path& project, - bool ext_mods, + b_info_flags fl, std::uint16_t verb = 1, const std::function& cmd_callback = {}, const path& program = path ("b"), @@ -118,7 +136,7 @@ namespace butl std::vector r; b_info (r, std::vector ({project}), - ext_mods, + fl, verb, cmd_callback, program, @@ -128,3 +146,5 @@ namespace butl return std::move (r[0]); } } + +#include diff --git a/libbutl/b.ixx b/libbutl/b.ixx new file mode 100644 index 0000000..1667101 --- /dev/null +++ b/libbutl/b.ixx @@ -0,0 +1,31 @@ +// file : libbutl/b.ixx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +namespace butl +{ + // b_info_flags + // + inline b_info_flags operator& (b_info_flags x, b_info_flags y) + { + return x &= y; + } + + inline b_info_flags operator| (b_info_flags x, b_info_flags y) + { + return x |= y; + } + + inline b_info_flags operator&= (b_info_flags& x, b_info_flags y) + { + return x = static_cast ( + static_cast (x) & + static_cast (y)); + } + + inline b_info_flags operator|= (b_info_flags& x, b_info_flags y) + { + return x = static_cast ( + static_cast (x) | + static_cast (y)); + } +} diff --git a/libbutl/filesystem.ixx b/libbutl/filesystem.ixx index 193eae9..79607d7 100644 --- a/libbutl/filesystem.ixx +++ b/libbutl/filesystem.ixx @@ -137,32 +137,6 @@ namespace butl static_cast (y)); } - // path_match_flags - // - inline path_match_flags operator& (path_match_flags x, path_match_flags y) - { - return x &= y; - } - - inline path_match_flags operator| (path_match_flags x, path_match_flags y) - { - return x |= y; - } - - inline path_match_flags operator&= (path_match_flags& x, path_match_flags y) - { - return x = static_cast ( - static_cast (x) & - static_cast (y)); - } - - inline path_match_flags operator|= (path_match_flags& x, path_match_flags y) - { - return x = static_cast ( - static_cast (x) | - static_cast (y)); - } - // dir_entry // inline entry_type dir_entry:: diff --git a/libbutl/path-pattern.ixx b/libbutl/path-pattern.ixx index 71f125c..6fee31e 100644 --- a/libbutl/path-pattern.ixx +++ b/libbutl/path-pattern.ixx @@ -3,6 +3,32 @@ namespace butl { + // path_match_flags + // + inline path_match_flags operator& (path_match_flags x, path_match_flags y) + { + return x &= y; + } + + inline path_match_flags operator| (path_match_flags x, path_match_flags y) + { + return x |= y; + } + + inline path_match_flags operator&= (path_match_flags& x, path_match_flags y) + { + return x = static_cast ( + static_cast (x) & + static_cast (y)); + } + + inline path_match_flags operator|= (path_match_flags& x, path_match_flags y) + { + return x = static_cast ( + static_cast (x) | + static_cast (y)); + } + // path_pattern_iterator // inline path_pattern_iterator:: diff --git a/tests/b-info/driver.cxx b/tests/b-info/driver.cxx index 6832aaa..5691221 100644 --- a/tests/b-info/driver.cxx +++ b/tests/b-info/driver.cxx @@ -49,13 +49,14 @@ try cout.exceptions (ios::failbit | ios::badbit); - b_project_info pi (b_info (project, - true /* ext_mods */, - 1 /* verb */, - {} /* cmd_callback */, - b, - {} /* search_fallback */, - {"--no-default-options"})); + b_project_info pi ( + b_info (project, + b_info_flags::ext_mods | b_info_flags::subprojects, + 1 /* verb */, + {} /* cmd_callback */, + b, + {} /* search_fallback */, + {"--no-default-options"})); cout << "project: " << pi.project << endl << "version: " << pi.version << endl -- cgit v1.1