Skip to content

Commit 615c2ef

Browse files
orenc17Michael Schwarcz
authored andcommitted
SPM: Overhaul the psa build system to integrate with mbed-cli (#6867)
SPM: PSA build system integration with tools
1 parent c50dcad commit 615c2ef

File tree

6 files changed

+38
-41
lines changed

6 files changed

+38
-41
lines changed

tools/build_api.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .libraries import Library
4848
from .toolchains import TOOLCHAIN_CLASSES
4949
from .config import Config
50-
from .spm import generate_spm_data
50+
from .spm import generate_spm_data, generate_partitions_sources
5151

5252
RELEASE_VERSIONS = ['2', '5']
5353

@@ -509,7 +509,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
509509
notify=None, name=None, macros=None, inc_dirs=None, jobs=1,
510510
report=None, properties=None, project_id=None,
511511
project_description=None, config=None,
512-
app_config=None, build_profile=None, stats_depth=None, ignore=None):
512+
app_config=None, build_profile=None, stats_depth=None,
513+
ignore=None, psa_manifests=None):
513514
""" Build a project. A project may be a test or a user program.
514515
515516
Positional arguments:
@@ -580,11 +581,20 @@ def build_project(src_paths, build_path, target, toolchain_name,
580581
# Call unified scan_resources
581582
resources = scan_resources(src_paths, toolchain, inc_dirs=inc_dirs)
582583

584+
if psa_manifests is None:
585+
psa_manifests = resources.psa_manifests
586+
else:
587+
psa_manifests.extend(resources.psa_manifests)
588+
589+
for f in generate_partitions_sources(psa_manifests):
590+
resources.add(toolchain.scan_resources(
591+
f, base_path=resources.base_path))
592+
583593
# Skip SPM sources for Mbed OS 2 builds
584594
# Directories scanned would not include the root of Mbed OS for legacy builds
585595
if 'rtos' in toolchain.config.lib_config_data:
586596
# Generate SPM additional code from manifests
587-
psa_files_dir = generate_spm_data(resources.psa_manifests, build_path)
597+
psa_files_dir = generate_spm_data(psa_manifests, build_path)
588598
resources.add(toolchain.scan_resources(psa_files_dir))
589599

590600
# Change linker script if specified
@@ -658,7 +668,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
658668
archive=True, notify=None, macros=None, inc_dirs=None, jobs=1,
659669
report=None, properties=None, project_id=None,
660670
remove_config_header_file=False, app_config=None,
661-
build_profile=None, ignore=None):
671+
build_profile=None, ignore=None, psa_manifests=None):
662672
""" Build a library
663673
664674
Positional arguments:
@@ -745,6 +755,15 @@ def build_library(src_paths, build_path, target, toolchain_name,
745755
dependencies_paths=dependencies_paths,
746756
inc_dirs=inc_dirs)
747757

758+
if psa_manifests is None:
759+
psa_manifests = resources.psa_manifests
760+
else:
761+
psa_manifests.extend(resources.psa_manifests)
762+
763+
for f in generate_partitions_sources(psa_manifests):
764+
resources.add(toolchain.scan_resources(
765+
f, base_path=resources.base_path))
766+
748767
# Copy headers, objects and static libraries - all files needed for
749768
# static lib, PSA manifests
750769
toolchain.copy_files(resources.headers, build_path, resources=resources)
@@ -761,10 +780,6 @@ def build_library(src_paths, build_path, target, toolchain_name,
761780
toolchain.copy_files(resources.hex_files, build_path,
762781
resources=resources)
763782

764-
# if resources.psa_manifests:
765-
# toolchain.copy_files(resources.psa_manifests, build_path,
766-
# resources=resources)
767-
768783
# Compile Sources
769784
objects = toolchain.compile_sources(resources, resources.inc_dirs)
770785
resources.objects.extend(objects)

tools/make.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
from utils import argparse_many
5555
from utils import argparse_dir_not_parent
5656
from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
57-
from tools.spm import generate_partitions_sources, scan_for_manifests
5857

5958
if __name__ == '__main__':
6059
# Parse Options
@@ -242,8 +241,6 @@
242241
"Currently set search path: %s"
243242
%(toolchain, search_path))
244243

245-
generate_partitions_sources(scan_for_manifests(options.source_dir))
246-
247244
# Test
248245
build_data_blob = {} if options.build_data else None
249246
for test_no in p:

