]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - utils/sym_check/sym_diff.py
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / utils / sym_check / sym_diff.py
1 #!/usr/bin/env python
2 #===----------------------------------------------------------------------===##
3 #
4 #                     The LLVM Compiler Infrastructure
5 #
6 # This file is dual licensed under the MIT and the University of Illinois Open
7 # Source Licenses. See LICENSE.TXT for details.
8 #
9 #===----------------------------------------------------------------------===##
10 """
11 sym_diff - Compare two symbol lists and output the differences.
12 """
13
14 from argparse import ArgumentParser
15 import sys
16 from sym_check import diff, util
17
18
19 def main():
20     parser = ArgumentParser(
21         description='Extract a list of symbols from a shared library.')
22     parser.add_argument(
23         '--names-only', dest='names_only',
24         help='Only print symbol names',
25         action='store_true', default=False)
26     parser.add_argument(
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)
33     parser.add_argument(
34         '-o', '--output', dest='output',
35         help='The output file. stdout is used if not given',
36         type=str, action='store', default=None)
37     parser.add_argument(
38         '--demangle', dest='demangle', action='store_true', default=False)
39     parser.add_argument(
40         'old_syms', metavar='old-syms', type=str,
41         help='The file containing the old symbol list or a library')
42     parser.add_argument(
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()
46
47     old_syms_list = util.extract_or_load(args.old_syms)
48     new_syms_list = util.extract_or_load(args.new_syms)
49
50     if args.only_stdlib:
51         old_syms_list, _ = util.filter_stdlib_symbols(old_syms_list)
52         new_syms_list, _ = util.filter_stdlib_symbols(new_syms_list)
53
54     added, removed, changed = diff.diff(old_syms_list, new_syms_list)
55     if args.removed_only:
56         added = {}
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:
61         print(report)
62     else:
63         with open(args.output, 'w') as f:
64             f.write(report + '\n')
65     sys.exit(is_break)
66
67
68 if __name__ == '__main__':
69     main()