Skip to content

Commit 0bdc712

Browse files
authored
Merge pull request #12998 from sbutcher-arm/fix-adjust-config
Fix Mbed TLS `adjust-config.sh` script
2 parents 66343b0 + 5b03168 commit 0bdc712

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

features/mbedtls/importer/adjust-config.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ conf() {
2525
$SCRIPT -f $FILE --force $@
2626
}
2727

28-
add_code() {
28+
# Add code before the matching line
29+
prepend_code() {
30+
MATCH_PATTERN="$1"
31+
shift
32+
CODE=$(IFS=""; printf "%s" "$*")
33+
34+
perl -i -pe \
35+
"s/$MATCH_PATTERN/$CODE$MATCH_PATTERN/igs" \
36+
"$FILE"
37+
}
38+
39+
# Add code after the matching line
40+
append_code() {
2941
MATCH_PATTERN="$1"
3042
shift
3143
CODE=$(IFS=""; printf "%s" "$*")
@@ -37,7 +49,7 @@ add_code() {
3749

3850
# add an #ifndef to include config-no-entropy.h when the target does not have
3951
# an entropy source we can use.
40-
add_code \
52+
append_code \
4153
"#ifndef MBEDTLS_CONFIG_H\n" \
4254
"\n" \
4355
"#include \"platform\/inc\/platform_mbed.h\"\n" \
@@ -56,8 +68,8 @@ add_code
5668
"\n" \
5769
"#else\n"
5870

59-
add_code \
60-
"#include \"mbedtls\/check_config.h\"\n" \
71+
prepend_code \
72+
"#endif \/\* MBEDTLS_CONFIG_H \*\/" \
6173
"\n" \
6274
"#endif \/* !MBEDTLS_ENTROPY_HARDWARE_ALT && !MBEDTLS_TEST_NULL_ENTROPY && !MBEDTLS_ENTROPY_NV_SEED *\/\n" \
6375
"\n" \
@@ -70,7 +82,8 @@ add_code
7082
" !defined(MBEDTLS_ENTROPY_HARDWARE_ALT) && !defined(MBEDTLS_ENTROPY_NV_SEED)\n" \
7183
"#error \"No entropy source was found at build time, so TLS \" \\\\\n" \
7284
" \"functionality is not available\"\n" \
73-
"#endif\n"
85+
"#endif\n" \
86+
"\n"
7487

7588
# not supported on mbed OS, nor used by mbed Client
7689
conf unset MBEDTLS_NET_C

0 commit comments

Comments
 (0)