Skip to content

Commit 6548824

Browse files
author
Oren Cohen
committed
Refactor
* Use default image command generator. * Call directly to mbed-cli. * Add --skip-tests.
1 parent 16bcd5f commit 6548824

File tree

1 file changed

+63
-51
lines changed

1 file changed

+63
-51
lines changed

tools/psa/release.py

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
sys.path.insert(0, ROOT)
2929
from tools.targets import Target, TARGET_MAP, TARGET_NAMES
3030

31-
MAKE_PY_LOCATTION = os.path.join(ROOT, 'tools', 'make.py')
32-
TEST_PY_LOCATTION = os.path.join(ROOT, 'tools', 'test.py')
3331

3432
logging.basicConfig(level=logging.DEBUG,
3533
format='[%(name)s] %(asctime)s: %(message)s.',
@@ -88,6 +86,33 @@ def _get_psa_secure_targets_list():
8886
return [str(t) for t in TARGET_NAMES if
8987
Target.get_target(t).is_PSA_secure_target]
9088

89+
90+
def _get_default_image_build_command(target, toolchain, profile):
91+
"""
92+
Creates a build command for a default image.
93+
94+
:param target: target to be built.
95+
:param toolchain: toolchain to be used.
96+
:param profile: build profile.
97+
:return: Build command in a list form.
98+
"""
99+
cmd = [
100+
'mbed', 'compile',
101+
'-t', toolchain,
102+
'-m', target,
103+
'--profile', profile,
104+
'--source', ROOT,
105+
'--build', os.path.join(ROOT, 'BUILD', target)
106+
]
107+
108+
if _psa_backend(target) is 'TFM':
109+
cmd += ['--app-config', TFM_MBED_APP]
110+
else:
111+
cmd += ['--artifact-name', 'psa_release_1.0']
112+
113+
return cmd
114+
115+
91116
def get_mbed_official_psa_release(target=None):
92117
"""
93118
Creates a list of PSA targets with default toolchain and
@@ -116,41 +141,28 @@ def create_mbed_ignore(build_dir):
116141
f.write('*\n')
117142

118143

119-
def build_mbed_spm_platform(target, toolchain, profile='release'):
144+
def build_tests_mbed_spm_platform(target, toolchain, profile):
120145
"""
121146
Builds Secure images for MBED-SPM target.
122147
123148
:param target: target to be built.
124149
:param toolchain: toolchain to be used.
125150
:param profile: build profile.
126151
"""
127-
subprocess.check_call([
128-
sys.executable, TEST_PY_LOCATTION,
129-
'--greentea',
130-
'--profile', profile,
131-
'-t', toolchain,
132-
'-m', target,
133-
'--source', ROOT,
134-
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
135-
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests',
136-
target, 'test_spec.json'),
137-
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
138-
target, 'build_data.json'),
139-
'-n', MBED_PSA_TESTS
140-
])
141152
logger.info(
142153
"Building tests images({}) for {} using {} with {} profile".format(
143154
MBED_PSA_TESTS, target, toolchain, profile))
144155

145156
subprocess.check_call([
146-
sys.executable, MAKE_PY_LOCATTION,
157+
'mbed', 'test', '--compile',
147158
'-t', toolchain,
148159
'-m', target,
149160
'--profile', profile,
150161
'--source', ROOT,
151-
'--build', os.path.join(ROOT, 'BUILD', target),
152-
'--artifact-name', 'psa_release_1.0'
153-
])
162+
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
163+
'-n', MBED_PSA_TESTS],
164+
stdout=subprocess_output, stderr=subprocess_err)
165+
154166
logger.info(
155167
"Finished building tests images({}) for {} successfully".format(
156168
MBED_PSA_TESTS, target))
@@ -166,7 +178,7 @@ def _tfm_test_defines(test):
166178
return ['-D{}'.format(define) for define in TFM_TESTS[test]]
167179

168180

169-
def build_tfm_platform(target, toolchain, profile='release'):
181+
def build_tests_tfm_platform(target, toolchain, profile):
170182
"""
171183
Builds Secure images for TF-M target.
172184
@@ -179,29 +191,16 @@ def build_tfm_platform(target, toolchain, profile='release'):
179191
"Building tests image({}) for {} using {} with {} profile".format(
180192
test, target, toolchain, profile))
181193
subprocess.check_call([
182-
sys.executable, TEST_PY_LOCATTION,
183-
'--greentea',
184-
'--profile', profile,
185-
'-t', toolchain,
186-
'-m', target,
187-
'--source', ROOT,
188-
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
189-
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests',
190-
target, 'test_spec.json'),
191-
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
192-
target, 'build_data.json'),
193-
'--app-config', TFM_MBED_APP, '-n', test] + _tfm_test_defines(test),
194-
stdout=subprocess.PIPE)
194+
'mbed', 'test', '--compile',
195+
'-t', toolchain,
196+
'-m', target,
197+
'--profile', profile,
198+
'--source', ROOT,
199+
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
200+
'-n', MBED_PSA_TESTS,
201+
'--app-config', TFM_MBED_APP, '-n', test] + _tfm_test_defines(
202+
test), stdout=subprocess_output, stderr=subprocess_err)
195203

