diff mbox series

[applied] abidw: Add --abixml-version

Message ID 87bl2p6zof.fsf@redhat.com
State New
Headers show
Series [applied] abidw: Add --abixml-version | expand

Commit Message

Dodji Seketeli Nov. 12, 2021, 5:39 p.m. UTC
Hello,

This patch adds a command line option to display the version number of
the ABIXML output format.

	* doc/manuals/abidw.rst: Document the --abixml-version command
	line option.
	* configure.ac (ABIXML_VERSION_MAJOR, ABIXML_VERSION_MINOR):
	Define these two new autoconf variables.
	* include/abg-config.h (abigail_get_abixml_version): Declare new
	function.
	* include/abg-tools-utils.h (get_abixml_version_string): Declare
	new function.
	* include/abg-version.h.in (ABIGAIL_ABIXML_VERSION_MAJOR)
	(ABIGAIL_ABIXML_VERSION_MINOR): Define new preprocessor macros.
	* src/abg-config.cc (config::config): Initialize
	config::m_format_{minor,major} using the newly defined
	preprocessor macros ABIGAIL_ABIXML_VERSION_M{IN,AJ}OR.
	* src/abg-tools-utils.cc (get_abixml_version_string): Define new
	function.
	* tools/abidw.cc (options::display_abixml_version): Define new
	data member.
	(options::options): Initialize it.
	(display_usage): Emit a help string for the new --abixml-version
	option.
	(parse_command_line): Parse the --abixml-version string.
	(main): Emit the abixml version when asked.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to the master branch.

---
 configure.ac              |  4 ++++
 doc/manuals/abidw.rst     | 14 +++++++++-----
 include/abg-config.h      |  3 +++
 include/abg-tools-utils.h |  1 +
 include/abg-version.h.in  |  2 ++
 src/abg-config.cc         | 17 +++++++++++++++--
 src/abg-tools-utils.cc    | 12 ++++++++++++
 tools/abidw.cc            | 17 ++++++++++++++++-
 8 files changed, 62 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 4f835d07..5342a269 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,10 +38,14 @@  AM_SILENT_RULES([yes])
 VERSION_MAJOR=version_major
 VERSION_MINOR=version_minor
 VERSION_REVISION=0
+ABIXML_VERSION_MAJOR=2
+ABIXML_VERSION_MINOR=1
 
 AC_SUBST(VERSION_MAJOR)
 AC_SUBST(VERSION_MINOR)
 AC_SUBST(VERSION_REVISION)
+AC_SUBST(ABIXML_VERSION_MAJOR)
+AC_SUBST(ABIXML_VERSION_MINOR)
 
 dnl This VERSION_SUFFIX environment variable is to allow appending
 dnl arbitrary text to the libabigail version string representation.
diff --git a/doc/manuals/abidw.rst b/doc/manuals/abidw.rst
index d7545899..fe4aafd8 100644
--- a/doc/manuals/abidw.rst
+++ b/doc/manuals/abidw.rst
@@ -5,11 +5,11 @@  abidw
 
 abidw reads a shared library in `ELF`_ format and emits an XML
 representation of its ABI to standard output.  The emitted
-representation includes all the globally defined functions and
-variables, along with a complete representation of their types.  It
-also includes a representation of the globally defined ELF symbols of
-the file.  The input shared library must contain associated debug
-information in `DWARF`_ format.
+representation format, named ``ABIXML``, includes all the globally
+defined functions and variables, along with a complete representation
+of their types.  It also includes a representation of the globally
+defined ELF symbols of the file.  The input shared library must
+contain associated debug information in `DWARF`_ format.
 
 When given the ``--linux-tree`` option, this program can also handle a
 Linux kernel tree.  That is, a directory tree that contains both the
@@ -39,6 +39,10 @@  Options
 
     Display the version of the program and exit.
 
+  * `--abixml-version`
+
+    Display the version of the ABIXML format emitted by this program and exit.
+
   * ``--debug-info-dir | -d`` <*dir-path*>
 
     In cases where the debug info for *path-to-elf-file* is in a
diff --git a/include/abg-config.h b/include/abg-config.h
index f16f05be..4d94c71c 100644
--- a/include/abg-config.h
+++ b/include/abg-config.h
@@ -72,6 +72,9 @@  extern "C"
 			      std::string& min,
 			      std::string& rev,
 			      std::string& suf);
+
+  void
+  abigail_get_abixml_version(std::string& maj, std::string& min);
 }
 
 }//end namespace abigail
diff --git a/include/abg-tools-utils.h b/include/abg-tools-utils.h
index ba09f30f..68e54028 100644
--- a/include/abg-tools-utils.h
+++ b/include/abg-tools-utils.h
@@ -61,6 +61,7 @@  bool split_string(const string&, const string&, vector<string>&);
 bool string_suffix(const string&, const string&, string&);
 bool sorted_strings_common_prefix(vector<string>&, string&);
 string get_library_version_string();
+string get_abixml_version_string();
 bool execute_command_and_get_output(const string&, vector<string>&);
 bool get_dsos_provided_by_rpm(const string& rpm_path,
 			      set<string>& provided_dsos);
