abidw: add option to omit the compilation directory

The compilation directory contains machine specific information
therefore breaks reproducibility of abidw's output across different
build paths. Hence introduce --no-comp-dir-path (as in the xml
attribute). Internally I decided to not carry on the duplication of
'dir' and 'path' and used 'comp_dir'.

Thanks to earlier changes, adding an option boils down to adding it to
set_common_options and to the write_context along with some auxiliary
functions for setting and getting.

write_translation_unit uses the flag in the write_context and omits the
comp-dir-path if asked for.

	* include/abg-writer.h (set_write_comp_dir): Declare new function.
	(set_common_options): Use it.
	* src/abg-writer.cc (write_context::m_write_comp_dir): Define new
	data member.
	(write_context::write_context): Initialize it.
	(write_context::{g,s}et_write_comp_dir): Define new member
	accessors.
	(set_write_comp_dir): Define new free-form getter.
	(write_translation_unit): Teach to respect write_comp_dir flag of
	write_context.
	* tools/abidw.cc (options::write_corpus_path): Define new data
	member.
	(options::options): Initialize it.
	(display_usage): Add doc string for a new command line option: --no-comp-dir-path.
	(parse_command_line): Parse the new command line option --no-comp-dir-path.

Signed-off-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Matthias Maennich 2019-05-21 05:39:21 +01:00 committed by Dodji Seketeli
parent fca2661581
commit bf9e8b9448
3 changed files with 40 additions and 2 deletions

View File

@ -59,6 +59,9 @@ set_write_architecture(write_context& ctxt, bool flag);
void
set_write_corpus_path(write_context& ctxt, bool flag);
void
set_write_comp_dir(write_context& ctxt, bool flag);
/// A convenience generic function to set common options (usually used
/// by Libabigail tools) from a generic options carrying-object, into
/// a given @ref write_context.
@ -76,6 +79,7 @@ set_common_options(write_context& ctxt, const OPTS& opts)
set_show_locs(ctxt, opts.show_locs);
set_write_architecture(ctxt, opts.write_architecture);
set_write_corpus_path(ctxt, opts.write_corpus_path);
set_write_comp_dir(ctxt, opts.write_comp_dir);
}
void

View File

@ -167,6 +167,7 @@ class write_context
bool m_show_locs;
bool m_write_architecture;
bool m_write_corpus_path;
bool m_write_comp_dir;
mutable type_ptr_map m_type_id_map;
mutable type_ptr_set_type m_emitted_type_set;
type_ptr_set_type m_emitted_decl_only_set;
@ -197,7 +198,8 @@ public:
m_annotate(false),
m_show_locs(true),
m_write_architecture(true),
m_write_corpus_path(true)
m_write_corpus_path(true),
m_write_comp_dir(true)
{}
/// Getter of the environment we are operating from.
@ -267,6 +269,21 @@ public:
set_write_corpus_path(bool f)
{m_write_corpus_path = f;}
/// Getter of the comp-dir-path option.
///
/// @return true iff compilation dir information shall be emitted
bool
get_write_comp_dir()
{return m_write_comp_dir;}
/// Setter of the comp-dir-path option
///
/// @param f the new value of the flag.
void
set_write_comp_dir(bool f)
{m_write_comp_dir = f;}
/// Getter of the "show-locs" option.
///
/// When this option is true then the XML writer emits location
@ -1819,6 +1836,18 @@ void
set_write_corpus_path(write_context& ctxt, bool flag)
{ctxt.set_write_corpus_path(flag);}
/// Set the 'write-comp-dir' flag.
///
/// When this flag is set then the XML writer will emit compilation dir
/// information
///
/// @param ctxt the context to set this flag on to.
///
/// @param flag the new value of the 'write-comp-dir' flag.
void
set_write_comp_dir(write_context& ctxt, bool flag)
{ctxt.set_write_comp_dir(flag);}
/// Serialize a translation unit to an output stream.
///
/// @param ctxt the context of the serialization. It contains e.g,
@ -1851,7 +1880,7 @@ write_translation_unit(write_context& ctxt,
if (!tu.get_path().empty())
o << " path='" << xml::escape_xml_string(tu.get_path()) << "'";
if (!tu.get_compilation_dir_path().empty())
if (!tu.get_compilation_dir_path().empty() && ctxt.get_write_comp_dir())
o << " comp-dir-path='"
<< xml::escape_xml_string(tu.get_compilation_dir_path()) << "'";

View File

@ -96,6 +96,7 @@ struct options
bool show_base_name_alt_debug_info_path;
bool write_architecture;
bool write_corpus_path;
bool write_comp_dir;
bool load_all_types;
bool linux_kernel_mode;
bool corpus_group_for_linux;
@ -112,6 +113,7 @@ struct options
show_base_name_alt_debug_info_path(),
write_architecture(true),
write_corpus_path(true),
write_comp_dir(true),
load_all_types(),
linux_kernel_mode(true),
corpus_group_for_linux(false),
@ -150,6 +152,7 @@ display_usage(const string& prog_name, ostream& out)
<< " --no-architecture do not emit architecture info in the output\n"
<< " --no-corpus-path do not take the path to the corpora into account\n"
<< " --no-show-locs do not show location information\n"
<< " --no-comp-dir-path do not show compilation path 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 "
@ -257,6 +260,8 @@ parse_command_line(int argc, char* argv[], options& opts)
opts.write_corpus_path = false;
else if (!strcmp(argv[i], "--no-show-locs"))
opts.show_locs = false;
else if (!strcmp(argv[i], "--no-comp-dir-path"))
opts.write_comp_dir = false;
else if (!strcmp(argv[i], "--check-alternate-debug-info")
|| !strcmp(argv[i], "--check-alternate-debug-info-base-name"))
{