aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-08-02 11:06:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-08-02 11:06:35 +0200
commit0c1ea060f7417ffc52cababd74278ea9d6047114 (patch)
tree4759bd1823c549381dd53efc5b5738ab2fd1ce42
parent8dd3964adbaccb1286d67d1b3ba63e47f545e65f (diff)
Add version_string, list of modules to b_info() result
Also only attempt to parse the string version to standard version if the version modules is loaded.
-rw-r--r--libbutl/b.cxx37
-rw-r--r--libbutl/b.mxx8
-rw-r--r--tests/b-info/driver.cxx12
-rw-r--r--tests/b-info/testscript2
4 files changed, 48 insertions, 11 deletions
diff --git a/libbutl/b.cxx b/libbutl/b.cxx
index e1caa4c..c55496c 100644
--- a/libbutl/b.cxx
+++ b/libbutl/b.cxx
@@ -20,6 +20,7 @@
#include <ios> // ios::failure
#include <utility> // move()
#include <sstream>
+#include <algorithm>
#endif
// Other includes.
@@ -156,16 +157,7 @@ namespace butl
}
else if (l.compare (0, 9, "version: ") == 0)
{
- string v (l, 9);
- if (!v.empty ())
- try
- {
- r.version = standard_version (v, standard_version::allow_stub);
- }
- catch (const invalid_argument& e)
- {
- bad_value ("version '" + v + "': " + e.what ());
- }
+ r.version_string = string (l, 9);
}
else if (l.compare (0, 9, "summary: ") == 0)
{
@@ -232,12 +224,37 @@ namespace butl
for (size_t b (0), e (0); next_word (v, b, e); )
r.meta_operations.push_back (string (v, b, e - b));
}
+ else if (l.compare (0, 9, "modules: ") == 0)
+ {
+ string v (l, 9);
+ for (size_t b (0), e (0); next_word (v, b, e); )
+ r.modules.push_back (string (v, b, e - b));
+ }
}
is.close (); // Detect errors.
if (pr.wait ())
+ {
+ // Parse version string to standard version if the project loaded
+ // the version module.
+ //
+ const auto& ms (r.modules);
+ if (find (ms.begin (), ms.end (), "version") != ms.end ())
+ {
+ try
+ {
+ r.version = standard_version (r.version_string,
+ standard_version::allow_stub);
+ }
+ catch (const invalid_argument& e)
+ {
+ bad_value ("version '" + r.version_string + "': " + e.what ());
+ }
+ }
+
return r;
+ }
}
// Note that ios::failure inherits from std::runtime_error, so this
// catch-clause must go last.
diff --git a/libbutl/b.mxx b/libbutl/b.mxx
index 9e12711..97dcf0c 100644
--- a/libbutl/b.mxx
+++ b/libbutl/b.mxx
@@ -73,9 +73,12 @@ LIBBUTL_MODEXPORT namespace butl
// 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
+ // (see process_run_callback() for details), build program search details,
// and additional options.
//
+ // Note that version_string is only parsed to standard_version if the
+ // project uses the version module. Otherwise, standard_version is empty.
+ //
struct b_project_info
{
using url_type = butl::url;
@@ -87,6 +90,7 @@ LIBBUTL_MODEXPORT namespace butl
};
project_name project;
+ std::string version_string;
standard_version version;
std::string summary;
url_type url;
@@ -100,6 +104,8 @@ LIBBUTL_MODEXPORT namespace butl
std::vector<std::string> operations;
std::vector<std::string> meta_operations;
+
+ std::vector<std::string> modules;
};
using b_callback = void (const char* const args[], std::size_t n);
diff --git a/tests/b-info/driver.cxx b/tests/b-info/driver.cxx
index 3ecfbc0..c5a2013 100644
--- a/tests/b-info/driver.cxx
+++ b/tests/b-info/driver.cxx
@@ -110,6 +110,18 @@ try
cout << *i;
}
+ cout << endl
+ << "modules: ";
+
+ for (auto b (pi.modules.begin ()), i (b);
+ i != pi.modules.end ();
+ ++i)
+ {
+ if (i != b)
+ cout << ' ';
+
+ cout << *i;
+ }
cout << endl;
return 0;
diff --git a/tests/b-info/testscript b/tests/b-info/testscript
index c5c3910..2ec5f4e 100644
--- a/tests/b-info/testscript
+++ b/tests/b-info/testscript
@@ -61,6 +61,7 @@ test.options += -b $recall($build.path)
subprojects: @subprj/
operations: update clean
meta-operations: perform configure disfigure dist info
+ modules: version config dist
EOO
$* prj/subprj >>/~"%EOO%"
@@ -74,6 +75,7 @@ test.options += -b $recall($build.path)
subprojects:$sp
operations: update clean
meta-operations: perform configure disfigure dist info
+ modules: config dist
EOO
}