Merge pull request #10606 from jeromecoutant/PR_PSAscript

PSA release script update: add toolchain option
pull/10631/head
Martin Kojtal 2019-05-21 15:06:10 +01:00 committed by GitHub
commit 77ca32dd57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 27 deletions

View File

@ -35,12 +35,14 @@ For an application with custom secure portions, the secure image should be gener
### Usage ### Usage
```text ```text
usage: release.py [-h] [-m MCU] [-d] [-q] [-l] [--commit] [--skip-tests] usage: release.py [-h] [-m MCU] [-t TC] [-d] [-q] [-l] [--commit]
[-x ...] [--skip-tests] [-x ...]
optional arguments: optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-m MCU, --mcu MCU build for the given MCU -m MCU, --mcu MCU build for the given MCU
-t TC, --tc TC build for the given tool chain (default is
default_toolchain)
-d, --debug set build profile to debug -d, --debug set build profile to debug
-q, --quiet No Build log will be printed -q, --quiet No Build log will be printed
-l, --list Print supported PSA secure targets -l, --list Print supported PSA secure targets
@ -50,6 +52,7 @@ optional arguments:
``` ```
* When `MCU ` is not specified, the script compiles all the images for all the targets. * When `MCU ` is not specified, the script compiles all the images for all the targets.
* When `-t/--tc` is not specified, the script compiles with the default_toolchain speciified in targets.json.
* When `-d/--debug` is not specified, the script compiles the images using the release profile. * When `-d/--debug` is not specified, the script compiles the images using the release profile.
* When `--commit` is not specified, the script will not commit the images to git. * When `--commit` is not specified, the script will not commit the images to git.
* A user can specify additional commands that will be passed on to the build commands (Ex. -D for compilation defines). * A user can specify additional commands that will be passed on to the build commands (Ex. -D for compilation defines).

View File

