1#!/usr/bin/env python 2#===----------------------------------------------------------------------===## 3# 4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5# See https://llvm.org/LICENSE.txt for license information. 6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7# 8#===----------------------------------------------------------------------===## 9 10""" 11sym_match - Match all symbols in a list against a list of regexes. 12""" 13from argparse import ArgumentParser 14import sys 15from libcxx.sym_check import util, match, extract 16 17 18def main(): 19 parser = ArgumentParser( 20 description='Extract a list of symbols from a shared library.') 21 parser.add_argument( 22 '--blacklist', dest='blacklist', 23 type=str, action='store', default=None) 24 parser.add_argument( 25 'symbol_list', metavar='symbol_list', type=str, 26 help='The file containing the old symbol list') 27 parser.add_argument( 28 'regexes', metavar='regexes', default=[], nargs='*', 29 help='The file containing the new symbol list or a library') 30 args = parser.parse_args() 31 32 if not args.regexes and args.blacklist is None: 33 sys.stderr.write('Either a regex or a blacklist must be specified.\n') 34 sys.exit(1) 35 if args.blacklist: 36 search_list = util.read_blacklist(args.blacklist) 37 else: 38 search_list = args.regexes 39 40 symbol_list = util.extract_or_load(args.symbol_list) 41 42 matching_count, report = match.find_and_report_matching( 43 symbol_list, search_list) 44 sys.stdout.write(report) 45 if matching_count != 0: 46 print('%d matching symbols found...' % matching_count) 47 48 49if __name__ == '__main__': 50 main() 51