19
19
import subprocess
20
20
import sys
21
21
import shutil
22
+ import logging
22
23
from argparse import ArgumentParser
23
24
25
+ FNULL = open (os .devnull , 'w' )
24
26
ROOT = os .path .abspath (os .path .join (os .path .dirname (__file__ ),
25
27
os .pardir , os .pardir ))
26
28
sys .path .insert (0 , ROOT )
27
29
from tools .targets import Target , TARGET_MAP , TARGET_NAMES
28
30
29
31
MAKE_PY_LOCATTION = os .path .join (ROOT , 'tools' , 'make.py' )
30
32
TEST_PY_LOCATTION = os .path .join (ROOT , 'tools' , 'test.py' )
33
+
34
+ logging .basicConfig (level = logging .DEBUG ,
35
+ format = '[%(name)s] %(asctime)s: %(message)s.' ,
36
+ datefmt = '%H:%M:%S' )
37
+ logger = logging .getLogger ('PSA release tool' )
38
+ subprocess_output = None
39
+ subprocess_err = None
40
+
31
41
TFM_MBED_APP = os .path .join (ROOT , 'tools' , 'psa' , 'tfm' , 'mbed_app.json' )
32
42
MBED_PSA_TESTS = '*psa-spm*,*psa-crypto_access_control'
33
43
TFM_TESTS = {
@@ -80,6 +90,8 @@ def get_mbed_official_psa_release(target=None):
80
90
psa_targets_release_list = []
81
91
psa_secure_targets = [t for t in TARGET_NAMES if
82
92
Target .get_target (t ).is_PSA_secure_target ]
93
+ logger .debug ("Found the following PSA targets: {}" .format (
94
+ ', ' .join (psa_secure_targets )))
83
95
if target is not None :
84
96
if target not in psa_secure_targets :
85
97
raise Exception ("{} is not a PSA secure target" .format (target ))
@@ -97,6 +109,7 @@ def create_mbed_ignore(build_dir):
97
109
98
110
:param build_dir: Directory to create .mbedignore file.
99
111
"""
112
+ logger .debug ('Created .mbedignore in {}' .format (build_dir ))
100
113
with open (os .path .join (build_dir , '.mbedignore' ), 'w' ) as f :
101
114
f .write ('*\n ' )
102
115
@@ -123,6 +136,9 @@ def build_mbed_spm_platform(target, toolchain, profile='release'):
123
136
target , 'build_data.json' ),
124
137
'-n' , MBED_PSA_TESTS
125
138
])
139
+ logger .info (
140
+ "Building tests images({}) for {} using {} with {} profile" .format (
141
+ MBED_PSA_TESTS , target , toolchain , profile ))
126
142
127
143
subprocess .check_call ([
128
144
sys .executable , MAKE_PY_LOCATTION ,
@@ -133,6 +149,9 @@ def build_mbed_spm_platform(target, toolchain, profile='release'):
133
149
'--build' , os .path .join (ROOT , 'BUILD' , target ),
134
150
'--artifact-name' , 'psa_release_1.0'
135
151
])
152
+ logger .info (
153
+ "Finished building tests images({}) for {} successfully" .format (
154
+ MBED_PSA_TESTS , target ))
136
155
137
156
138
157
def _tfm_test_defines (test ):
@@ -154,6 +173,9 @@ def build_tfm_platform(target, toolchain, profile='release'):
154
173
:param profile: build profile.
155
174
"""
156
175
for test in TFM_TESTS .keys ():
176
+ logger .info (
177
+ "Building tests image({}) for {} using {} with {} profile" .format (
178
+ test , target , toolchain , profile ))
157
179
subprocess .check_call ([
158
180
sys .executable , TEST_PY_LOCATTION ,
159
181
'--greentea' ,
@@ -178,6 +200,8 @@ def build_tfm_platform(target, toolchain, profile='release'):
178
200
'--build' , os .path .join (ROOT , 'BUILD' , target ),
179
201
'--app-config' , TFM_MBED_APP
180
202
])
203
+ logger .info (
204
+ "Finished Building tests image({}) for {}" .format (test , target ))
181
205
182
206
183
207
def commit_binaries (target , delivery_dir ):
@@ -193,22 +217,28 @@ def commit_binaries(target, delivery_dir):
193
217
'-C' , ROOT ,
194
218
'diff' , '--exit-code' , '--quiet' ,
195
219
delivery_dir
196
- ])
220
+ ], stdout = subprocess_output , stderr = subprocess_err )
197
221
198
222
if changes_made :
223
+ logger .info ("Change in images for {} has been detected" .format (target ))
199
224
subprocess .check_call ([
200
225
'git' ,
201
226
'-C' , ROOT ,
202
227
'add' , os .path .relpath (delivery_dir , ROOT )
203
- ])
228
+ ], stdout = subprocess_output , stderr = subprocess_err )
204
229
205
230
commit_message = '-m\" Update secure binaries for {}\" ' .format (target )
231
+ logger .info ("Committing images for {}" .format (target ))
232
+ commit_message = '--message="Update secure binaries for {}"' .format (
233
+ target )
206
234
subprocess .check_call ([
207
235
'git' ,
208
236
'-C' , ROOT ,
209
237
'commit' ,
210
238
commit_message
211
- ])
239
+ ], stdout = subprocess_output , stderr = subprocess_err )
240
+ else :
241
+ logger .info ("No changes detected for {}, Skipping commit" .format (target ))
212
242
213
243
214
244
def build_psa_platform (target , toolchain , delivery_dir , debug = False ,
@@ -227,6 +257,11 @@ def build_psa_platform(target, toolchain, delivery_dir, debug=False,
227
257
build_tfm_platform (target , toolchain , profile )
228
258
else :
229
259
build_mbed_spm_platform (target , toolchain , profile )
260
+ logger .info ("Building default image for {} using {} with {} profile" .format (
261
+ target , toolchain , profile ))
262
+
263
+ logger .info (
264
+ "Finished building default image for {} successfully" .format (target ))
230
265
231
266
if git_commit :
232
267
commit_binaries (target , delivery_dir )
@@ -244,6 +279,11 @@ def get_parser():
244
279
action = "store_true" ,
245
280
default = False )
246
281
282
+ parser .add_argument ('-q' , '--quiet' ,
283
+ action = "store_true" ,
284
+ default = False ,
285
+ help = "No Build log will be printed" )
286
+
247
287
parser .add_argument ("--commit" ,
248
288
help = "create a git commit for each platform" ,
249
289
action = "store_true" ,
@@ -258,20 +298,31 @@ def prep_build_dir():
258
298
"""
259
299
build_dir = os .path .join (ROOT , 'BUILD' )
260
300
if os .path .exists (build_dir ):
301
+ logger .debug ("BUILD directory already exists... Deleting" )
261
302
shutil .rmtree (build_dir )
262
303
263
304
os .makedirs (build_dir )
305
+ logger .info ("BUILD directory created in {}" .format (build_dir ))
264
306
create_mbed_ignore (build_dir )
265
307
266
308
267
309
def main ():
268
310
parser = get_parser ()
269
311
options = parser .parse_args ()
312
+ if options .quiet :
313
+ logger .setLevel (logging .INFO )
314
+ global subprocess_output , subprocess_err
315
+ subprocess_output = FNULL
316
+ subprocess_err = subprocess .STDOUT
317
+
270
318
prep_build_dir ()
271
319
psa_platforms_list = get_mbed_official_psa_release (options .mcu )
320
+ logger .info ("Building the following platforms: {}" .format (
321
+ ', ' .join ([t [0 ] for t in psa_platforms_list ])))
272
322
273
323
for target , tc , directory in psa_platforms_list :
274
324
build_psa_platform (target , tc , directory , options .debug , options .commit )
325
+ logger .info ("Finished Updating PSA images" )
275
326
276
327
277
328
if __name__ == '__main__' :
0 commit comments