2 #===----------------------------------------------------------------------===##
4 # The LLVM Compiler Infrastructure
6 # This file is dual licensed under the MIT and the University of Illinois Open
7 # Source Licenses. See LICENSE.TXT for details.
9 #===----------------------------------------------------------------------===##
11 sym_diff - Compare two symbol lists and output the differences.
14 from argparse import ArgumentParser
16 from sym_check import diff, util
20 parser = ArgumentParser(
21 description='Extract a list of symbols from a shared library.')
23 '--names-only', dest='names_only',
24 help='Only print symbol names',
25 action='store_true', default=False)
27 '--removed-only', dest='removed_only',
28 help='Only print removed symbols',
29 action='store_true', default=False)
30 parser.add_argument('--only-stdlib-symbols', dest='only_stdlib',
31 help="Filter all symbols not related to the stdlib",
32 action='store_true', default=False)
34 '-o', '--output', dest='output',
35 help='The output file. stdout is used if not given',
36 type=str, action='store', default=None)
38 '--demangle', dest='demangle', action='store_true', default=False)
40 'old_syms', metavar='old-syms', type=str,
41 help='The file containing the old symbol list or a library')
43 'new_syms', metavar='new-syms', type=str,
44 help='The file containing the new symbol list or a library')
45 args = parser.parse_args()
47 old_syms_list = util.extract_or_load(args.old_syms)
48 new_syms_list = util.extract_or_load(args.new_syms)
51 old_syms_list, _ = util.filter_stdlib_symbols(old_syms_list)
52 new_syms_list, _ = util.filter_stdlib_symbols(new_syms_list)
54 added, removed, changed = diff.diff(old_syms_list, new_syms_list)
57 report, is_break = diff.report_diff(added, removed, changed,
58 names_only=args.names_only,
59 demangle=args.demangle)
60 if args.output is None:
63 with open(args.output, 'w') as f:
64 f.write(report + '\n')
68 if __name__ == '__main__':