Add --version option to several libabigail tools
authorDodji Seketeli <dodji@redhat.com>
Mon, 16 Nov 2015 10:39:15 +0000 (11:39 +0100)
committerDodji Seketeli <dodji@redhat.com>
Mon, 16 Nov 2015 11:54:10 +0000 (12:54 +0100)
This patch changed the revision number of the libabigail library to
make it reflect the fact that we are not in "release candidate" mode,
before the first 1.0 release.  So the revision number is now "rc0".

The configuration manager has been updated to support version numbers
that are strings, so that it can supports things like "rc0".

Then, several libabigail tools have been modified to support the
--version option to display their version number.

* configure.ac: Set the version revision to "rc0".
* doc/manuals/abicompat.rst: Adjust manual for new --version
option.
* doc/manuals/abidiff.rst: Likewise.
* doc/manuals/abidw.rst: Likewise.
* doc/manuals/abilint.rst: Likewise.
* doc/manuals/abipkgdiff.rst: Likewise.
* include/abg-config.h (config::{m_format_minor, m_format_major}):
Make these be strings.
(config::{get,set}_format_minor_version_number): Make these return
strings.
(config::{get,set}_format_major_version_number): Make these return
or take strings.
(abigail_get_library_version): Make this take strings.
* src/abg-config.cc (config::config): Adjust.
(config::{get,set}_format_major_version_number): Make these return
or take strings.
(config::{get,set}_format_minor_version_number): Make these return
strings.
(abigail_get_library_version): Make this take strings.
* include/abg-version.h.in: Make the version variables be strings.
* src/abg-writer.cc (write_translation_unit): The version numbers
are now strings so adjust.
* tools/{abicompat,abidiff,abidw,abilint,abipkgdiff,abisym}.cc
(options::display_version): New data member.
(options::options): Initialize it.
(display_usage): Add documentation for new --version option.
(parse_command_line): Parse new --version option.
(main): Support --version.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
16 files changed:
configure.ac
doc/manuals/abicompat.rst
doc/manuals/abidiff.rst
doc/manuals/abidw.rst
doc/manuals/abilint.rst
doc/manuals/abipkgdiff.rst
include/abg-config.h
include/abg-version.h.in
src/abg-config.cc
src/abg-writer.cc
tools/abicompat.cc
tools/abidiff.cc
tools/abidw.cc
tools/abilint.cc
tools/abipkgdiff.cc
tools/abisym.cc

index 236c6ebb03ba070a1be8425e84e5b2b92d0985d4..bb81ffd056c5ff10f5b2a0b4cac3841e42b94a73 100644 (file)
@@ -1,6 +1,6 @@
 m4_define([version_major],   [1])
 m4_define([version_minor],   [0])
