mirror of
git://sourceware.org/git/libabigail.git
synced 2025-02-01 06:11:37 +00:00
abidw: add option to only emit file names (--short-locs)
Various emitted directories contain machine specific information and therefore break reproducibility of abidw's output across different build paths. Hence introduce --short-locs to only emit file names. Thanks to earlier changes, adding an option boils down to adding it to set_opts and to the write_context along with some auxiliary functions for setting and getting. * include/abg-writer.h (set_short_locs): Declare new function. (set_common_options): Use it. set_opts * src/abg-writer.cc (write_context::m_short_locs): New data member. (write_context::write_context): Initialize it. (write_context::{g,s}et_short_locs): Define new accessors. (write_location, write_translation_unit, write_corpus): Honour the new write_context::get_short_locs property. (set_short_locs): Define new function. * tools/abidw.cc (options::short_locs): New data member. (display_usage): Help string for the new --no-show-locs option. (parse_command_line): Parse the new --no-show-locs option. Signed-off-by: Matthias Maennich <maennich@google.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
parent
bf9e8b9448
commit
f3f7537b6e
@ -62,6 +62,9 @@ set_write_corpus_path(write_context& ctxt, bool flag);
|
||||
void
|
||||
set_write_comp_dir(write_context& ctxt, bool flag);
|
||||
|
||||
void
|
||||
set_short_locs(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.
|
||||
@ -80,6 +83,7 @@ set_common_options(write_context& ctxt, const OPTS& opts)
|
||||
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);
|
||||
set_short_locs(ctxt, opts.short_locs);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -168,6 +168,7 @@ class write_context
|
||||
bool m_write_architecture;
|
||||
bool m_write_corpus_path;
|
||||
bool m_write_comp_dir;
|
||||
bool m_short_locs;
|
||||
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;
|
||||
@ -199,7 +200,8 @@ public:
|
||||
m_show_locs(true),
|
||||
m_write_architecture(true),
|
||||
m_write_corpus_path(true),
|
||||
m_write_comp_dir(true)
|
||||
m_write_comp_dir(true),
|
||||
m_short_locs(false)
|
||||
{}
|
||||
|
||||
/// Getter of the environment we are operating from.
|
||||
@ -283,6 +285,19 @@ public:
|
||||
set_write_comp_dir(bool f)
|
||||
{m_write_comp_dir = f;}
|
||||
|
||||
/// Getter of the short-locs option.
|
||||
///
|
||||
/// @return true iff short locations shall be emitted
|
||||
bool
|
||||
get_short_locs()
|
||||
{return m_short_locs;}
|
||||
|
||||
/// Setter of the short-locs option
|
||||
///
|
||||
/// @param f the new value of the flag.
|
||||
void
|
||||
set_short_locs(bool f)
|
||||
{m_short_locs = f;}
|
||||
|
||||
/// Getter of the "show-locs" option.
|
||||
///
|
||||
@ -1108,6 +1123,9 @@ write_location(const location& loc, write_context& ctxt)
|
||||
|
||||
ostream &o = ctxt.get_ostream();
|
||||
|
||||
if (ctxt.get_short_locs())
|
||||
tools_utils::base_name(filepath, filepath);
|
||||
|
||||
o << " filepath='" << xml::escape_xml_string(filepath) << "'"
|
||||
<< " line='" << line << "'"
|
||||
<< " column='" << column << "'";
|
||||
@ -1848,6 +1866,18 @@ void
|
||||
set_write_comp_dir(write_context& ctxt, bool flag)
|
||||
{ctxt.set_write_comp_dir(flag);}
|
||||
|
||||
/// Set the 'short-locs' flag.
|
||||
///
|
||||
/// When this flag is set then the XML writer will emit only file names
|
||||
/// rather than full paths.
|
||||
///
|
||||
/// @param ctxt the context to set this flag on to.
|
||||
///
|
||||
/// @param flag the new value of the 'short-locs' flag.
|
||||
void
|
||||
set_short_locs(write_context& ctxt, bool flag)
|
||||
{ctxt.set_short_locs(flag);}
|
||||
|
||||
/// Serialize a translation unit to an output stream.
|
||||
///
|
||||
/// @param ctxt the context of the serialization. It contains e.g,
|
||||
@ -1877,8 +1907,11 @@ write_translation_unit(write_context& ctxt,
|
||||
if (tu.get_address_size() != 0)
|
||||
o << " address-size='" << static_cast<int>(tu.get_address_size()) << "'";
|
||||
|
||||
if (!tu.get_path().empty())
|
||||
o << " path='" << xml::escape_xml_string(tu.get_path()) << "'";
|
||||
std::string tu_path = tu.get_path();
|
||||
if (ctxt.get_short_locs())
|
||||
tools_utils::base_name(tu_path, tu_path);
|
||||
if (!tu_path.empty())
|
||||
o << " path='" << xml::escape_xml_string(tu_path) << "'";
|
||||
|
||||
if (!tu.get_compilation_dir_path().empty() && ctxt.get_write_comp_dir())
|
||||
o << " comp-dir-path='"
|
||||
@ -4197,14 +4230,15 @@ write_corpus(write_context& ctxt,
|
||||
if (!ctxt.get_write_corpus_path())
|
||||
{
|
||||
if (member_of_group)
|
||||
{
|
||||
size_t pos = corpus_path.rfind('/');
|
||||
corpus_path
|
||||
= corpus_path.substr(pos != std::string::npos ? pos + 1 : 0);
|
||||
}
|
||||
tools_utils::base_name(corpus_path, corpus_path);
|
||||
else
|
||||
corpus_path.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ctxt.get_short_locs())
|
||||
tools_utils::base_name(corpus_path, corpus_path);
|
||||
}
|
||||
if (!corpus_path.empty())
|
||||
out << " path='" << xml::escape_xml_string(corpus_path) << "'";
|
||||
|
||||
|
@ -97,6 +97,7 @@ struct options
|
||||
bool write_architecture;
|
||||
bool write_corpus_path;
|
||||
bool write_comp_dir;
|
||||
bool short_locs;
|
||||
bool load_all_types;
|
||||
bool linux_kernel_mode;
|
||||
bool corpus_group_for_linux;
|
||||
@ -114,6 +115,7 @@ struct options
|
||||
write_architecture(true),
|
||||
write_corpus_path(true),
|
||||
write_comp_dir(true),
|
||||
short_locs(false),
|
||||
load_all_types(),
|
||||
linux_kernel_mode(true),
|
||||
corpus_group_for_linux(false),
|
||||
@ -152,6 +154,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"
|
||||
<< " --short-locs only print filenames rather than paths\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"
|
||||
@ -260,6 +263,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], "--short-locs"))
|
||||
opts.short_locs = true;
|
||||
else if (!strcmp(argv[i], "--no-comp-dir-path"))
|
||||
opts.write_comp_dir = false;
|
||||
else if (!strcmp(argv[i], "--check-alternate-debug-info")
|
||||
|
Loading…
Reference in New Issue
Block a user