From 50e725ae23124a10d56a615fb8b0ae80d0d2b4d3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 16 Jun 2020 13:07:31 +0200 Subject: Add metadata for exe{b}, including whether it is statically-linked Use this information to omit ad hoc C++ recipe tests is testing statically- linked build system. --- build2/b-options.cxx | 14 ++++++++++++- build2/b-options.hxx | 8 ++++++++ build2/b-options.ixx | 12 ++++++++++++ build2/b.cli | 2 ++ build2/b.cxx | 55 +++++++++++++++++++++++++++++++++++++++------------- build2/buildfile | 11 +++++++++++ 6 files changed, 88 insertions(+), 14 deletions(-) (limited to 'build2') 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 (true) : - ops.no_progress () ? optional (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 (true) : + ops.no_progress () ? optional (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. -- cgit v1.1