diff --git a/include/abg-version.h.in b/include/abg-version.h.in
index dc7531a1..939f0cd5 100644
--- a/include/abg-version.h.in
+++ b/include/abg-version.h.in
@@ -5,4 +5,6 @@ 
 #define ABIGAIL_VERSION_MINOR "@VERSION_MINOR@"
 #define ABIGAIL_VERSION_REVISION "@VERSION_REVISION@"
 #define ABIGAIL_VERSION_SUFFIX "@VERSION_SUFFIX@"
+#define ABIGAIL_ABIXML_VERSION_MAJOR "@ABIXML_VERSION_MAJOR@"
+#define ABIGAIL_ABIXML_VERSION_MINOR "@ABIXML_VERSION_MINOR@"
 #endif
diff --git a/src/abg-config.cc b/src/abg-config.cc
index 7d65e2ba..d2e15737 100644
--- a/src/abg-config.cc
+++ b/src/abg-config.cc
@@ -18,8 +18,8 @@  ABG_END_EXPORT_DECLARATIONS
 namespace abigail
 {
 config::config()
-  : m_format_minor("1"),
-    m_format_major("2"),
+  : m_format_minor(ABIGAIL_ABIXML_VERSION_MINOR),
+    m_format_major(ABIGAIL_ABIXML_VERSION_MAJOR),
     m_xml_element_indent(2),
     m_tu_instr_suffix(".bi"),
     m_tu_instr_archive_suffix(".abi")
@@ -80,5 +80,18 @@  abigail_get_library_version(std::string& major,
   suffix = ABIGAIL_VERSION_SUFFIX;
 }
 
+/// Return the version numbers for the ABIXML format.
+///
+/// @param maj the major version number of the ABIXML format.
+///
+/// @param min the minor version number of the ABIXML format.
+void
+abigail_get_abixml_version(std::string& major,
+			   std::string& minor)
+{
+  major = ABIGAIL_ABIXML_VERSION_MAJOR;
+  minor = ABIGAIL_ABIXML_VERSION_MINOR;
+}
+
 }
 }//end namespace abigail
diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index cd8fe468..e3e53fbc 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -1037,6 +1037,18 @@  get_library_version_string()
   return version_string;
 }
 
+/// Return the version string for the ABIXML format.
+///
+/// @return the version string of the ABIXML format.
+string
+get_abixml_version_string()
+{
+  string major, minor, version_string;
+  abigail::abigail_get_abixml_version(major, minor);
+  version_string = major + "." + minor;
+  return version_string;
+}
+
 /// Execute a shell command and returns its output.
 ///
 /// @param cmd the shell command to execute.
diff --git a/tools/abidw.cc b/tools/abidw.cc
index 240ed095..03f76e29 100644
--- a/tools/abidw.cc
+++ b/tools/abidw.cc
@@ -84,6 +84,7 @@  struct options
   vector<string>	kabi_whitelist_paths;
   suppressions_type	kabi_whitelist_supprs;
   bool			display_version;
+  bool			display_abixml_version;
   bool			check_alt_debug_info_path;
   bool			show_base_name_alt_debug_info_path;
   bool			write_architecture;
@@ -117,6 +118,7 @@  struct options
 
   options()
     : display_version(),
+      display_abixml_version(),
       check_alt_debug_info_path(),
       show_base_name_alt_debug_info_path(),
       write_architecture(true),
@@ -165,6 +167,7 @@  display_usage(const string& prog_name, ostream& out)
     << " where options can be: \n"
     << "  --help|-h  display this message\n"
     << "  --version|-v  display program version information and exit\n"
+    << "  --abixml-version  display the version of the ABIXML ABI format\n"
     << "  --debug-info-dir|-d <dir-path>  look for debug info under 'dir-path'\n"
     << "  --headers-dir|--hd <path> the path to headers of the elf file\n"
     << "  --header-file|--hf <path> the path one header of the elf file\n"
@@ -229,6 +232,9 @@  parse_command_line(int argc, char* argv[], options& opts)
       else if (!strcmp(argv[i], "--version")
 	       || !strcmp(argv[i], "-v"))
 	opts.display_version = true;
+      else if (!strcmp(argv[i], "--abixml-version")
+	       || !strcmp(argv[i], "-v"))
+	opts.display_abixml_version = true;
       else if (!strcmp(argv[i], "--debug-info-dir")
 	       || !strcmp(argv[i], "-d"))
 	{
@@ -817,7 +823,8 @@  main(int argc, char* argv[])
 
   if (!parse_command_line(argc, argv, opts)
       || (opts.in_file_path.empty()
-	  && !opts.display_version))
+	  && !opts.display_version
+	  && !opts.display_abixml_version))
     {
       if (!opts.wrong_option.empty())
 	emit_prefix(argv[0], cerr)
@@ -834,6 +841,14 @@  main(int argc, char* argv[])
       return 0;
     }
 
+    if (opts.display_abixml_version)
+      {
+	emit_prefix(argv[0], cout)
+	  << abigail::tools_utils::get_abixml_version_string()
+	  << "\n";
+	return 0;
+      }
+
   ABG_ASSERT(!opts.in_file_path.empty());
   if (opts.corpus_group_for_linux)
     {