tools/spm/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from .generate_partition_code import generate_partitions_sources, \
2-
generate_spm_data, scan_for_manifests
1+
from .generate_partition_code import \
2+
generate_partitions_sources, generate_spm_data
33

44
__all__ = [
55
'generate_partitions_sources',
66
'generate_spm_data',
7-
'scan_for_manifests'
87
]

tools/spm/generate_partition_code.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,6 @@ def generate_partitions_sources(manifest_files, extra_filters=None):
627627
manifest = Manifest.from_json(manifest_file)
628628
manifests.append(manifest)
629629

630-
# Validate the correctness of the manifest collection.
631-
validate_partition_manifests(manifests)
632-
633630
generated_folders = []
634631
for manifest in manifests:
635632
manifest_output_folder = manifest.autogen_folder
@@ -645,8 +642,7 @@ def generate_partitions_sources(manifest_files, extra_filters=None):
645642
manifest_output_folder,
646643
extra_filters=extra_filters
647644
)
648-
649-
generated_folders.append(manifest_output_folder)
645+
generated_folders.append(manifest_output_folder)
650646

651647
return generated_folders
652648

@@ -682,6 +678,9 @@ def generate_spm_data(manifest_files, output_dir, extra_filters=None):
682678
manifest_obj.autogen_folder).values()
683679
)
684680

681+
# Validate the correctness of the manifest collection.
682+
validate_partition_manifests(manifests)
683+
685684
if is_up_to_date(
686685
manifest_files,
687686
MANIFEST_TEMPLATES + COMMON_TEMPLATES,
@@ -699,18 +698,3 @@ def generate_spm_data(manifest_files, output_dir, extra_filters=None):
699698
autogen_folder,
700699
extra_filters=extra_filters
701700
)
702-
703-
704-
def scan_for_manifests(src_dirs):
705-
"""
706-
Scan a list of directories for PSA manifests.
707-
708-
:param src_dirs: List of directories
709-
:return: List of PSA manifests
710-
"""
711-
manifests = set()
712-
for src_dir in src_dirs:
713-
for root, dirnames, filenames in os.walk(src_dir, followlinks=True):
714-
for filename in fnmatch.filter(filenames, MANIFEST_FILE_PATTERN):
715-
manifests.add(os.path.join(root, filename))
716-
return list(manifests)

tools/test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from tools.utils import argparse_dir_not_parent
4444
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS, TOOLCHAIN_CLASSES
4545
from tools.settings import CLI_COLOR_MAP
46-
from tools.spm import generate_partitions_sources, scan_for_manifests
4746

4847
if __name__ == '__main__':
4948
try:
@@ -196,10 +195,9 @@
196195
if not base_source_paths:
197196
base_source_paths = ['.']
198197

199-
generate_partitions_sources(scan_for_manifests(base_source_paths))
200-
201198
build_report = {}
202199
build_properties = {}
200+
psa_manifests = []
203201

204202
library_build_success = False
205203
profile = extract_profile(parser, options, toolchain)
@@ -214,7 +212,8 @@
214212
notify=notify, archive=False,
215213
app_config=config,
216214
build_profile=profile,
217-
ignore=options.ignore)
215+
ignore=options.ignore,
216+
psa_manifests=psa_manifests)
218217

219218
library_build_success = True
220219
except ToolException as e:
@@ -243,7 +242,8 @@
243242
app_config=config,
244243
build_profile=profile,
245244
stats_depth=options.stats_depth,
246-
ignore=options.ignore)
245+
ignore=options.ignore,
246+
psa_manifests=psa_manifests)
247247

248248
# If a path to a test spec is provided, write it to a file
249249
if options.test_spec:

tools/test_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22112211
clean=False, notify=None, jobs=1, macros=None,
22122212
silent=False, report=None, properties=None,
22132213
continue_on_build_fail=False, app_config=None,
2214-
build_profile=None, stats_depth=None, ignore=None):
2214+
build_profile=None, stats_depth=None, ignore=None,
2215+
psa_manifests=None):
22152216
"""Given the data structure from 'find_tests' and the typical build parameters,
22162217
build all the tests
22172218
@@ -2264,7 +2265,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22642265
'build_profile': build_profile,
22652266
'toolchain_paths': TOOLCHAIN_PATHS,
22662267
'stats_depth': stats_depth,
2267-
'notify': MockNotifier()
2268+
'notify': MockNotifier(),
2269+
'psa_manifests': psa_manifests
22682270
}
22692271

22702272
results.append(p.apply_async(build_test_worker, args, kwargs))

0 commit comments

Comments
 (0)