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."
25 help="Only print symbol names",
32 help="Only print removed symbols",
37 "--only-stdlib-symbols",
39 help="Filter all symbols not related to the stdlib",
46 help="Exit with a non-zero status if any symbols " "differ",
54 help="The output file. stdout is used if not given",
60 "--demangle", dest
="demangle", action
="store_true", default
=False
66 help="The file containing the old symbol list or a library",
72 help="The file containing the new symbol list or a library",
74 args
= parser
.parse_args()
76 old_syms_list
= util
.extract_or_load(args
.old_syms
)
77 new_syms_list
= util
.extract_or_load(args
.new_syms
)
80 old_syms_list
, _
= util
.filter_stdlib_symbols(old_syms_list
)
81 new_syms_list
, _
= util
.filter_stdlib_symbols(new_syms_list
)
83 added
, removed
, changed
= diff
.diff(old_syms_list
, new_syms_list
)
86 report
, is_break
, is_different
= diff
.report_diff(
87 added
, removed
, changed
, names_only
=args
.names_only
, demangle
=args
.demangle
89 if args
.output
is None:
92 with
open(args
.output
, "w") as f
:
93 f
.write(report
+ "\n")
94 exit_code
= 1 if is_break
or (args
.strict
and is_different
) else 0
98 if __name__
== "__main__":