196-
subprocess.check_call([
197-
sys.executable, MAKE_PY_LOCATTION,
198-
'-t', toolchain,
199-
'-m', target,
200-
'--profile', profile,
201-
'--source', ROOT,
202-
'--build', os.path.join(ROOT, 'BUILD', target),
203-
'--app-config', TFM_MBED_APP
204-
])
205204
logger.info(
206205
"Finished Building tests image({}) for {}".format(test, target))
207206

@@ -229,7 +228,6 @@ def commit_binaries(target, delivery_dir):
229228
'add', os.path.relpath(delivery_dir, ROOT)
230229
], stdout=subprocess_output, stderr=subprocess_err)
231230

232-
commit_message = '-m\"Update secure binaries for {}\"'.format(target)
233231
logger.info("Committing images for {}".format(target))
234232
commit_message = '--message="Update secure binaries for {}"'.format(
235233
target)
@@ -244,7 +242,7 @@ def commit_binaries(target, delivery_dir):
244242

245243

246244
def build_psa_platform(target, toolchain, delivery_dir, debug=False,
247-
git_commit=False):
245+
git_commit=False, skip_tests=False):
248246
"""
249247
Calls the correct build function and commits if requested.
250248
@@ -253,15 +251,22 @@ def build_psa_platform(target, toolchain, delivery_dir, debug=False,
253251
:param delivery_dir: Artifact directory, where images should be placed.
254252
:param debug: Build with debug profile.
255253
:param git_commit: Commit the changes.
254+
:param skip_tests: skip the test images build phase.
256255
"""
257256
profile = 'debug' if debug else 'release'
258-
if _psa_backend(target) is 'TFM':
259-
build_tfm_platform(target, toolchain, profile)
260-
else:
261-
build_mbed_spm_platform(target, toolchain, profile)
257+
if not skip_tests:
258+
if _psa_backend(target) is 'TFM':
259+
build_tests_tfm_platform(target, toolchain, profile)
260+
else:
261+
build_tests_mbed_spm_platform(target, toolchain, profile)
262+
262263
logger.info("Building default image for {} using {} with {} profile".format(
263264
target, toolchain, profile))
264265

266+
subprocess.check_call(
267+
_get_default_image_build_command(target, toolchain, profile),
268+
stdout=subprocess_output, stderr=subprocess_err)
269+
265270
logger.info(
266271
"Finished building default image for {} successfully".format(target))
267272

@@ -291,6 +296,11 @@ def get_parser():
291296
help="create a git commit for each platform",
292297
action="store_true",
293298
default=False)
299+
300+
parser.add_argument('--skip-tests',
301+
action="store_true",
302+
default=False,
303+
help="skip the test build phase")
294304

295305
return parser
296306

@@ -324,7 +334,9 @@ def main():
324334
', '.join([t[0] for t in psa_platforms_list])))
325335

326336
for target, tc, directory in psa_platforms_list:
327-
build_psa_platform(target, tc, directory, options.debug, options.commit)
337+
build_psa_platform(target, tc, directory, options.debug,
338+
options.commit, options.skip_tests)
339+
328340
logger.info("Finished Updating PSA images")
329341

330342

0 commit comments

Comments
 (0)