aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/b-options.cxx14
-rw-r--r--build2/b-options.hxx8
-rw-r--r--build2/b-options.ixx12
-rw-r--r--build2/b.cli2
-rw-r--r--build2/b.cxx55
-rw-r--r--build2/buildfile11
-rw-r--r--libbuild2/version.hxx.in1
-rw-r--r--tests/build/root.build5
-rw-r--r--tests/dependency/recipe/testscript3
-rw-r--r--tests/recipe/cxx/testscript4
10 files changed, 100 insertions, 15 deletions
diff --git a/build2/b-options.cxx b/build2/b-options.cxx
index 4dadf99..ce322cc 100644
--- a/build2/b-options.cxx
+++ b/build2/b-options.cxx
@@ -674,7 +674,9 @@ namespace build2
options::
options ()
- : v_ (),
+ : build2_metadata_ (),
+ build2_metadata_specified_ (false),
+ v_ (),
V_ (),
quiet_ (),
silent_ (),
@@ -787,6 +789,13 @@ namespace build2
{
CLI_POTENTIALLY_UNUSED (a);
+ if (a.build2_metadata_specified_)
+ {
+ ::build2::cl::parser< uint64_t>::merge (
+ this->build2_metadata_, a.build2_metadata_);
+ this->build2_metadata_specified_ = true;
+ }
+
if (a.v_)
{
::build2::cl::parser< bool>::merge (
@@ -1202,6 +1211,9 @@ namespace build2
{
_cli_options_map_init ()
{
+ _cli_options_map_["--build2-metadata"] =
+ &::build2::cl::thunk< options, uint64_t, &options::build2_metadata_,
+ &options::build2_metadata_specified_ >;
_cli_options_map_["-v"] =
&::build2::cl::thunk< options, bool, &options::v_ >;
_cli_options_map_["-V"] =
diff --git a/build2/b-options.hxx b/build2/b-options.hxx
index 44777f7..c6f1f59 100644
--- a/build2/b-options.hxx
+++ b/build2/b-options.hxx
@@ -453,6 +453,12 @@ namespace build2
// Option accessors.
//
+ const uint64_t&
+ build2_metadata () const;
+
+ bool
+ build2_metadata_specified () const;
+
const bool&
v () const;
@@ -598,6 +604,8 @@ namespace build2
::build2::cl::unknown_mode argument);
public:
+ uint64_t build2_metadata_;
+ bool build2_metadata_specified_;
bool v_;
bool V_;
bool quiet_;
diff --git a/build2/b-options.ixx b/build2/b-options.ixx
index b8d7198..6444aa9 100644
--- a/build2/b-options.ixx
+++ b/build2/b-options.ixx
@@ -260,6 +260,18 @@ namespace build2
// options
//
+ inline const uint64_t& options::
+ build2_metadata () const
+ {
+ return this->build2_metadata_;
+ }
+
+ inline bool options::
+ build2_metadata_specified () const
+ {
+ return this->build2_metadata_specified_;
+ }
+
inline const bool& options::
v () const
{
diff --git a/build2/b.cli b/build2/b.cli
index 355e2d9..f65d14a 100644
--- a/build2/b.cli
+++ b/build2/b.cli
@@ -389,6 +389,8 @@ namespace build2
{
"\h#options|OPTIONS|"
+ uint64_t --build2-metadata; // Leave undocumented/hidden.
+
bool -v
{
"Print actual commands being executed. This options is equivalent to
diff --git a/build2/b.cxx b/build2/b.cxx
index bae40b6..930dbac 100644
--- a/build2/b.cxx
+++ b/build2/b.cxx
@@ -426,32 +426,61 @@ main (int argc, char* argv[])
fail << e;
}
- // Initialize the diagnostics state.
+ // Handle --build2-metadata (see also buildfile).
//
- init_diag (verbosity (),
- ops.silent (),
- (ops.progress () ? optional<bool> (true) :
- ops.no_progress () ? optional<bool> (false) : nullopt),
- ops.no_line (),
- ops.no_column (),
- fdterm (stderr_fd ()));
+#ifndef BUILD2_BOOTSTRAP
+ if (ops.build2_metadata_specified ())
+ {
+ auto& o (cout);
+
+ // Note that the export.metadata variable should be the first non-
+ // blank/comment line.
+ //
+ o << "# build2 buildfile b" << endl
+ << "export.metadata = 1 b" << endl
+ << "b.name = [string] b" << endl
+ << "b.version = [string] '" << LIBBUILD2_VERSION_FULL << '\'' << endl
+ << "b.checksum = [string] '" << LIBBUILD2_VERSION_FULL << '\'' << endl
+ << "b.static = [bool] " <<
+#ifdef LIBBUILD2_STATIC
+ "true"
+#else
+ "false"
+#endif
+ << endl;
+
+ return 0;
+ }
+#endif
// Handle --version.
//
if (ops.version ())
{
- cout << "build2 " << LIBBUILD2_VERSION_ID << endl
- << "libbutl " << LIBBUTL_VERSION_ID << endl
- << "host " << BUILD2_HOST_TRIPLET << endl;
+ auto& o (cout);
+
+ o << "build2 " << LIBBUILD2_VERSION_ID << endl
+ << "libbutl " << LIBBUTL_VERSION_ID << endl
+ << "host " << BUILD2_HOST_TRIPLET << endl;
#ifndef BUILD2_BOOTSTRAP
- cout << "Copyright (c) " << BUILD2_COPYRIGHT << "." << endl;
+ o << "Copyright (c) " << BUILD2_COPYRIGHT << "." << endl;
#endif
- cout << "This is free software released under the MIT license." << endl;
+ o << "This is free software released under the MIT license." << endl;
return 0;
}
+ // Initialize the diagnostics state.
+ //
+ init_diag (verbosity (),
+ ops.silent (),
+ (ops.progress () ? optional<bool> (true) :
+ ops.no_progress () ? optional<bool> (false) : nullopt),
+ ops.no_line (),
+ ops.no_column (),
+ fdterm (stderr_fd ()));
+
// Handle --help.
//
if (ops.help ())
diff --git a/build2/buildfile b/build2/buildfile
index 3be724c..4d62fb5 100644
--- a/build2/buildfile
+++ b/build2/buildfile
@@ -16,6 +16,17 @@ for m: bash bin c cc cxx in version
exe{b}: {hxx ixx txx cxx}{** -b-options} {hxx ixx cxx}{b-options} $libs
+# Target metadata, see also --build2-metadata in b.cxx.
+#
+exe{b}:
+{
+ export.metadata = 1 b
+ b.name = [string] b
+ b.version = $version
+ b.checksum = $version
+ b.static = ($bin.link_member(exe) == liba)
+}
+
# Build options.
#
# Pass our compiler target to be used as build2 host.
diff --git a/libbuild2/version.hxx.in b/libbuild2/version.hxx.in
index d221d03..a9db847 100644
--- a/libbuild2/version.hxx.in
+++ b/libbuild2/version.hxx.in
@@ -28,6 +28,7 @@
#define LIBBUILD2_VERSION $build2.version.project_number$ULL
#define LIBBUILD2_VERSION_STR "$build2.version.project$"
#define LIBBUILD2_VERSION_ID "$build2.version.project_id$"
+#define LIBBUILD2_VERSION_FULL "$build2.version$"
#define LIBBUILD2_VERSION_MAJOR $build2.version.major$
#define LIBBUILD2_VERSION_MINOR $build2.version.minor$
diff --git a/tests/build/root.build b/tests/build/root.build
index 4ac2957..e3f0f61 100644
--- a/tests/build/root.build
+++ b/tests/build/root.build
@@ -19,8 +19,11 @@ if ($cxx.class == 'msvc')
# path.
#
import.build2 = [null]
+import! [metadata] b = build2%exe{b}
+
+static = $($b:b.static) # True if testing statically-linked build system.
+shared = (!$static) # For '$shared || exit' idiom.
-import b = build2%exe{b}
testscript{*}: test = $b
# Specify the test target for cross-testing.
diff --git a/tests/dependency/recipe/testscript b/tests/dependency/recipe/testscript
index 5f9bdf1..bd33bcc 100644
--- a/tests/dependency/recipe/testscript
+++ b/tests/dependency/recipe/testscript
@@ -708,6 +708,8 @@ EOE
:
: Disable when cross-testing for the sake of simplicity.
:
+ #\
+ # @@ There is now metadata and name in exe{b}.
if ($test.target == $build.host)
{
$* <<EOI 2>>/~%EOE% != 0
@@ -724,6 +726,7 @@ EOE
info: or provide custom low-verbosity diagnostics with the 'diag' builtin
EOE
}
+ #\
: program
:
diff --git a/tests/recipe/cxx/testscript b/tests/recipe/cxx/testscript
index 3eb8015..6601c0a 100644
--- a/tests/recipe/cxx/testscript
+++ b/tests/recipe/cxx/testscript
@@ -1,6 +1,10 @@
# file : tests/recipe/cxx/testscript
# license : MIT; see accompanying LICENSE file
+# Ad hoc C++ recipes not supported in a statically-linked build system.
+#
++$shared || exit
+
+mkdir build
+cat <<EOI >=build/bootstrap.build
project = test