23
23
import stat
24
24
import re
25
25
import shutil
26
- from distutils .dir_util import copy_tree
27
26
28
27
def copy_of_psa_headers (mbedtls_root_path , psa_crypto_root_path ):
29
28
source_path = os .path .join (mbedtls_root_path , "include" , "psa" )
@@ -91,33 +90,38 @@ def copy_from_scripts(mbedtls_root_path, psa_crypto_root_path):
91
90
source_path = os .path .join (mbedtls_root_path , "scripts" )
92
91
destination_path = os .path .join (psa_crypto_root_path , "scripts" )
93
92
94
- copy_tree (os .path .join (source_path , "data_files" , "driver_jsons" ),
95
- os .path .join (destination_path , "data_files" , "driver_jsons" ))
96
- copy_tree (os .path .join (source_path , "data_files" , "driver_templates" ),
97
- os .path .join (destination_path , "data_files" , "driver_templates" ))
93
+ shutil .copytree (os .path .join (source_path , "data_files" , "driver_jsons" ),
94
+ os .path .join (destination_path , "data_files" , "driver_jsons" ),
95
+ dirs_exist_ok = True )
96
+ shutil .copytree (os .path .join (source_path , "data_files" , "driver_templates" ),
97
+ os .path .join (destination_path , "data_files" , "driver_templates" ),
98
+ dirs_exist_ok = True )
98
99
99
100
shutil .copy2 (os .path .join (source_path , "generate_driver_wrappers.py" ), destination_path )
100
101
shutil .copy2 (os .path .join (source_path , "generate_psa_constants.py" ), destination_path )
101
102
shutil .copy2 (os .path .join (source_path , "output_env.sh" ), destination_path )
102
103
shutil .copy2 (os .path .join (source_path , "config.py" ), destination_path )
103
104
104
- copy_tree (os .path .join (source_path , "mbedtls_dev" ),
105
- os .path .join (destination_path , "mbedtls_dev" ))
105
+ shutil . copytree (os .path .join (source_path , "mbedtls_dev" ),
106
+ os .path .join (destination_path , "mbedtls_dev" ), dirs_exist_ok = True )
106
107
107
108
def copy_from_tests (mbedtls_root_path , psa_crypto_root_path ):
108
109
source_path = os .path .join (mbedtls_root_path , "tests" )
109
110
destination_path = os .path .join (psa_crypto_root_path , "tests" )
110
111
111
112
shutil .copy2 (os .path .join (source_path , "seedfile" ), destination_path )
112
113
113
- copy_tree ( os .path .join ( source_path , "include" ),
114
- os .path .join ( destination_path , "include" ) )
114
+ shutil .copytree (os .path .join (source_path , "include" ),
115
+ os .path .join (destination_path , "include" ),
116
+ dirs_exist_ok = True )
115
117
116
- copy_tree ( os .path .join ( source_path , "scripts" ),
117
- os .path .join ( destination_path , "scripts" ) )
118
+ shutil .copytree (os .path .join (source_path , "scripts" ),
119
+ os .path .join (destination_path , "scripts" ),
120
+ dirs_exist_ok = True )
118
121
119
- copy_tree ( os .path .join ( source_path , "src" ),
120
- os .path .join ( destination_path , "src" ) )
122
+ shutil .copytree (os .path .join (source_path , "src" ),
123
+ os .path .join (destination_path , "src" ),
124
+ dirs_exist_ok = True )
121
125
122
126
tests_suites_files = filter (lambda file_ : re .match (
123
127
"test_suite_psa_crypto.*|helpers\.function|" \
@@ -150,9 +154,9 @@ def replace_all_sh_components(psa_crypto_root_path):
150
154
after_components = 0
151
155
components_start = re .compile (r"#### Basic checks" )
152
156
components_end = re .compile (r"#### Termination" )
153
- new_all_sh = open (os .path .join (tests_scripts_path , "all.sh" ), 'x' )
154
157
155
- with open (os .path .join (tests_scripts_path , "all.sh.bak" ), 'rt' ) as all_sh :
158
+ with open (os .path .join (tests_scripts_path , "all.sh" ), 'x' ) as new_all_sh , \
159
+ open (os .path .join (tests_scripts_path , "all.sh.bak" ), 'rt' ) as all_sh :
156
160
for line in all_sh :
157
161
if before_components :
158
162
if components_start .match (line ) != None :
@@ -176,7 +180,6 @@ def replace_all_sh_components(psa_crypto_root_path):
176
180
if after_components :
177
181
new_all_sh .write (line )
178
182
179
- new_all_sh .close ()
180
183
os .chmod (os .path .join (tests_scripts_path , "all.sh" ), stat .S_IEXEC | stat .S_IREAD | stat .S_IWRITE )
181
184
182
185
def extend_config_psa (psa_crypto_root_path ):
@@ -187,9 +190,11 @@ def extend_config_psa(psa_crypto_root_path):
187
190
if_defined_mbedtls_psa_crypto_config_file = re .compile ("#if defined\(MBEDTLS_PSA_CRYPTO_CONFIG_FILE\)" )
188
191
include_mbedtls_psa_crypto_config_file = re .compile ("#include MBEDTLS_PSA_CRYPTO_CONFIG_FILE" )
189
192
ext_placeholder = re .compile (".*BELOW THIS LINE - PLACEHOLDER FOR PSA-CRYPTO ADDITIONAL CONFIG OPTIONS TRANSLATION" )
190
- new_config_psa = open (os .path .join (include_mbedtls_path , "config_psa.h" ), 'x' )
193
+ endif_mbedtls_psa_crypto_config = re .compile ("#endif /\* MBEDTLS_PSA_CRYPTO_CONFIG \*/" )
194
+
195
+ with open (os .path .join (include_mbedtls_path , "config_psa.h" ), 'x' ) as new_config_psa , \
196
+ open (os .path .join (include_mbedtls_path , "config_psa.h.bak" ), 'rt' ) as config_psa :
191
197
192
- with open (os .path .join (include_mbedtls_path , "config_psa.h.bak" ), 'rt' ) as config_psa :
193
198
for line in config_psa :
194
199
if if_defined_mbedtls_psa_crypto_config_file .match (line ) != None :
195
200
new_config_psa .write ("#if defined(PSA_CRYPTO_CONFIG_FILE)\n " )
@@ -200,15 +205,17 @@ def extend_config_psa(psa_crypto_root_path):
200
205
else :
201
206
new_config_psa .write (line )
202
207
203
- config_psa .close ()
204
-
205
- with open (os .path .join (psa_crypto_root_path , "drivers" , "builtin" , "config_psa_ext.h" ), 'rt' ) as ext :
206
- for line in ext :
207
- new_config_psa .write (line )
208
+ with open (os .path .join (psa_crypto_root_path , "drivers" , "builtin" , "config_psa_ext.h" ), 'rt' ) as ext :
209
+ for line in ext :
210
+ new_config_psa .write (line )
208
211
209
- new_config_psa .write ("\n #endif /* MBEDTLS_PSA_CRYPTO_CONFIG */" )
210
- new_config_psa .write ("\n #endif /* MBEDTLS_CONFIG_PSA_H */" )
211
- new_config_psa .close ()
212
+ trailer = False
213
+ for line in config_psa :
214
+ if endif_mbedtls_psa_crypto_config .match (line ) != None :
215
+ new_config_psa .write ("\n " )
216
+ trailer = True
217
+ if trailer :
218
+ new_config_psa .write (line )
212
219
213
220
def main ():
214
221
parser = argparse .ArgumentParser (
0 commit comments