Skip to content

Commit 63ad668

Browse files
authored
Merge pull request #321 from dgreen-arm/config_py
Replace config.pl by config.py
2 parents 0b3dd8d + adc82f3 commit 63ad668

17 files changed

+766
-429
lines changed

3rdparty/everest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(everest_src
1010

1111
list(APPEND everest_inc ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include/everest ${CMAKE_CURRENT_SOURCE_DIR}/include/everest/kremlib)
1212

13-
execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/config.h get MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED RESULT_VARIABLE result)
13+
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/config.py -f ${CMAKE_CURRENT_SOURCE_DIR}/../../include/mbedtls/config.h get MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED RESULT_VARIABLE result)
1414

1515
if(${result} EQUAL 0)
1616

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}"
4646
"${CTR_DRBG_128_BIT_KEY_WARN_L3}"
4747
"${WARNING_BORDER}")
4848

49-
find_package(PythonInterp)
50-
find_package(Perl)
51-
if(PERL_FOUND)
49+
# Python 3 is only needed here to check for configuration warnings.
50+
find_package(PythonInterp 3)
51+
if(PYTHONINTERP_FOUND)
5252

5353
# If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
54-
execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
54+
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.py -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
5555
RESULT_VARIABLE result)
5656
if(${result} EQUAL 0)
5757
message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING})
5858
endif()
5959

6060
# If NULL Entropy is configured, display an appropriate warning
61-
execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_TEST_NULL_ENTROPY
61+
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.py -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_TEST_NULL_ENTROPY
6262
RESULT_VARIABLE result)
6363
if(${result} EQUAL 0)
6464
message(WARNING ${NULL_ENTROPY_WARNING})

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ post_build:
7070
ifndef WINDOWS
7171

7272
# If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
73-
-scripts/config.pl get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
73+
-scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
7474
echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
7575

7676
# If NULL Entropy is configured, display an appropriate warning
77-
-scripts/config.pl get MBEDTLS_TEST_NULL_ENTROPY && ([ $$? -eq 0 ]) && \
77+
-scripts/config.py get MBEDTLS_TEST_NULL_ENTROPY && ([ $$? -eq 0 ]) && \
7878
echo '$(NULL_ENTROPY_WARNING)'
7979
endif
8080

include/mbedtls/check_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#endif
4646

4747
/* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
48-
* it would confuse config.pl. */
48+
* it would confuse config.py. */
4949
#if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
5050
!defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
5151
#define MBEDTLS_PLATFORM_SNPRINTF_ALT

scripts/apidoc_full.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919
CONFIG_BAK=${CONFIG_H}.bak
2020
cp -p $CONFIG_H $CONFIG_BAK
2121

22-
scripts/config.pl realfull
22+
scripts/config.py realfull
2323
make apidoc
2424

2525
mv $CONFIG_BAK $CONFIG_H

scripts/config.pl

