[NFC][Py Reformat] Reformat python files in libcxx/libcxxabi
[llvm-project.git] / libcxx / utils / generate_abi_list.py
blob94e49dca60af14a4052b24cba86af229bc8cc039
1 #!/usr/bin/env python
2 # ===----------------------------------------------------------------------===##
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
8 # ===----------------------------------------------------------------------===##
10 import argparse
11 import io
12 import libcxx.sym_check.extract
13 import libcxx.sym_check.util
14 import pprint
15 import sys
18 def OutputFile(file):
19 if isinstance(file, io.IOBase):
20 return file
21 assert isinstance(file, str), "Got object {} which is not a str".format(file)
22 return open(file, "w", newline="\n")
25 def main(argv):
26 parser = argparse.ArgumentParser(
27 description="Extract a list of symbols from a shared library."
29 parser.add_argument(
30 "library", metavar="LIB", type=str, help="The library to extract symbols from."
32 parser.add_argument(
33 "-o",
34 "--output",
35 dest="output",
36 type=OutputFile,
37 default=sys.stdout,
38 help="The output file to write the symbols to. It is overwritten if it already exists. "
39 "If no file is specified, the results are written to standard output.",
41 args = parser.parse_args(argv)
43 symbols = libcxx.sym_check.extract.extract_symbols(args.library)
44 symbols, _ = libcxx.sym_check.util.filter_stdlib_symbols(symbols)
46 lines = [pprint.pformat(sym, width=99999) for sym in symbols]
47 args.output.writelines("\n".join(sorted(lines)))
50 if __name__ == "__main__":
51 main(sys.argv[1:])