Skip to content

Commit 5fe65e9

Browse files
committed
PSA release script update: add toolchain option
1 parent d997563 commit 5fe65e9

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

tools/psa/release.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _psa_backend(target):
6060
return 'TFM' if 'TFM' in Target.get_target(target).labels else 'MBED_SPM'
6161

6262

63-
def _get_target_info(target):
63+
def _get_target_info(target, toolchain):
6464
"""
6565
Creates a PSA target tuple with default toolchain and
6666
artifact delivery directory.
@@ -74,7 +74,12 @@ def _get_target_info(target):
7474
if not os.path.exists(delivery_dir):
7575
raise Exception("{} does not have delivery_dir".format(target))
7676

77-
return tuple([TARGET_MAP[target].name,
77+
if toolchain:
78+
return tuple([TARGET_MAP[target].name,
79+
toolchain,
80+
delivery_dir])
81+
else:
82+
return tuple([TARGET_MAP[target].name,
7883
TARGET_MAP[target].default_toolchain,
7984
delivery_dir])
8085

@@ -105,7 +110,7 @@ def verbose_check_call(cmd, check_call=True):
105110
return subprocess.call(cmd, stdout=subprocess_output, stderr=subprocess_err)
106111

107112

108-
def get_mbed_official_psa_release(target=None):
113+
def get_mbed_official_psa_release(target=None, toolchain=None):
109114
"""
110115
Creates a list of PSA targets with default toolchain and
111116
artifact delivery directory.
@@ -117,9 +122,9 @@ def get_mbed_official_psa_release(target=None):
117122
logger.debug("Found the following PSA targets: {}".format(
118123
', '.join(psa_secure_targets)))
119124
if target is not None:
120-
return [_get_target_info(target)]
125+
return [_get_target_info(target, toolchain)]
121126

122-
return [_get_target_info(t) for t in psa_secure_targets]
127+
return [_get_target_info(t, toolchain) for t in psa_secure_targets]
123128

124129

125130
def create_mbed_ignore(build_dir):
@@ -142,6 +147,11 @@ def build_tests(target, toolchain, profile, args):
142147
:param profile: build profile.
143148
:param args: list of extra arguments.
144149
"""
150+
build_dir = os.path.join(ROOT, 'BUILD', 'tests', target)
151+
if os.path.exists(build_dir):
152+
logger.info("BUILD directory deleted: {}".format(build_dir))
153+
shutil.rmtree(build_dir)
154+
145155
for test in PSA_TESTS.keys():
146156
logger.info(
147157
"Building tests image({}) for {} using {} with {} profile".format(
@@ -182,6 +192,11 @@ def build_default_image(target, toolchain, profile, args):
182192
logger.info("Building default image for {} using {} with {} profile".format(
183193
target, toolchain, profile))
184194

195+
build_dir = os.path.join(ROOT, 'BUILD', target)
196+
if os.path.exists(build_dir):
197+
logger.info("BUILD directory deleted: {}".format(build_dir))
198+
shutil.rmtree(build_dir)
199+
185200
cmd = [
186201
sys.executable, MAKE_PY_LOCATTION,
187202
'-t', toolchain,
@@ -200,7 +215,7 @@ def build_default_image(target, toolchain, profile, args):
200215
"Finished building default image for {} successfully".format(target))
201216

202217

203-
def commit_binaries(target, delivery_dir):
218+
def commit_binaries(target, delivery_dir, toolchain):
204219
"""
205220
Commits changes in secure binaries.
206221
@@ -222,8 +237,8 @@ def commit_binaries(target, delivery_dir):
222237
'add', os.path.relpath(delivery_dir, ROOT)])
223238

224239
logger.info("Committing images for {}".format(target))
225-
commit_message = '--message="Update secure binaries for {}"'.format(
226-
target)
240+
commit_message = '--message="Update secure binaries for %s (%s)"' % (
241+
target, toolchain)
227242
verbose_check_call([
228243
'git',
229244
'-C', ROOT,
@@ -252,7 +267,7 @@ def build_psa_platform(target, toolchain, delivery_dir, debug, git_commit,
252267

253268
build_default_image(target, toolchain, profile, args)
254269
if git_commit:
255-
commit_binaries(target, delivery_dir)
270+
commit_binaries(target, delivery_dir, toolchain)
256271

257272

258273
def get_parser():
@@ -263,6 +278,10 @@ def get_parser():
263278
choices=_get_psa_secure_targets_list(),
264279
metavar="MCU")
265280

281+
parser.add_argument("-t", "--tc",
282+
help="build for the given tool chain (default is default_toolchain)",
283+
default=None)
284+
266285
parser.add_argument("-d", "--debug",
267286
help="set build profile to debug",
268287
action="store_true",
@@ -298,16 +317,10 @@ def get_parser():
298317

299318

300319
def prep_build_dir():
301-
"""
302-
Creates a clean BUILD directory
303-
"""
304320
build_dir = os.path.join(ROOT, 'BUILD')
305-
if os.path.exists(build_dir):
306-
logger.debug("BUILD directory already exists... Deleting")
307-
shutil.rmtree(build_dir)
308-
309-
os.makedirs(build_dir)
310-
logger.info("BUILD directory created in {}".format(build_dir))
321+
if not os.path.exists(build_dir):
322+
logger.info("BUILD directory created in {}".format(build_dir))
323+
os.makedirs(build_dir)
311324
create_mbed_ignore(build_dir)
312325

313326

@@ -326,7 +339,7 @@ def main():
326339
return
327340

328341
prep_build_dir()
329-
psa_platforms_list = get_mbed_official_psa_release(options.mcu)
342+
psa_platforms_list = get_mbed_official_psa_release(options.mcu, options.tc)
330343
logger.info("Building the following platforms: {}".format(
331344
', '.join([t[0] for t in psa_platforms_list])))
332345

0 commit comments

Comments
 (0)