• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2"""
3sym_diff - Compare two symbol lists and output the differences.
4"""
5from argparse import ArgumentParser
6import sys
7from sym_check import diff, util
8
9
10def main():
11    parser = ArgumentParser(
12        description='Extract a list of symbols from a shared library.')
13    parser.add_argument(
14        '--names-only', dest='names_only',
15        help='Only print symbol names',
16        action='store_true', default=False)
17    parser.add_argument(
18        '-o', '--output', dest='output',
19        help='The output file. stdout is used if not given',
20        type=str, action='store', default=None)
21    parser.add_argument(
22        '--demangle', dest='demangle', action='store_true', default=False)
23    parser.add_argument(
24        'old_syms', metavar='old-syms', type=str,
25        help='The file containing the old symbol list or a library')
26    parser.add_argument(
27        'new_syms', metavar='new-syms', type=str,
28        help='The file containing the new symbol list or a library')
29    args = parser.parse_args()
30
31    old_syms_list = util.extract_or_load(args.old_syms)
32    new_syms_list = util.extract_or_load(args.new_syms)
33
34    added, removed, changed = diff.diff(old_syms_list, new_syms_list)
35    report, is_break = diff.report_diff(added, removed, changed,
36                                        names_only=args.names_only,
37                                        demangle=args.demangle)
38    if args.output is None:
39        print(report)
40    else:
41        with open(args.output, 'w') as f:
42            f.write(report + '\n')
43    sys.exit(is_break)
44
45
46if __name__ == '__main__':
47    main()
48