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""" 12sym_match - Match all symbols in a list against a list of regexes. 13""" 14from argparse import ArgumentParser 15import sys 16from libcxx.sym_check import util, match, extract 17 18 19def main(): 20 parser = ArgumentParser( 21 description='Extract a list of symbols from a shared library.') 22 parser.add_argument( 23 '--blacklist', dest='blacklist', 24 type=str, action='store', default=None) 25 parser.add_argument( 26 'symbol_list', metavar='symbol_list', type=str, 27 help='The file containing the old symbol list') 28 parser.add_argument( 29 'regexes', metavar='regexes', default=[], nargs='*', 30 help='The file containing the new symbol list or a library') 31 args = parser.parse_args() 32 33 if not args.regexes and args.blacklist is None: 34 sys.stderr.write('Either a regex or a blacklist must be specified.\n') 35 sys.exit(1) 36 if args.blacklist: 37 search_list = util.read_blacklist(args.blacklist) 38 else: 39 search_list = args.regexes 40 41 symbol_list = util.extract_or_load(args.symbol_list) 42 43 matching_count, report = match.find_and_report_matching( 44 symbol_list, search_list) 45 sys.stdout.write(report) 46 if matching_count != 0: 47 print('%d matching symbols found...' % matching_count) 48 49 50if __name__ == '__main__': 51 main() 52