2013-08-29 15:08:47 +00:00
|
|
|
// -*- Mode: C++ -*-
|
|
|
|
//
|
2015-01-07 12:53:58 +00:00
|
|
|
// Copyright (C) 2013-2015 Red Hat, Inc.
|
2013-08-29 15:08:47 +00:00
|
|
|
//
|
|
|
|
// This file is part of the GNU Application Binary Interface Generic
|
|
|
|
// Analysis and Instrumentation Library (libabigail). This library is
|
|
|
|
// free software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU Lesser General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
// later version.
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Lesser Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this program; see the file COPYING-LGPLV3. If
|
|
|
|
// not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
///@file
|
|
|
|
|
2014-06-04 14:30:18 +00:00
|
|
|
#include <tr1/memory>
|
2013-08-29 15:08:47 +00:00
|
|
|
#include <string>
|
2013-10-11 15:19:29 +00:00
|
|
|
#include <ostream>
|
Initial support for diffing ABI corpus files
* include/abg-comparison.h (string_function_ptr_map)
(changed_function_ptr, string_changed_function_ptr_map)
(corpus_diff_sptr): New convenience typedefs.
(translation_unit_diff): Add comments.
(class corpus_diff): New type.
(compute_diff): New overload for corpus_diff.
* include/abg-corpus.h (corpus::{functions, variables}): New
typedefs.
(corpus::{operator==, get_functions, get_variables}): New members.
* include/abg-diff-utils.h (struct deep_ptr_eq_functor): New
functor.
* include/abg-ir.h (translation_unit::operator==): New member
equality operator.
* src/abg-comparison.cc (struct corpus_diff::priv): New private
struct holding the private members of corpus_diff.
(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables,
ensure_lookup_tables_populated}): Define new private member functions.
(corpus_diff::{corpus_diff, first_corpus, second_corpus,
function_changes, variable_changes, length, report}): New public members.
(struct noop_deleter): New struct.
(compute_diff): New implementation for corpus_diff.
* src/abg-corpus.cc (struct corpus::priv): Renamed corpus::impl
into this. Add new fns, vars and is_symbol_table_built data
members.
(corpus::priv::build_symbol_table): New member function.
(class symtab_build_visitor_type): New visitor type to build the
symbol table.
(struct func_comp, struct var_comp): New comparison functors.
(corpus::priv::build_symbol_table): Define new member function.
(corpus::{corpus, add, get_translation_units, operator==,
get_functions, get_variables}): Define new members.
* src/abg-ir.cc (translation_unit::operator==): Define new member
equality operator.
(operator==(translation_unit_sptr l, translation_unit_sptr r)):
Define new equality operator.
* tools/abg-tools-utils.h (enum file_type): New enum.
(guess_file_type): Declare new function.
* tools/abg-tools-utils.cc (guess_file_type): define new function.
* tools/bidiff.cc (main): Guess the type of the files given in
input and support elf files reading and diffing.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:05:19 +00:00
|
|
|
#include <istream>
|
2015-07-20 08:06:17 +00:00
|
|
|
#include <iostream>
|
2013-08-29 15:08:47 +00:00
|
|
|
|
|
|
|
namespace abigail
|
|
|
|
{
|
|
|
|
|
2015-01-08 10:34:03 +00:00
|
|
|
namespace tools_utils
|
2013-08-29 15:08:47 +00:00
|
|
|
{
|
|
|
|
|
2015-01-08 10:34:03 +00:00
|
|
|
using std::ostream;
|
|
|
|
using std::istream;
|
|
|
|
using std::ifstream;
|
|
|
|
using std::string;
|
2015-07-20 08:06:17 +00:00
|
|
|
using std::tr1::shared_ptr;
|
2015-01-08 10:34:03 +00:00
|
|
|
|
|
|
|
bool file_exists(const string&);
|
|
|
|
bool is_regular_file(const string&);
|
|
|
|
bool is_dir(const string&);
|
|
|
|
bool base_name(string const& path,
|
|
|
|
string& file_name);
|
|
|
|
bool ensure_dir_path_created(const string&);
|
|
|
|
bool ensure_parent_dir_created(const string&);
|
|
|
|
bool check_file(const string& path, ostream& out);
|
2013-08-29 15:08:47 +00:00
|
|
|
|
2015-07-20 08:06:17 +00:00
|
|
|
class temp_file;
|
|
|
|
|
|
|
|
/// Convenience typedef for a shared_ptr to @ref temp_file.
|
|
|
|
typedef shared_ptr<temp_file> temp_file_sptr;
|
|
|
|
|
|
|
|
/// A temporary file.
|
|
|
|
///
|
|
|
|
/// This is a helper file around the mkstemp API.
|
|
|
|
///
|
|
|
|
/// Once the temporary file is created, users can interact with it
|
|
|
|
/// using an iostream. They can also get the path to the newly
|
|
|
|
/// created temporary file.
|
|
|
|
///
|
|
|
|
/// When the instance of @ref temp_file is destroyed, the underlying
|
|
|
|
/// resources are de-allocated, the underlying temporary file is
|
|
|
|
/// closed and removed.
|
|
|
|
class temp_file
|
|
|
|
{
|
|
|
|
struct priv;
|
|
|
|
typedef shared_ptr<priv> priv_sptr;
|
|
|
|
|
|
|
|
priv_sptr priv_;
|
|
|
|
|
|
|
|
temp_file();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool
|
|
|
|
is_good() const;
|
|
|
|
|
|
|
|
const char*
|
|
|
|
get_path() const;
|
|
|
|
|
|
|
|
std::iostream&
|
|
|
|
get_stream();
|
|
|
|
|
|
|
|
static temp_file_sptr
|
|
|
|
create();
|
|
|
|
}; // end class temp_file
|
Try to avoid a race condition when abipkgdiff extracts packages.
abipkgdiff extracts the content of the first package in a directory
named <tmpdir>/package1 and the content second package in
<tmpdir>/package2. If two independant instances of abipkgdiff are
launched at the same time, they are going to walk on each others'
toes, to say the least.
This patch extracts the content of each package in directory named
<tmpdir>/<randomname>/package1, where randomname is supposed to be a
random number, and so should be unique, most of the time.
I guess we should try harder to generate a randomname that is unique
when we see that the directory <tmpdir>/<randomname> exists already,
but for now, what we have is good enough, or at least better than what
we have had so far.
* include/abg-tools-utils.h (get_random_number)
(get_random_number_as_string): Declare new functions.
* src/abg-tools-utils.cc (get_random_number)
(get_random_number_as_string): Define them.
* tools/abipkgdiff.cc
(package::extracted_package_parent_dir_path): New data member.
(package::package): Initialize
package::extracted_package_parent_dir_path to
<tmpdir>/<randomname>, with randomname being a random number
represented as a string.
(extract_rpm): Make sure to create a hierarchy of directories, not
just a directory.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-19 22:02:00 +00:00
|
|
|
|
|
|
|
size_t
|
|
|
|
get_random_number();
|
|
|
|
|
|
|
|
string
|
|
|
|
get_random_number_as_string();
|
|
|
|
|
Initial support for diffing ABI corpus files
* include/abg-comparison.h (string_function_ptr_map)
(changed_function_ptr, string_changed_function_ptr_map)
(corpus_diff_sptr): New convenience typedefs.
(translation_unit_diff): Add comments.
(class corpus_diff): New type.
(compute_diff): New overload for corpus_diff.
* include/abg-corpus.h (corpus::{functions, variables}): New
typedefs.
(corpus::{operator==, get_functions, get_variables}): New members.
* include/abg-diff-utils.h (struct deep_ptr_eq_functor): New
functor.
* include/abg-ir.h (translation_unit::operator==): New member
equality operator.
* src/abg-comparison.cc (struct corpus_diff::priv): New private
struct holding the private members of corpus_diff.
(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables,
ensure_lookup_tables_populated}): Define new private member functions.
(corpus_diff::{corpus_diff, first_corpus, second_corpus,
function_changes, variable_changes, length, report}): New public members.
(struct noop_deleter): New struct.
(compute_diff): New implementation for corpus_diff.
* src/abg-corpus.cc (struct corpus::priv): Renamed corpus::impl
into this. Add new fns, vars and is_symbol_table_built data
members.
(corpus::priv::build_symbol_table): New member function.
(class symtab_build_visitor_type): New visitor type to build the
symbol table.
(struct func_comp, struct var_comp): New comparison functors.
(corpus::priv::build_symbol_table): Define new member function.
(corpus::{corpus, add, get_translation_units, operator==,
get_functions, get_variables}): Define new members.
* src/abg-ir.cc (translation_unit::operator==): Define new member
equality operator.
(operator==(translation_unit_sptr l, translation_unit_sptr r)):
Define new equality operator.
* tools/abg-tools-utils.h (enum file_type): New enum.
(guess_file_type): Declare new function.
* tools/abg-tools-utils.cc (guess_file_type): define new function.
* tools/bidiff.cc (main): Guess the type of the files given in
input and support elf files reading and diffing.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:05:19 +00:00
|
|
|
/// The different types of files understood the bi* suite of tools.
|
|
|
|
enum file_type
|
|
|
|
{
|
|
|
|
/// A file type we don't know about.
|
|
|
|
FILE_TYPE_UNKNOWN,
|
|
|
|
/// The native xml file format representing a translation unit.
|
|
|
|
FILE_TYPE_NATIVE_BI,
|
|
|
|
/// An elf file. Read this kind of file should yield an
|
|
|
|
/// abigail::corpus type.
|
|
|
|
FILE_TYPE_ELF,
|
2014-06-02 15:05:05 +00:00
|
|
|
/// An archive (AR) file.
|
|
|
|
FILE_TYPE_AR,
|
2014-01-07 13:12:26 +00:00
|
|
|
// A native xml file format representing a corpus of one or several
|
|
|
|
// translation units.
|
|
|
|
FILE_TYPE_XML_CORPUS,
|
|
|
|
// A zip file, possibly containing a corpus of one of several
|
|
|
|
// translation units.
|
|
|
|
FILE_TYPE_ZIP_CORPUS,
|
2015-05-21 07:38:32 +00:00
|
|
|
/// An RPM (.rpm) binary file
|
|
|
|
FILE_TYPE_RPM,
|
|
|
|
/// An SRPM (.src.rpm) file
|
|
|
|
FILE_TYPE_SRPM,
|
Initial support for diffing ABI corpus files
* include/abg-comparison.h (string_function_ptr_map)
(changed_function_ptr, string_changed_function_ptr_map)
(corpus_diff_sptr): New convenience typedefs.
(translation_unit_diff): Add comments.
(class corpus_diff): New type.
(compute_diff): New overload for corpus_diff.
* include/abg-corpus.h (corpus::{functions, variables}): New
typedefs.
(corpus::{operator==, get_functions, get_variables}): New members.
* include/abg-diff-utils.h (struct deep_ptr_eq_functor): New
functor.
* include/abg-ir.h (translation_unit::operator==): New member
equality operator.
* src/abg-comparison.cc (struct corpus_diff::priv): New private
struct holding the private members of corpus_diff.
(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables,
ensure_lookup_tables_populated}): Define new private member functions.
(corpus_diff::{corpus_diff, first_corpus, second_corpus,
function_changes, variable_changes, length, report}): New public members.
(struct noop_deleter): New struct.
(compute_diff): New implementation for corpus_diff.
* src/abg-corpus.cc (struct corpus::priv): Renamed corpus::impl
into this. Add new fns, vars and is_symbol_table_built data
members.
(corpus::priv::build_symbol_table): New member function.
(class symtab_build_visitor_type): New visitor type to build the
symbol table.
(struct func_comp, struct var_comp): New comparison functors.
(corpus::priv::build_symbol_table): Define new member function.
(corpus::{corpus, add, get_translation_units, operator==,
get_functions, get_variables}): Define new members.
* src/abg-ir.cc (translation_unit::operator==): Define new member
equality operator.
(operator==(translation_unit_sptr l, translation_unit_sptr r)):
Define new equality operator.
* tools/abg-tools-utils.h (enum file_type): New enum.
(guess_file_type): Declare new function.
* tools/abg-tools-utils.cc (guess_file_type): define new function.
* tools/bidiff.cc (main): Guess the type of the files given in
input and support elf files reading and diffing.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:05:19 +00:00
|
|
|
};
|
|
|
|
|
Make abidiff and abicompat return meaningful exit codes
As per https://sourceware.org/bugzilla/show_bug.cgi?id=18146, abidiff
the exit code of abidiff and abicompat is now a bit field that can be
inspected to know if the ABI change reported is incompatible for sure,
or if it needs user review of the output to decide.
This patch also updates the documentation.
* doc/manuals/abicompat.rst: Update documentation for abicompat
exit codes.
* doc/manuals/abidiff.rst: Likewise for abidiff exit codes.
* include/abg-tools-utils.h (enum abidiff_status): Declare new
enum.
(operator{|,&,|=}): Declare new operators for the new enum
abidiff_status.
(abidiff_status_has_error, abidiff_status_has_abi_change)
(abidiff_status_has_incompatible_abi_change): Declare new
functions.
* src/abg-tools-utils.cc (operator{|,&,|=}): Define these new
operators.
(abidiff_status_has_error, abidiff_status_has_abi_change)
(abidiff_status_has_incompatible_abi_change): Define new
functions.
* tests/test-diff-filter.cc (main): Adjust for the new exit code
of abidiff.
* tests/test-diff-suppr.cc (main): Likewise.
* tests/test-abicompat.cc (main): Likewise.
* tools/abicompat.cc (enum abicompat_status): Remove.
(operator{|,&,|=}): Remove these operators for enum
abicompat_status.
(perform_compat_check_in_normal_mode)
(perform_compat_check_in_weak_mode): Return abidiff_status instead
of abicompat_status. Adjust therefore.
(main): Adjust to return abidiff_status now, instead of a just
zero for all non-error cases.
* tools/abidiff.cc (main): Likewise.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-10 13:42:35 +00:00
|
|
|
/// Exit status for abidiff and abicompat tools.
|
|
|
|
///
|
|
|
|
/// It's actually a bit mask. The valu of each enumerator is a power
|
|
|
|
/// of two.
|
|
|
|
enum abidiff_status
|
|
|
|
{
|
|
|
|
/// This is for when the compared ABIs are equal.
|
|
|
|
///
|
|
|
|
/// Its numerical value is 0.
|
|
|
|
ABIDIFF_OK = 0,
|
|
|
|
|
|
|
|
/// This bit is set if there an application error.
|
|
|
|
///
|
|
|
|
/// Its numerical value is 1.
|
|
|
|
ABIDIFF_ERROR = 1,
|
|
|
|
|
|
|
|
/// This bit is set if the tool is invoked in an non appropriate
|
|
|
|
/// manner.
|
|
|
|
///
|
|
|
|
/// Its numerical value is 2.
|
|
|
|
ABIDIFF_USAGE_ERROR = 1 << 1,
|
|
|
|
|
|
|
|
/// This bit is set if the ABIs being compared are different.
|
|
|
|
///
|
|
|
|
/// Its numerical value is 4.
|
|
|
|
ABIDIFF_ABI_CHANGE = 1 << 2,
|
|
|
|
|
|
|
|
/// This bit is set if the ABIs being compared are different *and*
|
|
|
|
/// are incompatible.
|
|
|
|
///
|
|
|
|
/// Its numerical value is 8.
|
|
|
|
ABIDIFF_ABI_INCOMPATIBLE_CHANGE = 1 << 3
|
|
|
|
};
|
|
|
|
|
|
|
|
abidiff_status
|
|
|
|
operator|(abidiff_status, abidiff_status);
|
|
|
|
|
|
|
|
abidiff_status
|
|
|
|
operator&(abidiff_status, abidiff_status);
|
|
|
|
|
|
|
|
abidiff_status&
|
|
|
|
operator|=(abidiff_status&l, abidiff_status r);
|
|
|
|
bool
|
|
|
|
abidiff_status_has_error(abidiff_status s);
|
|
|
|
|
|
|
|
bool
|
|
|
|
abidiff_status_has_abi_change(abidiff_status s);
|
|
|
|
|
|
|
|
bool
|
|
|
|
abidiff_status_has_incompatible_abi_change(abidiff_status s);
|
|
|
|
|
2015-05-21 07:38:32 +00:00
|
|
|
ostream&
|
|
|
|
operator<<(ostream& output, file_type r);
|
|
|
|
|
2015-01-08 10:34:03 +00:00
|
|
|
file_type guess_file_type(istream& in);
|
|
|
|
file_type guess_file_type(const string& file_path);
|
Initial support for diffing ABI corpus files
* include/abg-comparison.h (string_function_ptr_map)
(changed_function_ptr, string_changed_function_ptr_map)
(corpus_diff_sptr): New convenience typedefs.
(translation_unit_diff): Add comments.
(class corpus_diff): New type.
(compute_diff): New overload for corpus_diff.
* include/abg-corpus.h (corpus::{functions, variables}): New
typedefs.
(corpus::{operator==, get_functions, get_variables}): New members.
* include/abg-diff-utils.h (struct deep_ptr_eq_functor): New
functor.
* include/abg-ir.h (translation_unit::operator==): New member
equality operator.
* src/abg-comparison.cc (struct corpus_diff::priv): New private
struct holding the private members of corpus_diff.
(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables,
ensure_lookup_tables_populated}): Define new private member functions.
(corpus_diff::{corpus_diff, first_corpus, second_corpus,
function_changes, variable_changes, length, report}): New public members.
(struct noop_deleter): New struct.
(compute_diff): New implementation for corpus_diff.
* src/abg-corpus.cc (struct corpus::priv): Renamed corpus::impl
into this. Add new fns, vars and is_symbol_table_built data
members.
(corpus::priv::build_symbol_table): New member function.
(class symtab_build_visitor_type): New visitor type to build the
symbol table.
(struct func_comp, struct var_comp): New comparison functors.
(corpus::priv::build_symbol_table): Define new member function.
(corpus::{corpus, add, get_translation_units, operator==,
get_functions, get_variables}): Define new members.
* src/abg-ir.cc (translation_unit::operator==): Define new member
equality operator.
(operator==(translation_unit_sptr l, translation_unit_sptr r)):
Define new equality operator.
* tools/abg-tools-utils.h (enum file_type): New enum.
(guess_file_type): Declare new function.
* tools/abg-tools-utils.cc (guess_file_type): define new function.
* tools/bidiff.cc (main): Guess the type of the files given in
input and support elf files reading and diffing.
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:05:19 +00:00
|
|
|
|
2014-06-04 14:30:18 +00:00
|
|
|
std::tr1::shared_ptr<char>
|
|
|
|
make_path_absolute(const char*p);
|
|
|
|
|
2015-01-08 10:34:03 +00:00
|
|
|
}// end namespace tools_utils
|
2013-08-29 15:08:47 +00:00
|
|
|
}//end namespace abigail
|