Home | History | Annotate | Download | only in sym_check
      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         '-o', '--output', dest='output',
     28         help='The output file. stdout is used if not given',
     29         type=str, action='store', default=None)
     30     parser.add_argument(
     31         '--demangle', dest='demangle', action='store_true', default=False)
     32     parser.add_argument(
     33         'old_syms', metavar='old-syms', type=str,
     34         help='The file containing the old symbol list or a library')
     35     parser.add_argument(
     36         'new_syms', metavar='new-syms', type=str,
     37         help='The file containing the new symbol list or a library')
     38     args = parser.parse_args()
     39 
     40     old_syms_list = util.extract_or_load(args.old_syms)
     41     new_syms_list = util.extract_or_load(args.new_syms)
     42 
     43     added, removed, changed = diff.diff(old_syms_list, new_syms_list)
     44     report, is_break = diff.report_diff(added, removed, changed,
     45                                         names_only=args.names_only,
     46                                         demangle=args.demangle)
     47     if args.output is None:
     48         print(report)
     49     else:
     50         with open(args.output, 'w') as f:
     51             f.write(report + '\n')
     52     sys.exit(is_break)
     53 
     54 
     55 if __name__ == '__main__':
     56     main()
     57