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 --- tests/b-info/buildfile | 8 ++++ tests/b-info/driver.cxx | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/b-info/testscript | 83 ++++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 tests/b-info/buildfile create mode 100644 tests/b-info/driver.cxx create mode 100644 tests/b-info/testscript (limited to 'tests/b-info') diff --git a/tests/b-info/buildfile b/tests/b-info/buildfile new file mode 100644 index 0000000..6395d63 --- /dev/null +++ b/tests/b-info/buildfile @@ -0,0 +1,8 @@ +# file : tests/b-info/buildfile +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +import libs = libbutl%lib{butl} +libs += $stdmod_lib + +exe{driver}: {hxx cxx}{*} $libs testscript diff --git a/tests/b-info/driver.cxx b/tests/b-info/driver.cxx new file mode 100644 index 0000000..9432551 --- /dev/null +++ b/tests/b-info/driver.cxx @@ -0,0 +1,118 @@ +// file : tests/b-info/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#ifndef __cpp_lib_modules +#include +#include +#endif + +// Other includes. + +#ifdef __cpp_modules +#ifdef __cpp_lib_modules +import std.core; +import std.io; +#endif +import butl.b; +import butl.path; +import butl.utility; // operator<<(ostream,exception) +#else +#include +#include +#include +#endif + +using namespace std; +using namespace butl; + +// Usage: argv[0] [-b ] +// +// Print the build2 project information to stdout. +// +// -b the build program to be used to retrieve the project information +// +int +main (int argc, char* argv[]) +try +{ + path b ("b"); + dir_path project; + + for (int i (1); i != argc; ++i) + { + string a (argv[i]); + + if (a == "-b") + { + ++i; + + assert (i != argc); + b = path (argv[i]); + } + else + { + assert (project.empty ()); + project = dir_path (move (a)); + } + } + + assert (!project.empty ()); + + cout.exceptions (ios::failbit | ios::badbit); + + b_project_info pi (b_info (project, 1 /* verb */, {}, b)); + + cout << "project: " << pi.project << endl + << "version: " << pi.version << endl + << "summary: " << pi.summary << endl + << "url: " << pi.url << endl + << "src_root: " << pi.src_root.representation () << endl + << "out_root: " << pi.out_root.representation () << endl + << "amalgamation: " << pi.amalgamation.representation () << endl + << "subprojects: "; + + for (auto b (pi.subprojects.begin ()), i (b); + i != pi.subprojects.end (); + ++i) + { + if (i != b) + cout << ' '; + + cout << i->name << '@' << i->path.representation (); + } + cout << endl + << "operations: "; + + for (auto b (pi.operations.begin ()), i (b); i != pi.operations.end (); ++i) + { + if (i != b) + cout << ' '; + + cout << *i; + } + cout << endl + << "meta-operations: "; + + for (auto b (pi.meta_operations.begin ()), i (b); + i != pi.meta_operations.end (); + ++i) + { + if (i != b) + cout << ' '; + + cout << *i; + } + cout << endl; + + return 0; +} +catch (const b_error& e) +{ + if (!e.normal ()) + cerr << e << endl; + + return 1; +} diff --git a/tests/b-info/testscript b/tests/b-info/testscript new file mode 100644 index 0000000..9d1cfeb --- /dev/null +++ b/tests/b-info/testscript @@ -0,0 +1,83 @@ +# file : tests/b-info/testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Note that when cross-testing we unlikely be able to run build2 on the +# target platform. +# ++if ($test.target != $build.host) + exit +end + +sp = ' ' +test.options += -b $recall($build.path) + +: basic +: +{ + mkdir -p prj/build; + + cat <=prj/build/bootstrap.build; + project = prj + + using version + using config + using dist + EOI + + cat <=prj/buildfile; + ./: subprj/ + EOI + + cat <=prj/manifest; + : 1 + name: prj + version: 1.2.3-a.0.z + summary: test project + license: MIT + EOI + + mkdir -p prj/subprj/build; + + cat <=prj/subprj/build/bootstrap.build; + project = + + using config + using dist + EOI + + touch prj/subprj/buildfile; + + $* prj >>/~"%EOO%"; + project: prj + version: 1.2.3-a.0.z + summary: test project + url:$sp + %src_root: .+/prj/% + %out_root: .+/prj/% + amalgamation: ../../../../ + subprojects: @subprj/ + operations: update clean + meta-operations: perform configure disfigure dist info + EOO + + $* prj/subprj >>/~"%EOO%" + project:$sp + version:$sp + summary:$sp + url:$sp + %src_root: .+/subprj/% + %out_root: .+/subprj/% + amalgamation: ../ + subprojects:$sp + operations: update clean + meta-operations: perform configure disfigure dist info + EOO +} + +: error +: +$* prj 2>>/~%EOE% != 0 + %error: .+% + % info: .+%? + EOE -- cgit v1.1