@ -60,7 +60,7 @@ def _psa_backend(target):
return 'TFM' if 'TFM' in Target.get_target(target).labels else 'MBED_SPM' return 'TFM' if 'TFM' in Target.get_target(target).labels else 'MBED_SPM'
def _get_target_info(target): def _get_target_info(target, toolchain):
""" """
Creates a PSA target tuple with default toolchain and Creates a PSA target tuple with default toolchain and
artifact delivery directory. artifact delivery directory.
@ -74,6 +74,13 @@ def _get_target_info(target):
if not os.path.exists(delivery_dir): if not os.path.exists(delivery_dir):
raise Exception("{} does not have delivery_dir".format(target)) raise Exception("{} does not have delivery_dir".format(target))
if toolchain:
if toolchain not in TARGET_MAP[target].supported_toolchains:
raise Exception("Toolchain {} is not supported by {}".format(toolchain, TARGET_MAP[target].name))
return tuple([TARGET_MAP[target].name,
toolchain,
delivery_dir])
else:
return tuple([TARGET_MAP[target].name, return tuple([TARGET_MAP[target].name,
TARGET_MAP[target].default_toolchain, TARGET_MAP[target].default_toolchain,
delivery_dir]) delivery_dir])
@ -105,7 +112,7 @@ def verbose_check_call(cmd, check_call=True):
return subprocess.call(cmd, stdout=subprocess_output, stderr=subprocess_err) return subprocess.call(cmd, stdout=subprocess_output, stderr=subprocess_err)
def get_mbed_official_psa_release(target=None): def get_mbed_official_psa_release(target=None, toolchain=None):
""" """
Creates a list of PSA targets with default toolchain and Creates a list of PSA targets with default toolchain and
artifact delivery directory. artifact delivery directory.
@ -117,9 +124,9 @@ def get_mbed_official_psa_release(target=None):
logger.debug("Found the following PSA targets: {}".format( logger.debug("Found the following PSA targets: {}".format(
', '.join(psa_secure_targets))) ', '.join(psa_secure_targets)))
if target is not None: if target is not None:
return [_get_target_info(target)] return [_get_target_info(target, toolchain)]
return [_get_target_info(t) for t in psa_secure_targets] return [_get_target_info(t, toolchain) for t in psa_secure_targets]
def create_mbed_ignore(build_dir): def create_mbed_ignore(build_dir):
@ -142,6 +149,11 @@ def build_tests(target, toolchain, profile, args):
:param profile: build profile. :param profile: build profile.
:param args: list of extra arguments. :param args: list of extra arguments.
""" """
build_dir = os.path.join(ROOT, 'BUILD', 'tests', target)
if os.path.exists(build_dir):
logger.info("BUILD directory deleted: {}".format(build_dir))
shutil.rmtree(build_dir)
for test in PSA_TESTS.keys(): for test in PSA_TESTS.keys():
logger.info( logger.info(
"Building tests image({}) for {} using {} with {} profile".format( "Building tests image({}) for {} using {} with {} profile".format(
@ -155,11 +167,9 @@ def build_tests(target, toolchain, profile, args):
'-t', toolchain, '-t', toolchain,
'-m', target, '-m', target,
'--source', ROOT, '--source', ROOT,
'--build', os.path.join(ROOT, 'BUILD', 'tests', target), '--build', build_dir,
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests', '--test-spec', os.path.join(build_dir, 'test_spec.json'),
target, 'test_spec.json'), '--build-data', os.path.join(build_dir, 'build_data.json'),
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
target, 'build_data.json'),
'-n', test] + test_defines + args '-n', test] + test_defines + args
if _psa_backend(target) is 'TFM': if _psa_backend(target) is 'TFM':
@ -182,13 +192,18 @@ def build_default_image(target, toolchain, profile, args):
logger.info("Building default image for {} using {} with {} profile".format( logger.info("Building default image for {} using {} with {} profile".format(
target, toolchain, profile)) target, toolchain, profile))
build_dir = os.path.join(ROOT, 'BUILD', target)
if os.path.exists(build_dir):
logger.info("BUILD directory deleted: {}".format(build_dir))
shutil.rmtree(build_dir)
cmd = [ cmd = [
sys.executable, MAKE_PY_LOCATTION, sys.executable, MAKE_PY_LOCATTION,
'-t', toolchain, '-t', toolchain,
'-m', target, '-m', target,
'--profile', profile, '--profile', profile,
'--source', ROOT, '--source', ROOT,
'--build', os.path.join(ROOT, 'BUILD', target)] + args '--build', build_dir] + args
if _psa_backend(target) is 'TFM': if _psa_backend(target) is 'TFM':
cmd += ['--app-config', TFM_MBED_APP] cmd += ['--app-config', TFM_MBED_APP]
@ -200,7 +215,7 @@ def build_default_image(target, toolchain, profile, args):
"Finished building default image for {} successfully".format(target)) "Finished building default image for {} successfully".format(target))
def commit_binaries(target, delivery_dir): def commit_binaries(target, delivery_dir, toolchain):
""" """
Commits changes in secure binaries. Commits changes in secure binaries.
@ -222,8 +237,8 @@ def commit_binaries(target, delivery_dir):
'add', os.path.relpath(delivery_dir, ROOT)]) 'add', os.path.relpath(delivery_dir, ROOT)])
logger.info("Committing images for {}".format(target)) logger.info("Committing images for {}".format(target))
commit_message = '--message="Update secure binaries for {}"'.format( commit_message = '--message="Update secure binaries for %s (%s)"' % (
target) target, toolchain)
verbose_check_call([ verbose_check_call([
'git', 'git',
'-C', ROOT, '-C', ROOT,
@ -252,7 +267,7 @@ def build_psa_platform(target, toolchain, delivery_dir, debug, git_commit,
build_default_image(target, toolchain, profile, args) build_default_image(target, toolchain, profile, args)
if git_commit: if git_commit:
commit_binaries(target, delivery_dir) commit_binaries(target, delivery_dir, toolchain)
def get_parser(): def get_parser():
@ -263,6 +278,10 @@ def get_parser():
choices=_get_psa_secure_targets_list(), choices=_get_psa_secure_targets_list(),
metavar="MCU") metavar="MCU")
parser.add_argument("-t", "--tc",
help="build for the given tool chain (default is default_toolchain)",
default=None)
parser.add_argument("-d", "--debug", parser.add_argument("-d", "--debug",
help="set build profile to debug", help="set build profile to debug",
action="store_true", action="store_true",
@ -298,16 +317,10 @@ def get_parser():
def prep_build_dir(): def prep_build_dir():
"""
Creates a clean BUILD directory
"""
build_dir = os.path.join(ROOT, 'BUILD') build_dir = os.path.join(ROOT, 'BUILD')
if os.path.exists(build_dir): if not os.path.exists(build_dir):
logger.debug("BUILD directory already exists... Deleting")
shutil.rmtree(build_dir)
os.makedirs(build_dir)
logger.info("BUILD directory created in {}".format(build_dir)) logger.info("BUILD directory created in {}".format(build_dir))
os.makedirs(build_dir)
create_mbed_ignore(build_dir) create_mbed_ignore(build_dir)
@ -326,7 +339,7 @@ def main():
return return
prep_build_dir() prep_build_dir()
psa_platforms_list = get_mbed_official_psa_release(options.mcu) psa_platforms_list = get_mbed_official_psa_release(options.mcu, options.tc)
logger.info("Building the following platforms: {}".format( logger.info("Building the following platforms: {}".format(
', '.join([t[0] for t in psa_platforms_list]))) ', '.join([t[0] for t in psa_platforms_list])))