Lines changed: 26 additions & 295 deletions
Original file line numberDiff line numberDiff line change
@@ -1,296 +1,27 @@
11
#!/usr/bin/env perl
2-
#
3-
# This file is part of mbed TLS (https://tls.mbed.org)
4-
#
5-
# Copyright (c) 2014-2016, ARM Limited, All Rights Reserved
6-
#
7-
# Purpose
8-
#
9-
# Comments and uncomments #define lines in the given header file and optionally
10-
# sets their value or can get the value. This is to provide scripting control of
11-
# what preprocessor symbols, and therefore what build time configuration flags
12-
# are set in the 'config.h' file.
13-
#
14-
# Usage: config.pl [-f <file> | --file <file>] [-o | --force]
15-
# [set <symbol> <value> | unset <symbol> | get <symbol> |
16-
# full | realfull]
17-
#
18-
# Full usage description provided below.
19-
#
20-
# The following options are disabled instead of enabled with "full".
21-
#
22-
# MBEDTLS_TEST_NULL_ENTROPY
23-
# MBEDTLS_DEPRECATED_REMOVED
24-
# MBEDTLS_HAVE_SSE2
25-
# MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
26-
# MBEDTLS_ECP_DP_M221_ENABLED
27-
# MBEDTLS_ECP_DP_M383_ENABLED
28-
# MBEDTLS_ECP_DP_M511_ENABLED
29-
# MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
30-
# MBEDTLS_NO_PLATFORM_ENTROPY
31-
# MBEDTLS_RSA_NO_CRT
32-
# MBEDTLS_PSA_CRYPTO_SPM
33-
# MBEDTLS_PSA_INJECT_ENTROPY
34-
# MBEDTLS_ECP_RESTARTABLE
35-
# and any symbol beginning _ALT
36-
#
37-
38-
use warnings;
39-
use strict;
40-
41-
my $config_file = "include/mbedtls/config.h";
42-
my $usage = <<EOU;
43-
$0 [-f <file> | --file <file>] [-o | --force]
44-
[set <symbol> <value> | unset <symbol> | get <symbol> |
45-
full | realfull | baremetal]
46-
47-
Commands
48-
set <symbol> [<value>] - Uncomments or adds a #define for the <symbol> to
49-
the configuration file, and optionally making it
50-
of <value>.
51-
If the symbol isn't present in the file an error
52-
is returned.
53-
unset <symbol> - Comments out the #define for the given symbol if
54-
present in the configuration file.
55-
get <symbol> - Finds the #define for the given symbol, returning
56-
an exitcode of 0 if the symbol is found, and 1 if
57-
not. The value of the symbol is output if one is
58-
specified in the configuration file.
59-
full - Uncomments all #define's in the configuration file
60-
excluding some reserved symbols, until the
61-
'Module configuration options' section
62-
realfull - Uncomments all #define's with no exclusions
63-
baremetal - Sets full configuration suitable for baremetal build.
64-
65-
Options
66-
-f | --file <filename> - The file or file path for the configuration file
67-
to edit. When omitted, the following default is
68-
used:
69-
$config_file
70-
-o | --force - If the symbol isn't present in the configuration
71-
file when setting its value, a #define is
72-
appended to the end of the file.
73-
74-
EOU
75-
76-
my @excluded = qw(
77-
MBEDTLS_TEST_NULL_ENTROPY
78-
MBEDTLS_DEPRECATED_REMOVED
79-
MBEDTLS_HAVE_SSE2
80-
MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
81-
MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
82-
MBEDTLS_ECP_DP_M221_ENABLED
83-
MBEDTLS_ECP_DP_M383_ENABLED
84-
MBEDTLS_ECP_DP_M511_ENABLED
85-
MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
86-
MBEDTLS_NO_PLATFORM_ENTROPY
87-
MBEDTLS_RSA_NO_CRT
88-
MBEDTLS_NO_UDBL_DIVISION
89-
MBEDTLS_NO_64BIT_MULTIPLICATION
90-
MBEDTLS_PSA_CRYPTO_SE_C
91-
MBEDTLS_PSA_CRYPTO_SPM
92-
MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
93-
MBEDTLS_PSA_INJECT_ENTROPY
94-
MBEDTLS_ECP_RESTARTABLE
95-
MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
96-
_ALT\s*$
97-
);
98-
99-
# Things that should be disabled in "baremetal"
100-
my @excluded_baremetal = qw(
101-
MBEDTLS_TIMING_C
102-
MBEDTLS_FS_IO
103-
MBEDTLS_ENTROPY_NV_SEED
104-
MBEDTLS_HAVE_TIME
105-
MBEDTLS_HAVE_TIME_DATE
106-
MBEDTLS_DEPRECATED_WARNING
107-
MBEDTLS_HAVEGE_C
108-
MBEDTLS_THREADING_C
109-
MBEDTLS_THREADING_PTHREAD
110-
MBEDTLS_MEMORY_BACKTRACE
111-
MBEDTLS_MEMORY_BUFFER_ALLOC_C
112-
MBEDTLS_PLATFORM_TIME_ALT
113-
MBEDTLS_PLATFORM_FPRINTF_ALT
114-
MBEDTLS_PSA_ITS_FILE_C
115-
MBEDTLS_PSA_CRYPTO_SE_C
116-
MBEDTLS_PSA_CRYPTO_STORAGE_C
117-
);
118-
119-
# Things that should be enabled in "full" even if they match @excluded
120-
my @non_excluded = qw(
121-
PLATFORM_[A-Z0-9]+_ALT
122-
);
123-
124-
# Things that should be enabled in "baremetal"
125-
my @non_excluded_baremetal = qw(
126-
MBEDTLS_NO_PLATFORM_ENTROPY
127-
);
128-
129-
# Process the command line arguments
130-
131-
my $force_option = 0;
132-
133-
my ($arg, $name, $value, $action);
134-
135-
while ($arg = shift) {
136-
137-
# Check if the argument is an option
138-
if ($arg eq "-f" || $arg eq "--file") {
139-
$config_file = shift;
140-
141-
-f $config_file or die "No such file: $config_file\n";
142-
143-
}
144-
elsif ($arg eq "-o" || $arg eq "--force") {
145-
$force_option = 1;
146-
147-
}
148-
else
149-
{
150-
# ...else assume it's a command
151-
$action = $arg;
152-
153-
if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) {
154-
# No additional parameters
155-
die $usage if @ARGV;
156-
157-
}
158-
elsif ($action eq "unset" || $action eq "get") {
159-
die $usage unless @ARGV;
160-
$name = shift;
161-
162-
}
163-
elsif ($action eq "set") {
164-
die $usage unless @ARGV;
165-
$name = shift;
166-
$value = shift if @ARGV;
167-
168-
}
169-
else {
170-
die "Command '$action' not recognised.\n\n".$usage;
171-
}
172-
}
173-
}
174-
175-
# If no command was specified, exit...
176-
if ( not defined($action) ){ die $usage; }
177-
178-
# Check the config file is present
179-
if (! -f $config_file) {
180-
181-
chdir '..' or die;
182-
183-
# Confirm this is the project root directory and try again
184-
if ( !(-d 'scripts' && -d 'include' && -d 'library' && -f $config_file) ) {
185-
die "If no file specified, must be run from the project root or scripts directory.\n";
186-
}
187-
}
188-
189-
190-
# Now read the file and process the contents
191-
192-
open my $config_read, '<', $config_file or die "read $config_file: $!\n";
193-
my @config_lines = <$config_read>;
194-
close $config_read;
195-
196-
# Add required baremetal symbols to the list that is included.
197-
if ( $action eq "baremetal" ) {
198-
@non_excluded = ( @non_excluded, @non_excluded_baremetal );
199-
}
200-
201-
my ($exclude_re, $no_exclude_re, $exclude_baremetal_re);
202-
if ($action eq "realfull") {
203-
$exclude_re = qr/^$/;
204-
$no_exclude_re = qr/./;
205-
} else {
206-
$exclude_re = join '|', @excluded;
207-
$no_exclude_re = join '|', @non_excluded;
208-
}
209-
if ( $action eq "baremetal" ) {
210-
$exclude_baremetal_re = join '|', @excluded_baremetal;
211-
}
212-
213-
my $config_write = undef;
214-
if ($action ne "get") {
215-
open $config_write, '>', $config_file or die "write $config_file: $!\n";
216-
}
217-
218-
my $done;
219-
for my $line (@config_lines) {
220-
if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) {
221-
if ($line =~ /name SECTION: Module configuration options/) {
222-
$done = 1;
223-
}
224-
225-
if (!$done && $line =~ m!^//\s?#define! &&
226-
( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) &&
227-
( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) {
228-
$line =~ s!^//\s?!!;
229-
}
230-
if (!$done && $line =~ m!^\s?#define! &&
231-
! ( ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) &&
232-
( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) ) {
233-
$line =~ s!^!//!;
234-
}
235-
} elsif ($action eq "unset") {
236-
if (!$done && $line =~ /^\s*#define\s*$name\b/) {
237-
$line = '//' . $line;
238-
$done = 1;
239-
}
240-
} elsif (!$done && $action eq "set") {
241-
if ($line =~ m!^(?://)?\s*#define\s*$name\b!) {
242-
$line = "#define $name";
243-
$line .= " $value" if defined $value && $value ne "";
244-
$line .= "\n";
245-
$done = 1;
246-
}
247-
} elsif (!$done && $action eq "get") {
248-
if ($line =~ /^\s*#define\s*$name(?:\s+(.*?))\s*(?:$|\/\*|\/\/)/) {
249-
$value = $1;
250-
$done = 1;
251-
}
252-
}
253-
254-
if (defined $config_write) {
255-
print $config_write $line or die "write $config_file: $!\n";
256-
}
257-
}
258-
259-
# Did the set command work?
260-
if ($action eq "set" && $force_option && !$done) {
261-
262-
# If the force option was set, append the symbol to the end of the file
263-
my $line = "#define $name";
264-
$line .= " $value" if defined $value && $value ne "";
265-
$line .= "\n";
266-
$done = 1;
267-
268-
print $config_write $line or die "write $config_file: $!\n";
269-
}
270-
271-
if (defined $config_write) {
272-
close $config_write or die "close $config_file: $!\n";
273-
}
274-
275-
if ($action eq "get") {
276-
if ($done) {
277-
if ($value ne '') {
278-
print "$value\n";
279-
}
280-
exit 0;
281-
} else {
282-
# If the symbol was not found, return an error
283-
exit 1;
284-
}
285-
}
286-
287-
if ($action eq "full" && !$done) {
288-
die "Configuration section was not found in $config_file\n";
289-
290-
}
291-
292-
if ($action ne "full" && $action ne "unset" && !$done) {
293-
die "A #define for the symbol $name was not found in $config_file\n";
294-
}
295-
296-
__END__
2+
# Backward compatibility redirection
3+
4+
## Copyright (C) 2019, ARM Limited, All Rights Reserved
5+
## SPDX-License-Identifier: Apache-2.0
6+
##
7+
## Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
## not use this file except in compliance with the License.
9+
## You may obtain a copy of the License at
10+
##
11+
## http://www.apache.org/licenses/LICENSE-2.0
12+
##
13+
## Unless required by applicable law or agreed to in writing, software
14+
## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
## See the License for the specific language governing permissions and
17+
## limitations under the License.
18+
##
19+
## This file is part of Mbed TLS (https://tls.mbed.org)
20+
21+
my $py = $0;
22+
$py =~ s/\.pl$/.py/;
23+
exec 'python3', $py, @ARGV;
24+
print STDERR "$0: python3: $!\n";
25+
exec 'python', $py, @ARGV;
26+
print STDERR "$0: python: $!\n";
27+
exit 127;

0 commit comments

Comments
 (0)