Emit more informational messages on unrecognized options

This is like what was done for abififf, but for abicompat, abidw,
abipkgdiff and abilint.

	* tools/abicompat.cc (options::prog_name): New data member.
	(display_help, perform_compat_check_in_normal_mode)
	(perform_compat_check_in_weak_mode, main): Prefix error messages
	with the name of the program.
	* tools/abidw.cc (options::wrong_option): New data member.
	(display_help): Prefix error messages with the name of the
	program.n
	(parse_command_line): Record the name of the unrecognized option.
	(main): Tell the name of the unrecognized option.  Prefix error
	messages with the name of the program.
	* tools/abilint.cc (optionqs::wrong_option): New data member
	(display_usage): Prefix error messages with the name of the
	program.
	(parse_command_line): Record the name of the unrecognized option.
	(main): Tell the name of the unrecognized option.  Prefix error
	messages with the name of the program.
	* tools/abipkgdiff.cc (options::{wrong_option, prog_name}): New
	data members.
	(package::erase_extraction_directory, display_usage, extract_rpm)
	(extract_deb, extract_tar)
	(erase_created_temporary_directories_parent, extract_package)
	(compare, create_maps_of_package_content): Prefix error messages
	with the name of the program.
	(maybe_check_suppression_files): Adjust.
	(parse_command_line): Record the name of the unrecognized option,
	and the name of option which lacks an operand.
	(main): Give the name of the unrecognized option.  Prefix error
	messages with the name of the program.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2016-02-12 12:37:04 +01:00
parent b0335a42d5
commit c2d32394b9
4 changed files with 319 additions and 223 deletions

View File

