Skip to content

Commit 884d2e5

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 18bc1d8 commit 884d2e5

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

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

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

589599
# Change linker script if specified
@@ -660,7 +670,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
660670
archive=True, notify=None, macros=None, inc_dirs=None, jobs=1,
661671
report=None, properties=None, project_id=None,
662672
remove_config_header_file=False, app_config=None,
663-
build_profile=None, ignore=None):
673+
build_profile=None, ignore=None, psa_manifests=None):
664674
""" Build a library
665675
666676
Positional arguments:
@@ -747,6 +757,15 @@ def build_library(src_paths, build_path, target, toolchain_name,
747757
dependencies_paths=dependencies_paths,
748758
inc_dirs=inc_dirs)
749759

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

766-
# if resources.psa_manifests:
767-
# toolchain.copy_files(resources.psa_manifests, build_path,
768-
# resources=resources)
769-
770785
# Compile Sources
771786
objects = toolchain.compile_sources(resources, resources.inc_dirs)
772787
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:
@@ -248,7 +247,8 @@
248247
app_config=config,
249248
build_profile=profile,
250249
stats_depth=options.stats_depth,
251-
ignore=options.ignore)
250+
ignore=options.ignore,
251+
psa_manifests=psa_manifests)
252252

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

tools/test_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,7 +2209,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22092209
clean=False, notify=None, jobs=1, macros=None,
22102210
silent=False, report=None, properties=None,
22112211
continue_on_build_fail=False, app_config=None,
2212-
build_profile=None, stats_depth=None, ignore=None):
2212+
build_profile=None, stats_depth=None, ignore=None,
2213+
psa_manifests=None):
22132214
"""Given the data structure from 'find_tests' and the typical build parameters,
22142215
build all the tests
22152216
@@ -2262,7 +2263,8 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22622263
'build_profile': build_profile,
22632264
'toolchain_paths': TOOLCHAIN_PATHS,
22642265
'stats_depth': stats_depth,
2265-
'notify': MockNotifier()
2266+
'notify': MockNotifier(),
2267+
'psa_manifests': psa_manifests
22662268
}
22672269

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

0 commit comments

Comments
 (0)