-m4_define([version_revision],[0])
+m4_define([version_revision],[rc0])
 
 AC_INIT([libabigail],
        [version_major.version_minor.version_revision],
index 547c648b4926dd9a8863765b1ad2833335569c9f..377b72b523b23d24e08232509263035914ba0db8 100644 (file)
@@ -28,6 +28,10 @@ Options
 
     Display a short help about the command and exit.
 
+  * `--version | -v`
+
+    Display the version of the program and exit.
+
   * ``--list-undefined-symbols | -u``
 
     Display the list of undefined symbols of the application and exit.
index 99f5fa9d5b6d76f624e02b3f6885b89789ec6e15..f6924f6a5faf7d56f666d747653693347d305225 100644 (file)
@@ -32,6 +32,10 @@ Options
 
     Display a short help about the command and exit.
 
+  * `--version | -v`
+
+    Display the version of the program and exit.
+
   * ``--debug-info-dir1 | --d1`` <*di-path1*>
 
     For cases where the debug information for *first-shared-library*
index 9a6183545305ab70b16f81fc81104c08a14c70ef..80d7a0f27db088dda12c7a2611c714193937003c 100644 (file)
@@ -24,6 +24,10 @@ Options
 
     Display a short help about the command and exit.
 
+  * `--version | -v`
+
+    Display the version of the program and exit.
+
   * ``--debug-info-dir | -d`` <*dir-path*>
 
     In cases where the debug info for *path-to-elf-file* is in a
index 1e4b99e8c5ce7a635caaf4929c358927e5120c71..ca89eb0100b4e2f860eaf6890b8ac3fe1253f27b 100644 (file)
@@ -31,6 +31,10 @@ Options
 
     Display a short help message and exits.
 
+  * `--version | -v`
+
+    Display the version of the program and exit.
+
   * ``--debug-info-dir`` <*path*>
 
     When reading an `ELF`_ input file which debug information is split
index fca74ad08cadcbe241c5ceee42150f52f8c645d1..b2a536478a544fac712a380c0cefc88abff0aeef 100644 (file)
@@ -40,6 +40,10 @@ Options
 
     Display a short help about the command and exit.
 
+  * `--version | -v`
+
+    Display the version of the program and exit.
+
   * ``--debug-info-pkg1 | --d1`` <path>
 
     For cases where the debug information for *package1* is split out
index e20430ec8e5e64f482a1f5af443d2be44abd96fa..1d92c51231dc6c93b8586ca5c89195ade3a7ea5d 100644 (file)
@@ -31,26 +31,26 @@ namespace abigail
 /// This type abstracts the configuration information of the library.
 class config
 {
-  unsigned char        m_format_minor;
-  unsigned char        m_format_major;
-  unsigned             m_xml_element_indent;
-  std::string          m_tu_instr_suffix;
-  std::string          m_tu_instr_archive_suffix;
+  std::string  m_format_minor;
+  std::string  m_format_major;
+  unsigned     m_xml_element_indent;
+  std::string  m_tu_instr_suffix;
+  std::string  m_tu_instr_archive_suffix;
 
 public:
   config();
 
-  unsigned char
+  const std::string&
   get_format_minor_version_number() const;
 
   void
-  set_format_minor_version_number(unsigned char);
+  set_format_minor_version_number(const std::string& v);
 
-  unsigned char
+  const std::string&
   get_format_major_version_number() const;
 
   void
-  set_format_major_version_number(unsigned char);
+  set_format_major_version_number(const std::string& v);
 
   unsigned
   get_xml_element_indent() const;
@@ -81,7 +81,9 @@ extern "C"
   ///
   /// \param rev the revision version number of the library.
   void
-  abigail_get_library_version(int& maj, int& min, int& rev);
+  abigail_get_library_version(std::string& maj,
+                             std::string& min,
+                             std::string& rev);
 }
 
 }//end namespace abigail
index 07f322d0fa4fd354a0172b99d28ba5c34a4b1677..68c8d84d5ee57f7367682634654e527232e36ce0 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef __ABG_VERSION_H__
 #define __ABG_VERSION_H__
-#define ABIGAIL_VERSION_MAJOR @VERSION_MAJOR@
-#define ABIGAIL_VERSION_MINOR @VERSION_MINOR@
-#define ABIGAIL_VERSION_REVISION @VERSION_REVISION@
+#define ABIGAIL_VERSION_MAJOR "@VERSION_MAJOR@"
+#define ABIGAIL_VERSION_MINOR "@VERSION_MINOR@"
+#define ABIGAIL_VERSION_REVISION "@VERSION_REVISION@"
 #endif
