Skip to content

Commit 79ea266

Browse files
committed
PSA release script update: add toolchain option
1 parent d997563 commit 79ea266

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

tools/psa/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ For an application with custom secure portions, the secure image should be gener
3535
3636
### Usage
3737
```text
38-
usage: release.py [-h] [-m MCU] [-d] [-q] [-l] [--commit] [--skip-tests]
39-
[-x ...]
38+
usage: release.py [-h] [-m MCU] [-t TC] [-d] [-q] [-l] [--commit]
39+
[--skip-tests] [-x ...]
4040
4141
optional arguments:
4242
-h, --help show this help message and exit
4343
-m MCU, --mcu MCU build for the given MCU
44+
-t TC, --tc TC build for the given tool chain (default is
45+
default_toolchain)
4446
-d, --debug set build profile to debug
4547
-q, --quiet No Build log will be printed
4648
-l, --list Print supported PSA secure targets
@@ -50,6 +52,7 @@ optional arguments:
5052
```
5153

5254
* When `MCU ` is not specified, the script compiles all the images for all the targets.
55+
* When `-t/--tc` is not specified, the script compiles with the default_toolchain speciified in targets.json.
5356
* When `-d/--debug` is not specified, the script compiles the images using the release profile.
5457
* When `--commit` is not specified, the script will not commit the images to git.
5558
* A user can specify additional commands that will be passed on to the build commands (Ex. -D for compilation defines).

tools/psa/release.py

Lines changed: 38 additions & 25 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,14 @@ 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+
if toolchain not in TARGET_MAP[target].supported_toolchains:
79+
raise Exception("Toolchain {} is not supported by {}".format(toolchain, TARGET_MAP[target].name))
80+
return tuple([TARGET_MAP[target].name,
81+
toolchain,
82+
delivery_dir])
83+
else:
84+
return tuple([TARGET_MAP[target].name,
7885
TARGET_MAP[target].default_toolchain,
7986
delivery_dir])
8087

@@ -105,7 +112,7 @@ def verbose_check_call(cmd, check_call=True):
105112
return subprocess.call(cmd, stdout=subprocess_output, stderr=subprocess_err)
106113

107114

108-
def get_mbed_official_psa_release(target=None):
115+
def get_mbed_official_psa_release(target=None, toolchain=None):
109116
"""
110117
Creates a list of PSA targets with default toolchain and
111118
artifact delivery directory.
@@ -117,9 +124,9 @@ def get_mbed_official_psa_release(target=None):
117124
logger.debug("Found the following PSA targets: {}".format(
118125
', '.join(psa_secure_targets)))
119126
if target is not None:
120-
return [_get_target_info(target)]
127+
return [_get_target_info(target, toolchain)]
121128

122-
return [_get_target_info(t) for t in psa_secure_targets]
129+
return [_get_target_info(t, toolchain) for t in psa_secure_targets]
123130

124131

125132
def create_mbed_ignore(build_dir):
@@ -142,6 +149,11 @@ def build_tests(target, toolchain, profile, args):
142149
:param profile: build profile.
143150
:param args: list of extra arguments.
144151
"""
152+
build_dir = os.path.join(ROOT, 'BUILD', 'tests', target)
153+
if os.path.exists(build_dir):
154+
logger.info("BUILD directory deleted: {}".format(build_dir))
155+
shutil.rmtree(build_dir)
156+
145157
for test in PSA_TESTS.keys():
146158
logger.info(
147159
"Building tests image({}) for {} using {} with {} profile".format(
@@ -155,11 +167,9 @@ def build_tests(target, toolchain, profile, args):
155167
'-t', toolchain,
156168
'-m', target,
157169
'--source', ROOT,
158-
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
159-
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests',
160-
target, 'test_spec.json'),
161-
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
162-
target, 'build_data.json'),
170+
'--build', build_dir,
171+
'--test-spec', os.path.join(build_dir, 'test_spec.json'),
172+
'--build-data', os.path.join(build_dir, 'build_data.json'),
163173
'-n', test] + test_defines + args
164174

165175
if _psa_backend(target) is 'TFM':
@@ -182,13 +192,18 @@ 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,
188203
'-m', target,
189204
'--profile', profile,
190205
'--source', ROOT,
191-
'--build', os.path.join(ROOT, 'BUILD', target)] + args
206+
'--build', build_dir] + args
192207

193208
if _psa_backend(target) is 'TFM':
194209
cmd += ['--app-config', TFM_MBED_APP]
@@ -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)