From 3183f3bb927a90783ae0aeaf190a0919377aabe4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 21 Apr 2020 12:02:15 +0200 Subject: Add metadata --- cli/buildfile | 6 ++++++ cli/cli.cxx | 13 +++++++++++++ cli/options.cli | 2 ++ cli/options.cxx | 22 ++++++++++++++++------ cli/options.hxx | 10 ++++++++++ cli/options.ixx | 18 ++++++++++++++++++ cli/version.hxx.in | 2 ++ 7 files changed, 67 insertions(+), 6 deletions(-) (limited to 'cli') diff --git a/cli/buildfile b/cli/buildfile index 7d634e0..d6723d0 100644 --- a/cli/buildfile +++ b/cli/buildfile @@ -4,6 +4,12 @@ import libs = libcutl%lib{cutl} exe{cli}: cxx{cli} libue{cli} +{ + # Target metadata, see also --build2-metadata in cli.cxx. + # + cli.version = $version.project_id + cli.checksum = $version +} libue{cli}: {hxx ixx txx cxx}{** -cli -version -options} \ {hxx}{version} {hxx ixx cxx}{options} \ diff --git a/cli/cli.cxx b/cli/cli.cxx index 0c7f3a1..c57caee 100644 --- a/cli/cli.cxx +++ b/cli/cli.cxx @@ -32,6 +32,19 @@ main (int argc, char* argv[]) cli::argv_file_scanner scan (argc, argv, "--options-file"); options ops (scan); + // Handle --build2-metadata (see also buildfile). + // + if (ops.build2_metadata ()) + { + ostream& o (cout); + + o << "# build2 buildfile cli" << endl + << "cli.version = '" << CLI_VERSION_ID << '\'' << endl + << "cli.checksum = '" << CLI_CHECKSUM << '\'' << endl; + + return 0; + } + // Handle --version // if (ops.version ()) diff --git a/cli/options.cli b/cli/options.cli index 3f7b24d..e564bc4 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -15,6 +15,8 @@ include ; class options { + bool --build2-metadata; // Leave undocumented/hidden. + bool --help {"Print usage information and exit."}; bool --version {"Print version and exit."}; diff --git a/cli/options.cxx b/cli/options.cxx index 1e782e3..cc22a35 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -628,7 +628,8 @@ namespace cli options:: options () -: help_ (), +: build2_metadata_ (), + help_ (), version_ (), include_path_ (), include_path_specified_ (false), @@ -767,7 +768,8 @@ options (int& argc, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + help_ (), version_ (), include_path_ (), include_path_specified_ (false), @@ -909,7 +911,8 @@ options (int start, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + help_ (), version_ (), include_path_ (), include_path_specified_ (false), @@ -1051,7 +1054,8 @@ options (int& argc, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + help_ (), version_ (), include_path_ (), include_path_specified_ (false), @@ -1195,7 +1199,8 @@ options (int start, bool erase, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + help_ (), version_ (), include_path_ (), include_path_specified_ (false), @@ -1335,7 +1340,8 @@ options:: options (::cli::scanner& s, ::cli::unknown_mode opt, ::cli::unknown_mode arg) -: help_ (), +: build2_metadata_ (), + help_ (), version_ (), include_path_ (), include_path_specified_ (false), @@ -1477,6 +1483,8 @@ print_usage (::std::ostream& os, ::cli::usage_para p) if (p == ::cli::usage_para::text) os << ::std::endl; + os << "--build2-metadata" << std::endl; + os << "--help Print usage information and exit." << ::std::endl; os << "--version Print version and exit." << ::std::endl; @@ -1725,6 +1733,8 @@ struct _cli_options_map_init { _cli_options_map_init () { + _cli_options_map_["--build2-metadata"] = + &::cli::thunk< options, bool, &options::build2_metadata_ >; _cli_options_map_["--help"] = &::cli::thunk< options, bool, &options::help_ >; _cli_options_map_["--version"] = diff --git a/cli/options.hxx b/cli/options.hxx index 6533432..b253092 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -442,6 +442,15 @@ class options // Option accessors and modifiers. // const bool& + build2_metadata () const; + + bool& + build2_metadata (); + + void + build2_metadata (const bool&); + + const bool& help () const; bool& @@ -1480,6 +1489,7 @@ class options ::cli::unknown_mode argument); public: + bool build2_metadata_; bool help_; bool version_; std::vector include_path_; diff --git a/cli/options.ixx b/cli/options.ixx index 2b63fa8..12d40db 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -256,6 +256,24 @@ namespace cli // inline const bool& options:: +build2_metadata () const +{ + return this->build2_metadata_; +} + +inline bool& options:: +build2_metadata () +{ + return this->build2_metadata_; +} + +inline void options:: +build2_metadata(const bool& x) +{ + this->build2_metadata_ = x; +} + +inline const bool& options:: help () const { return this->help_; diff --git a/cli/version.hxx.in b/cli/version.hxx.in index 610315e..90b649a 100644 --- a/cli/version.hxx.in +++ b/cli/version.hxx.in @@ -36,6 +36,8 @@ #define CLI_SNAPSHOT $cli.version.snapshot_sn$ULL #define CLI_SNAPSHOT_ID "$cli.version.snapshot_id$" +#define CLI_CHECKSUM "$cli.version$" + #include $libcutl.check(LIBCUTL_VERSION, LIBCUTL_SNAPSHOT)$ -- cgit v1.1