1#!/usr/bin/env python3
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""
19This script generates a file called identifiers that contains all Mbed TLS
20identifiers found on internal headers. This is the equivalent of what was
21previously `list-identifiers.sh --internal`, and is useful for generating an
22exclusion file list for ABI/API checking, since we do not promise compatibility
23for them.
24
25It uses the CodeParser class from check_names.py to perform the parsing.
26
27The script returns 0 on success, 1 if there is a script error.
28Must be run from Mbed TLS root.
29"""
30
31import argparse
32import logging
33from check_names import CodeParser
34
35def main():
36    parser = argparse.ArgumentParser(
37        formatter_class=argparse.RawDescriptionHelpFormatter,
38        description=(
39            "This script writes a list of parsed identifiers in internal "
40            "headers to \"identifiers\". This is useful for generating a list "
41            "of names to exclude from API/ABI compatibility checking. "))
42
43    parser.parse_args()
44
45    name_check = CodeParser(logging.getLogger())
46    result = name_check.parse_identifiers([
47        "include/mbedtls/*_internal.h",
48        "library/*.h"
49    ])
50    result.sort(key=lambda x: x.name)
51
52    identifiers = ["{}\n".format(match.name) for match in result]
53    with open("identifiers", "w", encoding="utf-8") as f:
54        f.writelines(identifiers)
55
56if __name__ == "__main__":
57    main()
58