From 1ca3ce471906f08d23f9163cdb8da884175ed331 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 11 Jun 2020 11:36:07 +0300 Subject: Add metadata --- odb/buildfile | 10 ++++++++++ odb/odb.cxx | 36 +++++++++++++++++++++++++++++------- odb/options.cli | 3 +++ odb/options.cxx | 36 ++++++++++++++++++++++++++++++------ odb/options.hxx | 19 +++++++++++++++++++ odb/options.ixx | 30 ++++++++++++++++++++++++++++++ odb/version.hxx | 3 +++ 7 files changed, 124 insertions(+), 13 deletions(-) diff --git a/odb/buildfile b/odb/buildfile index 8c8d458..8e931ad 100644 --- a/odb/buildfile +++ b/odb/buildfile @@ -65,6 +65,16 @@ exe{odb}: cxx{odb} exe{odb}: libus{odb}: bin.whole = false exe{odb}: plugin{odb}: include = adhoc +# Target metadata, see also --build2-metadata in odb.cxx. +# +exe{odb}: +{ + export.metadata = 1 odb + odb.name = [string] odb + odb.version = $version + odb.checksum = $version +} + plugin{odb}: libus{odb} switch $cxx.target.system diff --git a/odb/odb.cxx b/odb/odb.cxx index 5381668..225cc21 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -592,20 +592,40 @@ main (int argc, char* argv[]) cli::argv_file_scanner scan (ac, &av[0], oi, 3); options ops (scan); + // Handle --build2-metadata (see also buildfile). + // + if (ops.build2_metadata_specified ()) + { + ostream& o (cout); + + // Note that the export.metadata variable should be the first non- + // blank/comment line. + // + o << "# build2 buildfile odb" << endl + << "export.metadata = 1 odb" << endl + << "odb.name = [string] odb" << endl + << "odb.version = [string] '" << ODB_COMPILER_VERSION_STR << '\'' << endl + << "odb.checksum = [string] '" << ODB_COMPILER_VERSION_STR << '\'' << endl; + + return 0; + } + // Handle --version. // if (ops.version ()) { - cout << "ODB object-relational mapping (ORM) compiler for C++ " + ostream& o (cout); + + o << "ODB object-relational mapping (ORM) compiler for C++ " ODB_COMPILER_VERSION_STR << endl; #ifdef ODB_BUILD2 - cout << "Copyright (c) " << ODB_COPYRIGHT << "." << endl; + o << "Copyright (c) " << ODB_COPYRIGHT << "." << endl; #endif - cout << "This is free software; see the source for copying " - << "conditions. There is NO\nwarranty; not even for " - << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." << endl; + o << "This is free software; see the source for copying conditions. " + << "There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS " + << "FOR A PARTICULAR PURPOSE." << endl; return 0; } @@ -614,8 +634,10 @@ main (int argc, char* argv[]) // if (ops.help ()) { - cout << "Usage: " << argv[0] << " [options] file [file ...]" << endl - << "Options:" << endl; + ostream& o (cout); + + o << "Usage: " << argv[0] << " [options] file [file ...]" << endl + << "Options:" << endl; options::print_usage (cout); return 0; diff --git a/odb/options.cli b/odb/options.cli index e202159..bb8797b 100644 --- a/odb/options.cli +++ b/odb/options.cli @@ -5,6 +5,7 @@ include ; include ; include ; include ; +include ; include ; @@ -14,6 +15,8 @@ class options // Wrapper options. These are not passed to the plugin. // + std::uint64_t --build2-metadata; // Leave undocumented/hidden. + bool --help {"Print usage information and exit."}; bool --version {"Print version and exit."}; diff --git a/odb/options.cxx b/odb/options.cxx index 875ab7e..ec6cd7f 100644 --- a/odb/options.cxx +++ b/odb/options.cxx @@ -642,7 +642,9 @@ namespace cli options:: options () -: help_ (), +: build2_metadata_ (), + build2_metadata_specified_ (false), + help_ (), version_ (), I_ (), I_specified_ (false), @@ -853,7 +855,9 @@ options (int& argc, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + build2_metadata_specified_ (false), + help_ (), version_ (), I_ (), I_specified_ (false), @@ -1067,7 +1071,9 @@ options (int start, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + build2_metadata_specified_ (false), + help_ (), version_ (), I_ (), I_specified_ (false), @@ -1281,7 +1287,9 @@ options (int& argc, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + build2_metadata_specified_ (false), + help_ (), version_ (), I_ (), I_specified_ (false), @@ -1497,7 +1505,9 @@ options (int start, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + build2_metadata_specified_ (false), + help_ (), version_ (), I_ (), I_specified_ (false), @@ -1709,7 +1719,9 @@ options:: options (::cli::scanner& s, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + build2_metadata_specified_ (false), + help_ (), version_ (), I_ (), I_specified_ (false), @@ -2297,6 +2309,15 @@ static _cli_options_desc_type _cli_options_desc_; void options:: fill (::cli::options& os) { + // --build2-metadata + // + { + ::cli::option_names a; + std::string dv; + ::cli::option o ("--build2-metadata", a, false, dv); + os.push_back (o); + } + // --help // { @@ -3356,6 +3377,9 @@ struct _cli_options_map_init { _cli_options_map_init () { + _cli_options_map_["--build2-metadata"] = + &::cli::thunk< options, std::uint64_t, &options::build2_metadata_, + &options::build2_metadata_specified_ >; _cli_options_map_["--help"] = &::cli::thunk< options, bool, &options::help_ >; _cli_options_map_["--version"] = diff --git a/odb/options.hxx b/odb/options.hxx index 241c8a9..dce0fe0 100644 --- a/odb/options.hxx +++ b/odb/options.hxx @@ -448,6 +448,8 @@ namespace cli #include +#include + #include class options @@ -489,6 +491,21 @@ class options // Option accessors and modifiers. // + const std::uint64_t& + build2_metadata () const; + + std::uint64_t& + build2_metadata (); + + void + build2_metadata (const std::uint64_t&); + + bool + build2_metadata_specified () const; + + void + build2_metadata_specified (bool); + const bool& help () const; @@ -2075,6 +2092,8 @@ class options ::cli::unknown_mode argument); public: + std::uint64_t build2_metadata_; + bool build2_metadata_specified_; bool help_; bool version_; std::vector I_; diff --git a/odb/options.ixx b/odb/options.ixx index e0317cb..87e81bc 100644 --- a/odb/options.ixx +++ b/odb/options.ixx @@ -300,6 +300,36 @@ namespace cli // options // +inline const std::uint64_t& options:: +build2_metadata () const +{ + return this->build2_metadata_; +} + +inline std::uint64_t& options:: +build2_metadata () +{ + return this->build2_metadata_; +} + +inline void options:: +build2_metadata(const std::uint64_t& x) +{ + this->build2_metadata_ = x; +} + +inline bool options:: +build2_metadata_specified () const +{ + return this->build2_metadata_specified_; +} + +inline void options:: +build2_metadata_specified(bool x) +{ + this->build2_metadata_specified_ = x; +} + inline const bool& options:: help () const { diff --git a/odb/version.hxx b/odb/version.hxx index 8b4e379..9ed715f 100644 --- a/odb/version.hxx +++ b/odb/version.hxx @@ -28,6 +28,9 @@ // ODB compiler version: interface version plus the bugfix version. // +// NOTE: remember to update metadata to full version when switching to +// version.hxx.in. +// #define ODB_COMPILER_VERSION 2049968 #define ODB_COMPILER_VERSION_STR "2.5.0-b.18" -- cgit v1.1