list_internal_identifiers.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. This script generates a file called identifiers that contains all Mbed TLS
  19. identifiers found on internal headers. This is the equivalent of what was
  20. previously `list-identifiers.sh --internal`, and is useful for generating an
  21. exclusion file list for ABI/API checking, since we do not promise compatibility
  22. for them.
  23. It uses the CodeParser class from check_names.py to perform the parsing.
  24. The script returns 0 on success, 1 if there is a script error.
  25. Must be run from Mbed TLS root.
  26. """
  27. import argparse
  28. import logging
  29. from check_names import CodeParser
  30. def main():
  31. parser = argparse.ArgumentParser(
  32. formatter_class=argparse.RawDescriptionHelpFormatter,
  33. description=(
  34. "This script writes a list of parsed identifiers in internal "
  35. "headers to \"identifiers\". This is useful for generating a list "
  36. "of names to exclude from API/ABI compatibility checking. "))
  37. parser.parse_args()
  38. name_check = CodeParser(logging.getLogger())
  39. result = name_check.parse_identifiers([
  40. "include/mbedtls/*_internal.h",
  41. "library/*.h"
  42. ])[0]
  43. result.sort(key=lambda x: x.name)
  44. identifiers = ["{}\n".format(match.name) for match in result]
  45. with open("identifiers", "w", encoding="utf-8") as f:
  46. f.writelines(identifiers)
  47. if __name__ == "__main__":
  48. main()