Felix Conway | 1ef121c | 2025-04-09 09:51:13 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Felix Conway | e6605f9 | 2025-04-08 14:26:29 +0100 | [diff] [blame] | 2 | |
| 3 | # Perl code that is executed to transform each original line from a library |
| 4 | # source file into the corresponding line in the test driver copy of the |
| 5 | # library. Add a LIBTESTDRIVER1_/libtestdriver1_ to mbedtls_xxx and psa_xxx |
| 6 | # symbols. |
| 7 | |
| 8 | # Copyright The Mbed TLS Contributors |
| 9 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 10 | |
| 11 | use warnings; |
| 12 | use File::Basename; |
| 13 | |
| 14 | my @public_files = map { basename($_) } glob("../tf-psa-crypto/include/mbedtls/*.h"); |
| 15 | |
| 16 | my $public_files_regex = join('|', map { quotemeta($_) } @public_files); |
| 17 | |
| 18 | while (<>) { |
| 19 | s!^(\s*#\s*include\s*[\"<])mbedtls/build_info.h!${1}libtestdriver1/include/mbedtls/build_info.h!; |
| 20 | s!^(\s*#\s*include\s*[\"<])mbedtls/mbedtls_config.h!${1}libtestdriver1/include/mbedtls/mbedtls_config.h!; |
| 21 | s!^(\s*#\s*include\s*[\"<])mbedtls/config_adjust_x509.h!${1}libtestdriver1/include/mbedtls/config_adjust_x509.h!; |
| 22 | s!^(\s*#\s*include\s*[\"<])mbedtls/config_adjust_ssl.h!${1}libtestdriver1/include/mbedtls/config_adjust_ssl.h!; |
| 23 | s!^(\s*#\s*include\s*[\"<])mbedtls/check_config.h!${1}libtestdriver1/include/mbedtls/check_config.h!; |
| 24 | # Files in include/mbedtls and drivers/builtin/include/mbedtls are both |
| 25 | # included in files via #include mbedtls/<file>.h, so when expanding to the |
| 26 | # full path make sure that files in include/mbedtls are not expanded |
| 27 | # to driver/builtin/include/mbedtls. |
| 28 | if ( $public_files_regex ) { |
| 29 | s!^(\s*#\s*include\s*[\"<])mbedtls/($public_files_regex)!${1}libtestdriver1/tf-psa-crypto/include/mbedtls/${2}!; |
| 30 | } |
| 31 | s!^(\s*#\s*include\s*[\"<])mbedtls/!${1}libtestdriver1/tf-psa-crypto/drivers/builtin/include/mbedtls/!; |
| 32 | s!^(\s*#\s*include\s*[\"<])psa/!${1}libtestdriver1/tf-psa-crypto/include/psa/!; |
| 33 | s!^(\s*#\s*include\s*[\"<])tf-psa-crypto/!${1}libtestdriver1/tf-psa-crypto/include/tf-psa-crypto/!; |
| 34 | if (/^\s*#\s*include/) { |
| 35 | print; |
| 36 | next; |
| 37 | } |
| 38 | s/\b(?=MBEDTLS_|PSA_|TF_PSA_CRYPTO_)/LIBTESTDRIVER1_/g; |
| 39 | s/\b(?=mbedtls_|psa_|tf_psa_crypto_)/libtestdriver1_/g; |
| 40 | print; |
| 41 | } |