20
20
import sys
21
21
import shutil
22
22
import logging
23
- from argparse import ArgumentParser
23
+ import argparse
24
24
25
25
FNULL = open (os .devnull , 'w' )
26
26
ROOT = os .path .abspath (os .path .join (os .path .dirname (__file__ ),
@@ -89,13 +89,14 @@ def _get_psa_secure_targets_list():
89
89
Target .get_target (t ).is_PSA_secure_target ]
90
90
91
91
92
- def _get_default_image_build_command (target , toolchain , profile ):
92
+ def _get_default_image_build_command (target , toolchain , profile , args ):
93
93
"""
94
94
Creates a build command for a default image.
95
95
96
96
:param target: target to be built.
97
97
:param toolchain: toolchain to be used.
98
98
:param profile: build profile.
99
+ :param args: list of extra arguments.
99
100
:return: Build command in a list form.
100
101
"""
101
102
cmd = [
@@ -112,7 +113,22 @@ def _get_default_image_build_command(target, toolchain, profile):
112
113
else :
113
114
cmd += ['--artifact-name' , 'psa_release_1.0' ]
114
115
115
- return cmd
116
+ return cmd + args
117
+
118
+
119
+ def verbose_check_call (cmd , check_call = True ):
120
+ """
121
+
122
+ :param cmd: command to run as a list
123
+ :param check_call: choose subprocess method (call/check_call)
124
+ :return: return code of the executed command
125
+ """
126
+ logger .info ('Running: {}' .format (' ' .join (cmd )))
127
+ if check_call :
128
+ return subprocess .check_call (cmd , stdout = subprocess_output ,
129
+ stderr = subprocess_err )
130
+
131
+ return subprocess .call (cmd , stdout = subprocess_output , stderr = subprocess_err )
116
132
117
133
118
134
def get_mbed_official_psa_release (target = None ):
@@ -143,19 +159,19 @@ def create_mbed_ignore(build_dir):
143
159
f .write ('*\n ' )
144
160
145
161
146
- def build_tests_mbed_spm_platform (target , toolchain , profile ):
162
+ def build_tests_mbed_spm_platform (target , toolchain , profile , args ):
147
163
"""
148
164
Builds Secure images for MBED-SPM target.
149
165
150
166
:param target: target to be built.
151
167
:param toolchain: toolchain to be used.
152
168
:param profile: build profile.
169
+ :param args: list of extra arguments.
153
170
"""
154
171
logger .info (
155
172
"Building tests images({}) for {} using {} with {} profile" .format (
156
173
MBED_PSA_TESTS , target , toolchain , profile ))
157
-
158
- subprocess .check_call ([
174
+ cmd = [
159
175
sys .executable , TEST_PY_LOCATTION ,
160
176
'--greentea' ,
161
177
'--profile' , profile ,
@@ -167,30 +183,30 @@ def build_tests_mbed_spm_platform(target, toolchain, profile):
167
183
target , 'test_spec.json' ),
168
184
'--build-data' , os .path .join (ROOT , 'BUILD' , 'tests' ,
169
185
target , 'build_data.json' ),
170
- '-n' , MBED_PSA_TESTS
171
- ], stdout = subprocess_output , stderr = subprocess_err )
172
-
186
+ '-n' , MBED_PSA_TESTS ] + args
173
187
188
+ verbose_check_call (cmd )
174
189
logger .info (
175
190
"Finished building tests images({}) for {} successfully" .format (
176
191
MBED_PSA_TESTS , target ))
177
192
178
193
179
- def build_tests_tfm_platform (target , toolchain , profile ):
194
+ def build_tests_tfm_platform (target , toolchain , profile , args ):
180
195
"""
181
196
Builds Secure images for TF-M target.
182
197
183
198
:param target: target to be built.
184
199
:param toolchain: toolchain to be used.
185
200
:param profile: build profile.
201
+ :param args: list of extra arguments.
186
202
"""
187
203
for test in TFM_TESTS .keys ():
188
204
logger .info (
189
205
"Building tests image({}) for {} using {} with {} profile" .format (
190
206
test , target , toolchain , profile ))
191
207
192
208
test_defines = ['-D{}' .format (define ) for define in TFM_TESTS [test ]]
193
- subprocess . check_call ( [
209
+ cmd = [
194
210
sys .executable , TEST_PY_LOCATTION ,
195
211
'--greentea' ,
196
212
'--profile' , profile ,
@@ -203,9 +219,9 @@ def build_tests_tfm_platform(target, toolchain, profile):
203
219
'--build-data' , os .path .join (ROOT , 'BUILD' , 'tests' ,
204
220
target , 'build_data.json' ),
205
221
'-n' , test ,
206
- '--app-config' , TFM_MBED_APP ] + test_defines ,
207
- stdout = subprocess_output , stderr = subprocess_err )
222
+ '--app-config' , TFM_MBED_APP ] + test_defines + args
208
223
224
+ verbose_check_call (cmd )
209
225
logger .info (
210
226
"Finished Building tests image({}) for {}" .format (test , target ))
211
227
@@ -218,36 +234,33 @@ def commit_binaries(target, delivery_dir):
218
234
:param delivery_dir: Secure images should be moved to this folder
219
235
by the build system.
220
236
"""
221
- changes_made = subprocess . call ([
237
+ changes_made = verbose_check_call ([
222
238
'git' ,
223
239
'-C' , ROOT ,
224
240
'diff' , '--exit-code' , '--quiet' ,
225
- delivery_dir
226
- ], stdout = subprocess_output , stderr = subprocess_err )
241
+ delivery_dir ], check_call = False )
227
242
228
243
if changes_made :
229
244
logger .info ("Change in images for {} has been detected" .format (target ))
230
- subprocess . check_call ([
245
+ verbose_check_call ([
231
246
'git' ,
232
247
'-C' , ROOT ,
233
- 'add' , os .path .relpath (delivery_dir , ROOT )
234
- ], stdout = subprocess_output , stderr = subprocess_err )
248
+ 'add' , os .path .relpath (delivery_dir , ROOT )])
235
249
236
250
logger .info ("Committing images for {}" .format (target ))
237
251
commit_message = '--message="Update secure binaries for {}"' .format (
238
252
target )
239
- subprocess . check_call ([
253
+ verbose_check_call ([
240
254
'git' ,
241
255
'-C' , ROOT ,
242
256
'commit' ,
243
- commit_message
244
- ], stdout = subprocess_output , stderr = subprocess_err )
257
+ commit_message ])
245
258
else :
246
259
logger .info ("No changes detected for {}, Skipping commit" .format (target ))
247
260
248
261
249
- def build_psa_platform (target , toolchain , delivery_dir , debug = False ,
250
- git_commit = False , skip_tests = False ):
262
+ def build_psa_platform (target , toolchain , delivery_dir , debug , git_commit ,
263
+ skip_tests , args ):
251
264
"""
252
265
Calls the correct build function and commits if requested.
253
266
@@ -257,21 +270,20 @@ def build_psa_platform(target, toolchain, delivery_dir, debug=False,
257
270
:param debug: Build with debug profile.
258
271
:param git_commit: Commit the changes.
259
272
:param skip_tests: skip the test images build phase.
273
+ :param args: list of extra arguments.
260
274
"""
261
275
profile = 'debug' if debug else 'release'
262
276
if not skip_tests :
263
277
if _psa_backend (target ) is 'TFM' :
264
- build_tests_tfm_platform (target , toolchain , profile )
278
+ build_tests_tfm_platform (target , toolchain , profile , args )
265
279
else :
266
- build_tests_mbed_spm_platform (target , toolchain , profile )
280
+ build_tests_mbed_spm_platform (target , toolchain , profile , args )
267
281
268
282
logger .info ("Building default image for {} using {} with {} profile" .format (
269
283
target , toolchain , profile ))
270
284
271
- subprocess .check_call (
272
- _get_default_image_build_command (target , toolchain , profile ),
273
- stdout = subprocess_output , stderr = subprocess_err )
274
-
285
+ cmd = _get_default_image_build_command (target , toolchain , profile , args )
286
+ verbose_check_call (cmd )
275
287
logger .info (
276
288
"Finished building default image for {} successfully" .format (target ))
277
289
@@ -280,7 +292,7 @@ def build_psa_platform(target, toolchain, delivery_dir, debug=False,
280
292
281
293
282
294
def get_parser ():
283
- parser = ArgumentParser ()
295
+ parser = argparse . ArgumentParser ()
284
296
parser .add_argument ("-m" , "--mcu" ,
285
297
help = "build for the given MCU" ,
286
298
default = None ,
@@ -312,6 +324,11 @@ def get_parser():
312
324
default = False ,
313
325
help = "skip the test build phase" )
314
326
327
+ parser .add_argument ('-x' , '--extra' ,
328
+ dest = 'extra_args' ,
329
+ nargs = argparse .REMAINDER ,
330
+ help = "additional build parameters" )
331
+
315
332
return parser
316
333
317
334
@@ -339,7 +356,7 @@ def main():
339
356
subprocess_err = subprocess .STDOUT
340
357
341
358
if options .list :
342
- logger .info ("Avialable platforms are: {}" .format (
359
+ logger .info ("Available platforms are: {}" .format (
343
360
', ' .join ([t for t in _get_psa_secure_targets_list ()])))
344
361
return
345
362
@@ -350,7 +367,8 @@ def main():
350
367
351
368
for target , tc , directory in psa_platforms_list :
352
369
build_psa_platform (target , tc , directory , options .debug ,
353
- options .commit , options .skip_tests )
370
+ options .commit , options .skip_tests ,
371
+ options .extra_args )
354
372
355
373
logger .info ("Finished Updating PSA images" )
356
374
0 commit comments