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 sym_diff - Compare two symbol lists and output the differences.
13 from argparse
import ArgumentParser
15 from libcxx
.sym_check
import diff
, util
19 parser
= ArgumentParser(
20 description
='Extract a list of symbols from a shared library.')
22 '--names-only', dest
='names_only',
23 help='Only print symbol names',
24 action
='store_true', default
=False)
26 '--removed-only', dest
='removed_only',
27 help='Only print removed symbols',
28 action
='store_true', default
=False)
29 parser
.add_argument('--only-stdlib-symbols', dest
='only_stdlib',
30 help="Filter all symbols not related to the stdlib",
31 action
='store_true', default
=False)
32 parser
.add_argument('--strict', dest
='strict',
33 help="Exit with a non-zero status if any symbols "
35 action
='store_true', default
=False)
37 '-o', '--output', dest
='output',
38 help='The output file. stdout is used if not given',
39 type=str, action
='store', default
=None)
41 '--demangle', dest
='demangle', action
='store_true', default
=False)
43 'old_syms', metavar
='old-syms', type=str,
44 help='The file containing the old symbol list or a library')
46 'new_syms', metavar
='new-syms', type=str,
47 help='The file containing the new symbol list or a library')
48 args
= parser
.parse_args()
50 old_syms_list
= util
.extract_or_load(args
.old_syms
)
51 new_syms_list
= util
.extract_or_load(args
.new_syms
)
54 old_syms_list
, _
= util
.filter_stdlib_symbols(old_syms_list
)
55 new_syms_list
, _
= util
.filter_stdlib_symbols(new_syms_list
)
57 added
, removed
, changed
= diff
.diff(old_syms_list
, new_syms_list
)
60 report
, is_break
, is_different
= diff
.report_diff(
61 added
, removed
, changed
, names_only
=args
.names_only
,
62 demangle
=args
.demangle
)
63 if args
.output
is None:
66 with
open(args
.output
, 'w') as f
:
67 f
.write(report
+ '\n')
68 exit_code
= 1 if is_break
or (args
.strict
and is_different
) else 0
71 if __name__
== '__main__':