index 1881a21d0933f4d7f0436078bc40fd0c9b658fb6..8b1f7eb23e58410df2e62e7795151ea70a1ccd17 100644 (file)
 namespace abigail
 {
 config::config()
-: m_format_minor(0), m_format_major(1),
-  m_xml_element_indent(2),
-  m_tu_instr_suffix(".bi"),
-  m_tu_instr_archive_suffix (".abi")
-{ }
+  : m_format_minor("0"),
+    m_format_major("1"),
+    m_xml_element_indent(2)
+{
+  m_tu_instr_suffix = ".bi" ;
+  m_tu_instr_archive_suffix = ".abi";
+}
 
-unsigned char
+const std::string&
 config::get_format_minor_version_number() const
-{ return m_format_minor; }
+{return m_format_minor;}
 
 void
-config::set_format_minor_version_number(unsigned char v)
-{ m_format_minor = v; }
+config::set_format_minor_version_number(const std::string& v)
+{m_format_minor = v;}
 
-unsigned char
+const std::string&
 config::get_format_major_version_number() const
-{ return m_format_major; }
+{return m_format_major;}
 
 void
-config::set_format_major_version_number(unsigned char v)
-{ m_format_major= v; }
+config::set_format_major_version_number(const std::string& v)
+{m_format_major= v;}
 
 unsigned
 config::get_xml_element_indent() const
@@ -55,28 +57,30 @@ config::get_xml_element_indent() const
 
 void
 config::set_xml_element_indent(unsigned indent)
-{ m_xml_element_indent = indent; }
+{m_xml_element_indent = indent;}
 
 const std::string&
 config::get_tu_instr_suffix() const
-{ return m_tu_instr_suffix; }
+{return m_tu_instr_suffix;}
 
 void
 config::set_tu_instr_suffix(const std::string& s)
-{ m_tu_instr_suffix = s; }
+{m_tu_instr_suffix = s;}
 
 const std::string&
 config::get_tu_instr_archive_suffix() const
-{ return m_tu_instr_archive_suffix; }
+{return m_tu_instr_archive_suffix;}
 
 void
 config::set_tu_instr_archive_suffix(const std::string& s)
-{ m_tu_instr_archive_suffix = s; }
+{m_tu_instr_archive_suffix = s; }
 
 extern "C"
 {
 void
-abigail_get_library_version(int& major, int& minor, int& revision)
+abigail_get_library_version(std::string& major,
+                           std::string& minor,
+                           std::string& revision)
 {
   major = ABIGAIL_VERSION_MAJOR;
   minor = ABIGAIL_VERSION_MINOR;
index aebe145e9da7296618809d22f2bc0ae57b95f64c..8d64ce583a2ee8d8f28f15484bd054cdd3872b6e 100644 (file)
@@ -1203,8 +1203,8 @@ write_translation_unit(const translation_unit&    tu,
   do_indent(o, indent);
 
   o << "<abi-instr version='"
-    << static_cast<int> (c.get_format_major_version_number())
-    << "." << static_cast<int>(c.get_format_minor_version_number())
+    << c.get_format_major_version_number()
+    << "." << c.get_format_minor_version_number()
     << "'";
 
   if (tu.get_address_size() != 0)
index 09b0bff2db15f08bea81b2f95ffa3bba6c41d59c..f3bb949f01bb0eeb6c81d911211840da69cea0f2 100644 (file)
@@ -49,6 +49,7 @@
 #include <iostream>
 #include <fstream>
 #include <tr1/memory>
+#include "abg-config.h"
 #include "abg-tools-utils.h"
 #include "abg-corpus.h"
 #include "abg-dwarf-reader.h"
@@ -73,6 +74,7 @@ struct options
   shared_ptr<char>     lib2_di_root_path;
   vector<string>       suppression_paths;
   bool                 display_help;
+  bool                 display_version;
   bool                 weak_mode;
   bool                 list_undefined_symbols_only;
   bool                 show_base_names;
@@ -80,6 +82,7 @@ struct options
 
   options()
     :display_help(),
+     display_version(),
      weak_mode(),
      list_undefined_symbols_only(),
      show_base_names(),
@@ -95,6 +98,7 @@ display_usage(const string& prog_name, ostream& out)
       << "\n"
       << " where options can be: \n"
       << "  --help|-h  display this help message\n"
+      << "  --version|-v  show program version information and exit\n"
       << "  --list-undefined-symbols|-u  display the list of "
          "undefined symbols of the application\n"
       << "  --show-base-names|b  in the report, only show the base names "
@@ -132,6 +136,12 @@ parse_command_line(int argc, char* argv[], options& opts)
          else
            return false;
        }
+      else if (!strcmp(argv[i], "--version")
+              || !strcmp(argv[i], "-v"))
+       {
+         opts.display_version = true;
+         return true;
+       }
       else if (!strcmp(argv[i], "--list-undefined-symbols")
               || !strcmp(argv[i], "-u"))
        opts.list_undefined_symbols_only = true;
@@ -593,6 +603,14 @@ main(int argc, char* argv[])
                  | abigail::tools_utils::ABIDIFF_ERROR);
     }
 
+  if (opts.display_version)
+    {
+      string major, minor, revision;
+      abigail::abigail_get_library_version(major, minor, revision);
+      cout << major << "." << minor << "." << revision << "\n";
+      return 0;
+    }
+
   assert(!opts.app_path.empty());
   if (!abigail::tools_utils::check_file(opts.app_path, cerr))
     return abigail::tools_utils::ABIDIFF_ERROR;
index 5aa8ff9e2b644b36e9523bfacbf17a2ae999d115..b63357b008b7acfac5d6e5235794f202d5bfdcbc 100644 (file)
@@ -26,6 +26,7 @@
 #include <vector>
 #include <string>
 #include <iostream>
+#include "abg-config.h"
 #include "abg-comp-filter.h"
 #include "abg-tools-utils.h"
 #include "abg-reader.h"
@@ -57,6 +58,7 @@ using abigail::tools_utils::abidiff_status;
 struct options
 {
   bool display_usage;
+  bool display_version;
   bool missing_operand;
   string               file1;
   string               file2;
@@ -88,6 +90,7 @@ struct options
 
   options()
     : display_usage(),
+      display_version(),
       missing_operand(),
       no_arch(),
       show_stats_only(),
@@ -115,6 +118,7 @@ display_usage(const string& prog_name, ostream& out)
 {
   out << "usage: " << prog_name << " [options] [<file1> <file2>]\n"
       << " where options can be:\n"
+      << " --version|-v  display program version information and exit\n"
       << " --debug-info-dir1|--d1 <path> the root for the debug info of file1\n"
       << " --debug-info-dir2|--d2 <path> the root for the debug info of file2\n"
       << " --help|-h  display this message\n "
@@ -177,6 +181,12 @@ parse_command_line(int argc, char* argv[], options& opts)
          else
            return false;
        }
+      else if (!strcmp(argv[i], "--version")
+              || !strcmp(argv[i], "-v"))
+       {
+         opts.display_version = true;
+         return true;
+       }
       else if (!strcmp(argv[i], "--debug-info-dir1")
               || !strcmp(argv[i], "--d1"))
        {
@@ -501,6 +511,14 @@ main(int argc, char* argv[])
              | abigail::tools_utils::ABIDIFF_ERROR);
     }
 
+  if (opts.display_version)
+    {
+      string major, minor, revision;
+      abigail::abigail_get_library_version(major, minor, revision);
+      cout << major << "." << minor << "." << revision << "\n";
+      return 0;
+    }
+
   abidiff_status status = abigail::tools_utils::ABIDIFF_OK;
   if (!opts.file1.empty() && !opts.file2.empty())
     {
index 190d5f9a30c39b6174c7f7ce2fc50d96e6688e06..d42356a2e767387f4c9cae91a56ef8aad4b7886c 100644 (file)
@@ -35,6 +35,7 @@
 #include <iostream>
 #include <fstream>
 #include <tr1/memory>
+#include "abg-config.h"
 #include "abg-tools-utils.h"
 #include "abg-corpus.h"
 #include "abg-dwarf-reader.h"
@@ -63,6 +64,7 @@ struct options
   string               in_file_path;
   string               out_file_path;
   shared_ptr<char>     di_root_path;
+  bool                 display_version;
   bool                 check_alt_debug_info_path;
   bool                 show_base_name_alt_debug_info_path;
   bool                 write_architecture;
@@ -72,7 +74,8 @@ struct options
   bool                 abidiff;
 
   options()
-    : check_alt_debug_info_path(),
+    : display_version(),
+      check_alt_debug_info_path(),
       show_base_name_alt_debug_info_path(),
       write_architecture(true),
       load_all_types(),
@@ -87,18 +90,19 @@ display_usage(const string& prog_name, ostream& out)
 {
   out << "usage: " << prog_name << " [options] [<path-to-elf-file>]\n"
       << " where options can be: \n"
-      << "  --help|-h display this message\n"
-      << "  --debug-info-dir|-d <dir-path> look for debug info under 'dir-path'\n"
-      << "  --out-file <file-path> write the output to 'file-path'\n"
-      << "  --noout do not emit anything after reading the binary\n"
-      << "  --no-architecture do not emit architecture info in the output\n"
-      << "  --check-alternate-debug-info <elf-path> check alternate debug info "
+      << "  --help|-h  display this message\n"
+      << "  --version|-v  display program version information and exit\n"
+      << "  --debug-info-dir|-d <dir-path>  look for debug info under 'dir-path'\n"
+      << "  --out-file <file-path>  write the output to 'file-path'\n"
+      << "  --noout  do not emit anything after reading the binary\n"
+      << "  --no-architecture  do not emit architecture info in the output\n"
+      << "  --check-alternate-debug-info <elf-path>  check alternate debug info "
                "of <elf-path>\n"
-      << "  --check-alternate-debug-info-base-name <elf-path> check alternate "
+      << "  --check-alternate-debug-info-base-name <elf-path>  check alternate "
     "debug info of <elf-path>, and show its base name\n"
-      << "  --load-all-types read all types including those not reachable from"
+      << "  --load-all-types  read all types including those not reachable from"
          "exported declarations\n"
-      << "  --abidiff compare the loaded ABI against itself\n"
+      << "  --abidiff  compare the loaded ABI against itself\n"
       << "  --stats  show statistics about various internal stuff\n";
     ;
 }
@@ -118,6 +122,12 @@ parse_command_line(int argc, char* argv[], options& opts)
          else
            return false;
        }
+      else if (!strcmp(argv[i], "--version")
+              || !strcmp(argv[i], "-v"))
+       {
+         opts.display_version = true;
+         return true;
+       }
       else if (!strcmp(argv[i], "--debug-info-dir")
               || !strcmp(argv[i], "-d"))
        {
@@ -202,6 +212,14 @@ main(int argc, char* argv[])
       return 1;
     }
 
+  if (opts.display_version)
+    {
+      string major, minor, revision;
+      abigail::abigail_get_library_version(major, minor, revision);
+      cout << major << "." << minor << "." << revision << "\n";
+      return 0;
+    }
+
   assert(!opts.in_file_path.empty());
   if (!abigail::tools_utils::check_file(opts.in_file_path, cerr))
     return 1;
index 05a9a38b6505ef2fde094be1013717bf4d641f41..9c56b6a83365770354a2924f1c7fbd94868d395f 100644 (file)
@@ -34,6 +34,7 @@
 #include <string>
 #include <iostream>
 #include <fstream>
+#include "abg-config.h"
 #include "abg-tools-utils.h"
 #include "abg-ir.h"
 #include "abg-corpus.h"
@@ -65,6 +66,7 @@ using abigail::xml_writer::write_corpus_to_archive;
 struct options
 {
   string                       file_path;
+  bool                         display_version;
   bool                         read_from_stdin;
   bool                         read_tu;
   bool                         diff;
@@ -72,7 +74,8 @@ struct options
   std::tr1::shared_ptr<char>   di_root_path;
 
   options()
-    : read_from_stdin(false),
+    : display_version(false),
+      read_from_stdin(false),
       read_tu(false),
       diff(false),
       noout(false)
@@ -85,6 +88,7 @@ display_usage(const string& prog_name, ostream& out)
   out << "usage: " << prog_name << " [options] [<abi-file1>]\n"
       << " where options can be:\n"
       << "  --help  display this message\n"
+      << "  --version|-v  display program version information and exit\n"
       << "  --debug-info-dir <path> the path under which to look for "
            "debug info for the elf <abi-file>\n"
       << "  --diff  for xml inputs, perform a text diff between "
@@ -114,6 +118,12 @@ parse_command_line(int argc, char* argv[], options& opts)
          }
        else if (!strcmp(argv[i], "--help"))
          return false;
+       else if (!strcmp(argv[i], "--version")
+                || !strcmp(argv[i], "-v"))
+         {
+           opts.display_version = true;
+           return true;
+         }
        else if (!strcmp(argv[i], "--debug-info-dir"))
          {
            if (argc <= i + 1
@@ -154,6 +164,13 @@ main(int argc, char* argv[])
       return true;
     }
 
+  if (opts.display_version)
+    {
+      string major, minor, revision;
+      abigail::abigail_get_library_version(major, minor, revision);
+      cout << major << "." << minor << "." << revision << "\n";
+      return 0;
+    }
   abigail::ir::environment_sptr env(new abigail::ir::environment);
   if (opts.read_from_stdin)
     {
index b618efe599464a43e0e76e9722b6792260b826fa..3a94223d222871efc6b4bf5c294222a798eb2fef 100644 (file)
@@ -74,6 +74,7 @@
 #include <elfutils/libdw.h>
 #include <unistd.h>
 #include <pthread.h>
+#include "abg-config.h"
 #include "abg-tools-utils.h"
 #include "abg-comparison.h"
 #include "abg-dwarf-reader.h"
@@ -137,6 +138,7 @@ static struct options *prog_options;
 struct options
 {
   bool         display_usage;
+  bool         display_version;
   bool         missing_operand;
   bool         abignore;
   bool         parallel;
@@ -155,6 +157,7 @@ struct options
 
   options()
     : display_usage(),
+      display_version(),
       missing_operand(),
       abignore(true),
       parallel(true),
@@ -495,7 +498,9 @@ display_usage(const string& prog_name, ostream& out)
       << " --no-parallel                  do not execute in parallel\n"
       << " --fail-no-dbg                  fail if no debug info was found\n"
       << " --verbose                      emit verbose progress messages\n"
-      << " --help|-h                      display this help message\n";
+      << " --help|-h                      display this help message\n"
+      << " --version|-v                   display program version information"
+               " and exit\n";
 }
 
 #ifdef WITH_RPM
@@ -1561,6 +1566,12 @@ parse_command_line(int argc, char* argv[], options& opts)
           opts.display_usage = true;
           return true;
         }
+      else if (!strcmp(argv[i], "--version")
+              || !strcmp(argv[i], "-v"))
+       {
+         opts.display_version = true;
+         return true;
+       }
       else
         return false;
     }
@@ -1594,6 +1605,14 @@ main(int argc, char* argv[])
       return 1;
     }
 
