1#!/usr/bin/env python3
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
6"""
7This script generates a file called identifiers that contains all Mbed TLS
8identifiers found on internal headers. This is the equivalent of what was
9previously `list-identifiers.sh --internal`, and is useful for generating an
10exclusion file list for ABI/API checking, since we do not promise compatibility
11for them.
12
13It uses the CodeParser class from check_names.py to perform the parsing.
14
15The script returns 0 on success, 1 if there is a script error.
16Must be run from Mbed TLS root.
17"""
18
19import argparse
20import logging
21from check_names import CodeParser
22
23def main():
24    parser = argparse.ArgumentParser(
25        formatter_class=argparse.RawDescriptionHelpFormatter,
26        description=(
27            "This script writes a list of parsed identifiers in internal "
28            "headers to \"identifiers\". This is useful for generating a list "
29            "of names to exclude from API/ABI compatibility checking. "))
30
31    parser.parse_args()
32
33    name_check = CodeParser(logging.getLogger())
34    result = name_check.parse_identifiers([
35        "include/mbedtls/*_internal.h",
36        "library/*.h"
37    ])[0]
38    result.sort(key=lambda x: x.name)
39
40    identifiers = ["{}\n".format(match.name) for match in result]
41    with open("identifiers", "w", encoding="utf-8") as f:
42        f.writelines(identifiers)
43
44if __name__ == "__main__":
45    main()
46