@ -63,8 +63,14 @@ using std::ofstream;
using std::vector;
using std::tr1::shared_ptr;
struct options
using abigail::tools_utils::emit_prefix;
class options
{
options();
public:
string prog_name;
string unknow_option;
string app_path;
string lib1_path;
@ -81,8 +87,9 @@ struct options
bool show_redundant;
bool show_locs;
options()
:display_help(),
options(const char* program_name)
:prog_name(program_name),
display_help(),
display_version(),
weak_mode(),
list_undefined_symbols_only(),
@ -95,28 +102,29 @@ struct options
static void
display_usage(const string& prog_name, ostream& out)
{
out << "usage: " << prog_name
<< " [options] [application-path] [lib-v1-path] [lib-v2-path]"
<< "\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 "
" of the files; not the full paths\n"
<< " --app-debug-info-dir <path-to-app-debug-info> set the path "
"to the debug information directory for the application\n"
<< " --lib-debug-info-dir1 <path-to-lib-debug-info1> set the path "
"to the debug information directory for the first library\n"
<< " --lib-debug-info-dir2 <path-to-lib-debug-info2> set the path "
"to the debug information directory for the second library\n"
<< "--suppressions <path> specify a suppression file\n"
<< "--no-redundant do not display redundant changes\n"
<< "--no-show-locs do now show location information\n"
<< "--redundant display redundant changes (this is the default)\n"
<< "--weak-mode check compatibility between the application and "
"just one version of the library."
emit_prefix(prog_name, out)
<< "usage: " << prog_name
<< " [options] [application-path] [lib-v1-path] [lib-v2-path]"
<< "\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 "
" of the files; not the full paths\n"
<< " --app-debug-info-dir <path-to-app-debug-info> set the path "
"to the debug information directory for the application\n"
<< " --lib-debug-info-dir1 <path-to-lib-debug-info1> set the path "
"to the debug information directory for the first library\n"
<< " --lib-debug-info-dir2 <path-to-lib-debug-info2> set the path "
"to the debug information directory for the second library\n"
<< "--suppressions <path> specify a suppression file\n"
<< "--no-redundant do not display redundant changes\n"
<< "--no-show-locs do now show location information\n"
<< "--redundant display redundant changes (this is the default)\n"
<< "--weak-mode check compatibility between the application and "
"just one version of the library."
;
}
@ -332,7 +340,7 @@ perform_compat_check_in_normal_mode(options& opts,
for (vector<string>::const_iterator i = opts.suppression_paths.begin();
i != opts.suppression_paths.end();
++i)
if (check_file(*i, cerr))
if (check_file(*i, cerr, opts.prog_name))
read_suppressions(*i, supprs);
if (!supprs.empty())
@ -493,7 +501,7 @@ perform_compat_check_in_weak_mode(options& opts,
for (vector<string>::const_iterator i = opts.suppression_paths.begin();
i != opts.suppression_paths.end();
++i)
if (check_file(*i, cerr))
if (check_file(*i, cerr, opts.prog_name))
read_suppressions(*i, supprs);
if (!supprs.empty())
@ -587,20 +595,22 @@ perform_compat_check_in_weak_mode(options& opts,
int
main(int argc, char* argv[])
{
options opts;
options opts(argv[0]);
if (!parse_command_line(argc, argv, opts))
{
if (!opts.unknow_option.empty())
{
cerr << "unrecognized option: " << opts.unknow_option << "\n"
<< "try the --help option for more information\n";
emit_prefix(argv[0], cerr)
<< "unrecognized option: " << opts.unknow_option << "\n"
<< "try the --help option for more information\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
cerr << "wrong invocation\n"
<< "try the --help option for more information\n";
emit_prefix(argv[0], cerr)
<< "wrong invocation\n"
<< "try the --help option for more information\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
@ -621,14 +631,15 @@ main(int argc, char* argv[])
}
assert(!opts.app_path.empty());
if (!abigail::tools_utils::check_file(opts.app_path, cerr))
if (!abigail::tools_utils::check_file(opts.app_path, cerr, opts.prog_name))
return abigail::tools_utils::ABIDIFF_ERROR;
abigail::tools_utils::file_type type =
abigail::tools_utils::guess_file_type(opts.app_path);
if (type != abigail::tools_utils::FILE_TYPE_ELF)
{
cerr << opts.app_path << " is not an ELF file\n";
emit_prefix(argv[0], cerr)
<< opts.app_path << " is not an ELF file\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
@ -644,12 +655,14 @@ main(int argc, char* argv[])
if (status & abigail::dwarf_reader::STATUS_NO_SYMBOLS_FOUND)
{
cerr << "could not read symbols from " << opts.app_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read symbols from " << opts.app_path << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (!(status & abigail::dwarf_reader::STATUS_OK))
{
cerr << "could not read file " << opts.app_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read file " << opts.app_path << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
@ -673,12 +686,12 @@ main(int argc, char* argv[])
// Read the first version of the library.
assert(!opts.lib1_path.empty());
if (!abigail::tools_utils::check_file(opts.lib1_path, cerr))
if (!abigail::tools_utils::check_file(opts.lib1_path, cerr, opts.prog_name))
return abigail::tools_utils::ABIDIFF_ERROR;
type = abigail::tools_utils::guess_file_type(opts.lib1_path);
if (type != abigail::tools_utils::FILE_TYPE_ELF)
{
cerr << opts.lib1_path << " is not an ELF file\n";
emit_prefix(argv[0], cerr) << opts.lib1_path << " is not an ELF file\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
@ -688,7 +701,8 @@ main(int argc, char* argv[])
/*load_all_types=*/false,
status);
if (status & abigail::dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND)
cerr << "could not read debug info for " << opts.lib1_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read debug info for " << opts.lib1_path << "\n";
if (status & abigail::dwarf_reader::STATUS_NO_SYMBOLS_FOUND)
{
cerr << "could not read symbols from " << opts.lib1_path << "\n";
@ -696,7 +710,8 @@ main(int argc, char* argv[])
}
if (!(status & abigail::dwarf_reader::STATUS_OK))
{
cerr << "could not read file " << opts.lib1_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read file " << opts.lib1_path << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
@ -712,15 +727,18 @@ main(int argc, char* argv[])
/*load_all_types=*/false,
status);
if (status & abigail::dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND)
cerr << "could not read debug info for " << opts.lib2_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read debug info for " << opts.lib2_path << "\n";
if (status & abigail::dwarf_reader::STATUS_NO_SYMBOLS_FOUND)
{
cerr << "could not read symbols from " << opts.lib2_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read symbols from " << opts.lib2_path << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (!(status & abigail::dwarf_reader::STATUS_OK))
{
cerr << "could not read file " << opts.lib2_path << "\n";
emit_prefix(argv[0], cerr)
<< "could not read file " << opts.lib2_path << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
}

View File

@ -49,6 +49,7 @@ using std::cout;
using std::ostream;
using std::ofstream;
using std::tr1::shared_ptr;
using abigail::tools_utils::emit_prefix;
using abigail::tools_utils::temp_file;
using abigail::tools_utils::temp_file_sptr;
using abigail::comparison::corpus_diff;
@ -61,6 +62,7 @@ using abigail::xml_reader::read_corpus_from_native_xml_file;
struct options
{
string wrong_option;
string in_file_path;
string out_file_path;
shared_ptr<char> di_root_path;
@ -90,24 +92,25 @@ struct options
static void
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"
<< " --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"
<< " --no-show-locs do now show location information\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 "
emit_prefix(prog_name, out)
<< "usage: " << prog_name << " [options] [<path-to-elf-file>]\n"
<< " where options can be: \n"
<< " --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"
<< " --no-show-locs do now show location information\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 "
"debug info of <elf-path>, and show its base name\n"
<< " --load-all-types read all types including those not reachable from"
"exported declarations\n"
<< " --abidiff compare the loaded ABI against itself\n"
<< " --stats show statistics about various internal stuff\n";
;
<< " --load-all-types read all types including those not reachable from"
"exported declarations\n"
<< " --abidiff compare the loaded ABI against itself\n"
<< " --stats show statistics about various internal stuff\n";
;
}
static bool
@ -180,7 +183,11 @@ parse_command_line(int argc, char* argv[], options& opts)
|| !strcmp(argv[i], "--h"))
return false;
else
return false;
{
if (strlen(argv[i]) >= 2 && argv[i][0] == '-' && argv[i][1] == '-')
opts.wrong_option = argv[i];
return false;
}
}
return true;
@ -211,6 +218,9 @@ main(int argc, char* argv[])
|| (opts.in_file_path.empty()
&& !opts.display_version))
{
if (!opts.wrong_option.empty())
emit_prefix(argv[0], cerr)
<< "unrecognized option: " << opts.wrong_option << "\n";
display_usage(argv[0], cerr);
return 1;
}
@ -224,7 +234,7 @@ main(int argc, char* argv[])
}
assert(!opts.in_file_path.empty());
if (!abigail::tools_utils::check_file(opts.in_file_path, cerr))
if (!abigail::tools_utils::check_file(opts.in_file_path, cerr, argv[0]))
return 1;
abigail::tools_utils::file_type type =
@ -232,7 +242,8 @@ main(int argc, char* argv[])
if (type != abigail::tools_utils::FILE_TYPE_ELF
&& type != abigail::tools_utils::FILE_TYPE_AR)
{
cerr << opts.in_file_path << " is not an ELF file\n";
emit_prefix(argv[0], cerr)
<< opts.in_file_path << " is not an ELF file\n";
return 1;
}
@ -281,7 +292,8 @@ main(int argc, char* argv[])
}
else
{
cerr << "could not find alternate debug info file\n";
emit_prefix(argv[0], cerr)
<< "could not find alternate debug info file\n";
return 1;
}
}
@ -294,25 +306,28 @@ main(int argc, char* argv[])
{
if (p == 0)
{
cerr <<
"Could not read debug info from "
<< opts.in_file_path << "\n";
emit_prefix(argv[0], cerr)
<< "Could not read debug info from "
<< opts.in_file_path << "\n";
cerr << "You might want to supply the root directory where "
emit_prefix(argv[0], cerr)
<< "You might want to supply the root directory where "
"to search debug info from, using the "
"--debug-info-dir option "
"(e.g --debug-info-dir /usr/lib/debug)\n";
}
else
{
cerr << "Could not read debug info for '" << opts.in_file_path
<< "' from debug info root directory '" << p
<< "'\n";
emit_prefix(argv[0], cerr)
<< "Could not read debug info for '" << opts.in_file_path
<< "' from debug info root directory '" << p
<< "'\n";
}
}
else if (s == dwarf_reader::STATUS_NO_SYMBOLS_FOUND)
cerr << "Could not read ELF symbol information from "
<< opts.in_file_path << "\n";
emit_prefix(argv[0], cerr)
<< "Could not read ELF symbol information from "
<< opts.in_file_path << "\n";
return 1;
}
@ -331,7 +346,8 @@ main(int argc, char* argv[])
env.get());
if (!corp2)
{
cerr << "Could not read temporary XML representation of "
emit_prefix(argv[0], cerr)
<< "Could not read temporary XML representation of "
"elf file back\n";
return 1;
}
@ -359,8 +375,9 @@ main(int argc, char* argv[])
ofstream of(opts.out_file_path.c_str(), std::ios_base::trunc);
if (!of.is_open())
{
cerr << "could not open output file '"
<< opts.out_file_path << "'\n";
emit_prefix(argv[0], cerr)
<< "could not open output file '"
<< opts.out_file_path << "'\n";
return 1;
}
abigail::xml_writer::write_corpus_to_native_xml(corp, 0, of);

View File

@ -48,6 +48,7 @@ using std::cin;
using std::cout;
using std::ostream;
using std::ofstream;
using abigail::tools_utils::emit_prefix;
using abigail::tools_utils::check_file;
using abigail::tools_utils::file_type;
using abigail::tools_utils::guess_file_type;
@ -65,6 +66,7 @@ using abigail::xml_writer::write_corpus_to_archive;
struct options
{
string wrong_option;
string file_path;
bool display_version;
bool read_from_stdin;
@ -85,17 +87,18 @@ struct options
static void
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 "
"the input and the memory model saved back to disk\n"
<< " --noout do not display anything on stdout\n"
<< " --stdin|-- read abi-file content from stdin\n"
<< " --tu expect a single translation unit file\n";
emit_prefix(prog_name, 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 "
"the input and the memory model saved back to disk\n"
<< " --noout do not display anything on stdout\n"
<< " --stdin|-- read abi-file content from stdin\n"
<< " --tu expect a single translation unit file\n";
}
bool
@ -144,7 +147,11 @@ parse_command_line(int argc, char* argv[], options& opts)
else if (!strcmp(argv[i], "--noout"))
opts.noout = true;
else
return false;
{
if (strlen(argv[i]) >= 2 && argv[i][0] == '-' && argv[i][1] == '-')
opts.wrong_option = argv[i];
return false;
}
}
if (opts.file_path.empty())
@ -160,6 +167,9 @@ main(int argc, char* argv[])
options opts;
if (!parse_command_line(argc, argv, opts))
{
if (!opts.wrong_option.empty())
emit_prefix(argv[0], cerr)
<< "unrecognized option: " << opts.wrong_option << "\n";
display_usage(argv[0], cerr);
return true;
}
@ -184,7 +194,8 @@ main(int argc, char* argv[])
if (!tu)
{
cerr << "failed to read the ABI instrumentation from stdin\n";
emit_prefix(argv[0], cerr)
<< "failed to read the ABI instrumentation from stdin\n";
return true;
}
@ -202,7 +213,7 @@ main(int argc, char* argv[])
}
else if (!opts.file_path.empty())
{
if (!check_file(opts.file_path, cerr))
if (!check_file(opts.file_path, cerr, argv[0]))
return true;
abigail::translation_unit_sptr tu;
abigail::corpus_sptr corp;
@ -213,7 +224,8 @@ main(int argc, char* argv[])
switch (type)
{
case abigail::tools_utils::FILE_TYPE_UNKNOWN:
cerr << "Unknown file type given in input: " << opts.file_path;
emit_prefix(argv[0], cerr)
<< "Unknown file type given in input: " << opts.file_path;
return true;
case abigail::tools_utils::FILE_TYPE_NATIVE_BI:
tu = read_translation_unit_from_file(opts.file_path, env.get());
@ -249,25 +261,29 @@ main(int argc, char* argv[])
if (!tu && !corp)
{
cerr << "failed to read " << opts.file_path << "\n";
emit_prefix(argv[0], cerr)
<< "failed to read " << opts.file_path << "\n";
if (!(s & abigail::dwarf_reader::STATUS_OK))
{
if (s & abigail::dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND)
{
cerr << "could not find the debug info";
if(di_root_path == 0)
cerr << " Maybe you should consider using the "
emit_prefix(argv[0], cerr)
<< " Maybe you should consider using the "
"--debug-info-dir1 option to tell me about the "
"root directory of the debuginfo? "
"(e.g, --debug-info-dir1 /usr/lib/debug)\n";
else
cerr << "Maybe the root path to the debug "
emit_prefix(argv[0], cerr)
<< "Maybe the root path to the debug "
"information is wrong?\n";
}
if (s & abigail::dwarf_reader::STATUS_NO_SYMBOLS_FOUND)
cerr << "could not find the ELF symbols in the file "
<< opts.file_path
<< "\n";
emit_prefix(argv[0], cerr)
<< "could not find the ELF symbols in the file "
<< opts.file_path
<< "\n";
}
return true;
}
@ -278,7 +294,7 @@ main(int argc, char* argv[])
temp_file_sptr tmp_file = temp_file::create();
if (!tmp_file)
{
cerr << "failed to create temporary file\n";
emit_prefix(argv[0], cerr) << "failed to create temporary file\n";
return true;
}
@ -326,8 +342,9 @@ main(int argc, char* argv[])
(type == abigail::tools_utils::FILE_TYPE_NATIVE_BI)
? "translation unit"
: "ABI corpus";
cerr << "failed to write the translation unit "
<< opts.file_path << " back\n";
emit_prefix(argv[0], cerr)
<< "failed to write the translation unit "
<< opts.file_path << " back\n";
}
if (is_ok

View File

@ -86,6 +86,7 @@ using std::ostream;
using std::vector;
using std::map;
using std::tr1::shared_ptr;
using abigail::tools_utils::emit_prefix;
using abigail::tools_utils::check_file;
using abigail::tools_utils::guess_file_type;
using abigail::tools_utils::string_ends_with;
@ -136,8 +137,13 @@ static pthread_mutex_t arg_lock = PTHREAD_MUTEX_INITIALIZER;
static struct options *prog_options;
/// The options passed to the current program.
struct options
class options
{
options();
public:
string wrong_option;
string prog_name;
bool display_usage;
bool display_version;
bool missing_operand;
@ -157,8 +163,9 @@ struct options
bool fail_if_no_debug_info;
vector<string> suppression_paths;
options()
: display_usage(),
options(const string& program_name)
: prog_name(program_name),
display_usage(),
display_version(),
missing_operand(),
abignore(true),
@ -374,20 +381,21 @@ public:
return;
if (verbose)
cerr << "Erasing temporary extraction directory "
<< extracted_dir_path()
<< " ...";
emit_prefix("abipkgdiff", cerr)
<< "Erasing temporary extraction directory "
<< extracted_dir_path()
<< " ...";
string cmd = "rm -rf " + extracted_dir_path();
if (system(cmd.c_str()))
{
if (verbose)
cerr << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << " FAILED\n";
}
else
{
if (verbose)
cerr << " DONE\n";
emit_prefix("abipkgdiff", cerr) << " DONE\n";
}
}
@ -485,26 +493,27 @@ typedef shared_ptr<package> package_sptr;
static void
display_usage(const string& prog_name, ostream& out)
{
out << "usage: " << prog_name << " [options] <package1> <package2>\n"
<< " where options can be:\n"
<< " --debug-info-pkg1|--d1 <path> path of debug-info package of package1\n"
<< " --debug-info-pkg2|--d2 <path> path of debug-info package of package2\n"
<< " --suppressions|--suppr <path> specify supression specification path\n"
<< " --keep-tmp-files don't erase created temporary files\n"
<< " --dso-only compare shared libraries only\n"
<< " --no-linkage-name do not display linkage names of "
"added/removed/changed\n"
<< " --redundant display redundant changes\n"
<< " --no-show-locs do not show location information\n"
<< " --no-added-syms do not display added functions or variables\n"
<< " --no-added-binaries do not display added binaries\n"
<< " --no-abignore do not look for *.abignore files\n"
<< " --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"
<< " --version|-v display program version information"
" and exit\n";
emit_prefix(prog_name, out)
<< "usage: " << prog_name << " [options] <package1> <package2>\n"
<< " where options can be:\n"
<< " --debug-info-pkg1|--d1 <path> path of debug-info package of package1\n"
<< " --debug-info-pkg2|--d2 <path> path of debug-info package of package2\n"
<< " --suppressions|--suppr <path> specify supression specification path\n"
<< " --keep-tmp-files don't erase created temporary files\n"
<< " --dso-only compare shared libraries only\n"
<< " --no-linkage-name do not display linkage names of "
"added/removed/changed\n"
<< " --redundant display redundant changes\n"
<< " --no-show-locs do not show location information\n"
<< " --no-added-syms do not display added functions or variables\n"
<< " --no-added-binaries do not display added binaries\n"
<< " --no-abignore do not look for *.abignore files\n"
<< " --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"
<< " --version|-v display program version information"
" and exit\n";
}
#ifdef WITH_RPM
@ -522,11 +531,12 @@ extract_rpm(const string& package_path,
const string& extracted_package_dir_path)
{
if (verbose)
cerr << "Extracting package "
<< package_path
<< " to "
<< extracted_package_dir_path
<< " ...";
emit_prefix("abipkgdiff", cerr)
<< "Extracting package "
<< package_path
<< " to "
<< extracted_package_dir_path
<< " ...";
string cmd = "test -d " +
extracted_package_dir_path +
@ -535,7 +545,7 @@ extract_rpm(const string& package_path,
if (system(cmd.c_str()))
{
if (verbose)
cerr << "command " << cmd << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << "command " << cmd << " FAILED\n";
}
cmd = "mkdir -p " + extracted_package_dir_path + " && cd " +
@ -545,12 +555,12 @@ extract_rpm(const string& package_path,
if (system(cmd.c_str()))
{
if (verbose)
cerr << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << " FAILED\n";
return false;
}
if (verbose)
cerr << " DONE\n";
emit_prefix("abipkgdiff", cerr) << " DONE\n";
return true;
}
@ -572,11 +582,12 @@ extract_deb(const string& package_path,
const string& extracted_package_dir_path)
{
if (verbose)
cerr << "Extracting package "
<< package_path
<< "to "
<< extracted_package_dir_path
<< " ...";
emit_prefix("abipkgdiff", cerr)
<< "Extracting package "
<< package_path
<< "to "
<< extracted_package_dir_path
<< " ...";
string cmd = "test -d " +
extracted_package_dir_path +
@ -585,7 +596,7 @@ extract_deb(const string& package_path,
if (system(cmd.c_str()))
{
if (verbose)
cerr << "command " << cmd << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << "command " << cmd << " FAILED\n";
}
cmd = "mkdir -p " + extracted_package_dir_path + " && dpkg -x " +
@ -594,12 +605,12 @@ extract_deb(const string& package_path,
if (system(cmd.c_str()))
{
if (verbose)
cerr << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << " FAILED\n";
return false;
}
if (verbose)
cerr << " DONE\n";
emit_prefix("abipkgdiff", cerr) << " DONE\n";
return true;
}
@ -621,11 +632,12 @@ extract_tar(const string& package_path,
const string& extracted_package_dir_path)
{
if (verbose)
cerr << "Extracting tar archive "
<< package_path
<< " to "
<< extracted_package_dir_path
<< " ...";
emit_prefix("abipkgdiff", cerr)
<< "Extracting tar archive "
<< package_path
<< " to "
<< extracted_package_dir_path
<< " ...";
string cmd = "test -d " +
extracted_package_dir_path +
@ -634,7 +646,7 @@ extract_tar(const string& package_path,
if (system(cmd.c_str()))
{
if (verbose)
cerr << "command " << cmd << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << "command " << cmd << " FAILED\n";
}
cmd = "mkdir -p " + extracted_package_dir_path + " && cd " +
@ -643,12 +655,12 @@ extract_tar(const string& package_path,
if (system(cmd.c_str()))
{
if (verbose)
cerr << " FAILED\n";
emit_prefix("abipkgdiff", cerr) << " FAILED\n";
return false;
}
if (verbose)
cerr << " DONE\n";
emit_prefix("abipkgdiff", cerr) << " DONE\n";
return true;
}
@ -675,20 +687,21 @@ static void
erase_created_temporary_directories_parent()
{
if (verbose)
cerr << "Erasing temporary extraction parent directory "
<< package::extracted_packages_parent_dir()
<< " ...";
emit_prefix("abipkgdiff", cerr)
<< "Erasing temporary extraction parent directory "
<< package::extracted_packages_parent_dir()
<< " ...";
string cmd = "rm -rf " + package::extracted_packages_parent_dir();
if (system(cmd.c_str()))
{
if (verbose)
cerr << "FAILED\n";
emit_prefix("abipkgdiff", cerr) << "FAILED\n";
}
else
{
if (verbose)
cerr << "DONE\n";
emit_prefix("abipkgdiff", cerr) << "DONE\n";
}
}
@ -704,12 +717,14 @@ extract_package(const package& package)
#ifdef WITH_RPM
if (!extract_rpm(package.path(), package.extracted_dir_path()))
{
cerr << "Error while extracting package" << package.path() << "\n";
emit_prefix("abipkgdiff", cerr)
<< "Error while extracting package" << package.path() << "\n";
return false;
}
return true;
#else
cerr << "Support for rpm hasn't been enabled. Please consider "
emit_prefix("abipkgdiff", cerr)
<< "Support for rpm hasn't been enabled. Please consider "
"enabling it at package configure time\n";
return false;
#endif // WITH_RPM
@ -718,12 +733,14 @@ extract_package(const package& package)
#ifdef WITH_DEB
if (!extract_deb(package.path(), package.extracted_dir_path()))
{
cerr << "Error while extracting package" << package.path() << "\n";
emit_prefix("abipkgdiff", cerr)
<< "Error while extracting package" << package.path() << "\n";
return false;
}
return true;
#else
cerr << "Support for deb hasn't been enabled. Please consider "
emit_prefix("abipkgdiff", cerr)
<< "Support for deb hasn't been enabled. Please consider "
"enabling it at package configure time\n";
return false;
#endif // WITH_DEB
@ -738,13 +755,15 @@ extract_package(const package& package)
#ifdef WITH_TAR
if (!extract_tar(package.path(), package.extracted_dir_path()))
{
cerr << "Error while extracting GNU tar archive "
<< package.path() << "\n";
emit_prefix("abipkgdiff", cerr)
<< "Error while extracting GNU tar archive "
<< package.path() << "\n";
return false;
}
return true;
#else
cerr << "Support for GNU tar hasn't been enabled. Please consider "
emit_prefix("abipkgdiff", cerr)
<< "Support for GNU tar hasn't been enabled. Please consider "
"enabling it at package configure time\n";
return false;
#endif // WITH_TAR
@ -837,7 +856,7 @@ maybe_check_suppression_files(const options& opts)
for (vector<string>::const_iterator i = opts.suppression_paths.begin();
i != opts.suppression_paths.end();
++i)
if (!check_file(*i, cerr))
if (!check_file(*i, cerr, opts.prog_name))
return false;
return true;
@ -915,19 +934,21 @@ compare(const elf_file& elf1,
*di_dir2 = (char*) debug_dir2.c_str();
if (verbose)
cerr << "Comparing the ABIs of file "
<< elf1.path
<< " and "
<< elf2.path
<< "...\n";
emit_prefix("abipkgdiff", cerr)
<< "Comparing the ABIs of file "
<< elf1.path
<< " and "
<< elf2.path
<< "...\n";
abigail::dwarf_reader::status c1_status = abigail::dwarf_reader::STATUS_OK,
c2_status = abigail::dwarf_reader::STATUS_OK;
if (verbose)
cerr << " Reading file "
<< elf1.path
<< " ...\n";
emit_prefix("abipkgdiff", cerr)
<< " Reading file "
<< elf1.path
<< " ...\n";
corpus_sptr corpus1 = read_corpus_from_elf(elf1.path, &di_dir1, env.get(),
/*load_all_types=*/false,
@ -935,33 +956,36 @@ compare(const elf_file& elf1,
if (!(c1_status & abigail::dwarf_reader::STATUS_OK))
{
if (verbose)
cerr << "Could not read file '"
<< elf1.path
<< "' properly\n";
emit_prefix("abipkgdiff", cerr)
<< "Could not read file '"
<< elf1.path
<< "' properly\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (opts.fail_if_no_debug_info
&& (c1_status & abigail::dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND))
{
cerr << "Could not find debug info file";
emit_prefix("abipkgdiff", cerr) << "Could not find debug info file";
if (di_dir1 && strcmp(di_dir1, ""))
cerr << " under " << di_dir1 << "\n";
emit_prefix("abipkgdiff", cerr) << " under " << di_dir1 << "\n";
else
cerr << "\n";
emit_prefix("abipkgdiff", cerr) << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (verbose)
cerr << " DONE reading file "
emit_prefix("abipkgdiff", cerr)
<< " DONE reading file "
<< elf1.path
<< " ...\n";
if (verbose)
cerr << " Reading file "
<< elf2.path
<< " ...\n";
emit_prefix("abipkgdiff", cerr)
<< " Reading file "
<< elf2.path
<< " ...\n";
corpus_sptr corpus2 = read_corpus_from_elf(elf2.path, &di_dir2, env.get(),
/*load_all_types=*/false,
@ -969,44 +993,48 @@ compare(const elf_file& elf1,
if (!(c2_status & abigail::dwarf_reader::STATUS_OK))
{
if (verbose)
cerr << "Could not find the read file '"
<< elf2.path
<< "' properly\n";
emit_prefix("abipkgdiff", cerr)
<< "Could not find the read file '"
<< elf2.path
<< "' properly\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (opts.fail_if_no_debug_info
&& (c2_status & abigail::dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND))
{
cerr << "Could not find debug info file";
emit_prefix("abipkgdiff", cerr)
<< "Could not find debug info file";
if (di_dir1 && strcmp(di_dir2, ""))
cerr << " under " << di_dir2 << "\n";
emit_prefix("abipkgdiff", cerr)
<< " under " << di_dir2 << "\n";
else
cerr << "\n";
emit_prefix("abipkgdiff", cerr) << "\n";
return abigail::tools_utils::ABIDIFF_ERROR;
}
if (verbose)
cerr << " DONE reading file "
<< elf2.path
<< " ...\n";
emit_prefix("abipkgdiff", cerr)
<< " DONE reading file " << elf2.path << " ...\n";
if (verbose)
cerr << " Comparing the ABIs of: \n"
<< " " << elf1.path << "\n"
<< " " << elf2.path << "\n";
emit_prefix("abipkgdiff", cerr)
<< " Comparing the ABIs of: \n"
<< " " << elf1.path << "\n"
<< " " << elf2.path << "\n";
diff_context_sptr ctxt(new diff_context);
set_diff_context_from_opts(ctxt, opts);
diff = compute_diff(corpus1, corpus2, ctxt);
if (verbose)
cerr << "Comparing the ABIs of file "
<< elf1.path
<< " and "
<< elf2.path
<< " is DONE\n";
emit_prefix("abipkgdiff", cerr)
<< "Comparing the ABIs of file "
<< elf1.path
<< " and "
<< elf2.path
<< " is DONE\n";
abidiff_status s = abigail::tools_utils::ABIDIFF_OK;
if (diff->has_net_changes())
@ -1093,16 +1121,18 @@ create_maps_of_package_content(package& package,
pthread_setspecific(elf_file_paths_tls_key, elf_file_paths);
if (verbose)
cerr << "Analyzing the content of package "
<< package.path()
<< " extracted to "
<< package.extracted_dir_path()
<< " ...";
emit_prefix("abipkgdiff", cerr)
<< "Analyzing the content of package "
<< package.path()
<< " extracted to "
<< package.extracted_dir_path()
<< " ...";
if (ftw(package.extracted_dir_path().c_str(), callback, 16))
{
cerr << "Error while inspecting files in package"
<< package.extracted_dir_path() << "\n";
emit_prefix("abipkgdiff", cerr)
<< "Error while inspecting files in package"
<< package.extracted_dir_path() << "\n";
return false;
}
@ -1134,7 +1164,7 @@ create_maps_of_package_content(package& package,
delete elf_file_paths;
if (verbose)
cerr << " DONE\n";
emit_prefix("abipkgdiff", cerr) << " DONE\n";
return true;
}
@ -1538,8 +1568,9 @@ parse_command_line(int argc, char* argv[], options& opts)
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
return true;
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.debug_package1 =
abigail::tools_utils::make_path_absolute(argv[j]).get();
@ -1551,8 +1582,9 @@ parse_command_line(int argc, char* argv[], options& opts)
int j = i + 1;
if (j >= argc)
{
opts.missing_operand = true;
return true;
opts.missing_operand = true;
opts.wrong_option = argv[i];
return true;
}
opts.debug_package2 =
abigail::tools_utils::make_path_absolute(argv[j]).get();
@ -1602,7 +1634,11 @@ parse_command_line(int argc, char* argv[], options& opts)
return true;
}
else
return false;
{
if (strlen(argv[i]) >= 2 && argv[i][0] == '-' && argv[i][1] == '-')
opts.wrong_option = argv[i];
return false;
}
}
return true;
@ -1611,20 +1647,22 @@ parse_command_line(int argc, char* argv[], options& opts)
int
main(int argc, char* argv[])
{
options opts;
options opts(argv[0]);
prog_options = &opts;
vector<package_sptr> packages;
if (!parse_command_line(argc, argv, opts))
{
cerr << "unrecognized option\n"
"try the --help option for more information\n";
emit_prefix("abipkgdiff", cerr)
<< "unrecognized option:" << opts.wrong_option
<< "\ntry the --help option for more information\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
if (opts.missing_operand)
{
cerr << "missing operand\n"
emit_prefix("abipkgdiff", cerr)
<< "missing operand\n"
"try the --help option for more information\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
@ -1651,7 +1689,8 @@ main(int argc, char* argv[])
if (opts.package1.empty() || opts.package2.empty())
{
cerr << "Please enter two packages to compare" << "\n";
emit_prefix("abipkgdiff", cerr)
<< "Please enter two packages to compare" << "\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
@ -1677,7 +1716,8 @@ main(int argc, char* argv[])
case abigail::tools_utils::FILE_TYPE_RPM:
if (second_package->type() != abigail::tools_utils::FILE_TYPE_RPM)
{
cerr << opts.package2 << " should be an RPM file\n";
emit_prefix("abipkgdiff", cerr)
<< opts.package2 << " should be an RPM file\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
@ -1686,7 +1726,8 @@ main(int argc, char* argv[])
case abigail::tools_utils::FILE_TYPE_DEB:
if (second_package->type() != abigail::tools_utils::FILE_TYPE_DEB)
{
cerr << opts.package2 << " should be a DEB file\n";
emit_prefix("abipkgdiff", cerr)
<< opts.package2 << " should be a DEB file\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
@ -1695,7 +1736,8 @@ main(int argc, char* argv[])
case abigail::tools_utils::FILE_TYPE_DIR:
if (second_package->type() != abigail::tools_utils::FILE_TYPE_DIR)
{
cerr << opts.package2 << " should be a directory\n";
emit_prefix("abipkgdiff", cerr)
<< opts.package2 << " should be a directory\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
@ -1704,14 +1746,16 @@ main(int argc, char* argv[])
case abigail::tools_utils::FILE_TYPE_TAR:
if (second_package->type() != abigail::tools_utils::FILE_TYPE_TAR)
{
cerr << opts.package2 << " should be a GNU tar archive\n";
emit_prefix("abipkgdiff", cerr)
<< opts.package2 << " should be a GNU tar archive\n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}
break;
default:
cerr << opts.package1 << " should be a valid package file \n";
emit_prefix("abipkgdiff", cerr)
<< opts.package1 << " should be a valid package file \n";
return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
| abigail::tools_utils::ABIDIFF_ERROR);
}