Files
mbedtls/scripts/generate_config_checks.py
Gilles Peskine 30323afa6c Read current data rather than data about 4.0
It doesn't matter how a macro was used in a previous minor version of the
library. What matters is current information about options and internal
symbols, and information about past versions from which a macro may have
been removed.

The output is mostly the same, but:

* Macros that were options in 3.6, became internal in 4.0 and have now
  been completely removed are now shown as removed, not internal.
* Macros that were options in 3.6, were completely removed in 4.0, and are
  now back but internal, are now shown as internal, not removed.
* Macros that were options in 3.6, were removed in 4.0 and are back to
  being options are no longer rejected.
* Macros that were options in 3.6, were removed in 4.0 and are back to
  being internal derived macros in TF-PSA-Crypto are no longer rejected.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-01-05 16:29:21 +01:00

54 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""Generate C preprocessor code to check for bad configurations.
"""
from typing import Iterator
import framework_scripts_path # pylint: disable=unused-import
from mbedtls_framework.config_checks_generator import * \
#pylint: disable=wildcard-import,unused-wildcard-import
from mbedtls_framework import config_macros
class CryptoInternal(SubprojectInternal):
SUBPROJECT = 'TF-PSA-Crypto'
class CryptoOption(SubprojectOption):
SUBPROJECT = 'psa/crypto_config.h'
ALWAYS_ENABLED_SINCE_4_0 = frozenset([
'MBEDTLS_PSA_CRYPTO_CONFIG',
'MBEDTLS_USE_PSA_CRYPTO',
])
def checkers_for_removed_options() -> Iterator[Checker]:
"""Discover removed options. Yield corresponding checkers."""
previous_major = config_macros.History('mbedtls', '3.6')
current = config_macros.Current()
crypto = config_macros.Current('tf-psa-crypto')
old_public = previous_major.options()
new_public = current.options()
for option in sorted(old_public - new_public):
if option in ALWAYS_ENABLED_SINCE_4_0:
continue
if option in crypto.options():
yield CryptoOption(option)
elif option in crypto.internal():
yield CryptoInternal(option)
else:
yield Removed(option, 'Mbed TLS 4.0')
def all_checkers() -> Iterator[Checker]:
"""Yield all checkers."""
yield from checkers_for_removed_options()
MBEDTLS_CHECKS = BranchData(
header_directory='library',
header_prefix='mbedtls_',
project_cpp_prefix='MBEDTLS',
checkers=list(all_checkers()),
)
if __name__ == '__main__':
main(MBEDTLS_CHECKS)