sym_match.py 1.7 KB

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