+  if (opts.display_version)
+    {
+      string major, minor, revision;
+      abigail::abigail_get_library_version(major, minor, revision);
+      cout << major << "." << minor << "." << revision << "\n";
+      return 0;
+    }
+
   if (opts.package1.empty() || opts.package2.empty())
     {
       cerr << "Please enter two packages to compare" << "\n";
index 453de7f32be55d125c733886a923f556c096ec58..974a3d1a3fd5c2bf9b9be52d267045ee2ebeaaa0 100644 (file)
@@ -29,6 +29,7 @@
 #include <cstring>
 #include <iostream>
 #include <sstream>
+#include "abg-config.h"
 #include "abg-dwarf-reader.h"
 #include "abg-ir.h"
 
@@ -46,6 +47,7 @@ using abigail::elf_symbol_sptr;
 struct options
 {
   bool show_help;
+  bool display_version;
   char* elf_path;
   char* symbol_name;
   bool demangle;
@@ -53,6 +55,7 @@ struct options
 
   options()
     : show_help(false),
+      display_version(false),
       elf_path(0),
       symbol_name(0),
       demangle(false),
@@ -64,10 +67,11 @@ static void
 display_usage(const string& prog_name, ostream &out)
 {
   out << "usage: " << prog_name << " [options] <elf file> <symbol-name>\n"
-       << "where [options] can be:\n"
-       << "  --help  display this help string\n"
-       << "  --demangle demangle the symbols from the symbol table\n"
-       << "  --no-absolute-path do not show absolute paths in messages\n";
+      << "where [options] can be:\n"
+      << "  --help  display this help string\n"
+      << "  --version|-v  display program version information and exit\n"
+      << "  --demangle  demangle the symbols from the symbol table\n"
+      << "  --no-absolute-path  do not show absolute paths in messages\n";
 }
 
 static void
@@ -99,6 +103,12 @@ parse_command_line(int argc, char* argv[], options& opts)
          opts.show_help = true;
          return;
        }
+      else if (!strcmp(argv[i], "--version")
+              || !strcmp(argv[i], "-v"))
+       {
+         opts.display_version = true;
+         return;
+       }
       else if (!strcmp(argv[i], "--demangle"))
        opts.demangle = true;
       else if (!strcmp(argv[i], "--no-absolute-path"))
@@ -119,6 +129,15 @@ main(int argc, char* argv[])
       display_usage(argv[0], cout);
       return 1;
     }
+
+  if (opts.display_version)
+    {
+      string major, minor, revision;
+      abigail::abigail_get_library_version(major, minor, revision);
+      cout << major << "." << minor << "." << revision << "\n";
+      return 0;
+    }
+
   assert(opts.elf_path != 0
         && opts.symbol_name != 0);