Skip to content

Commit 4aaeda2

Browse files
Oren CohenMichael Schwarcz
authored andcommitted
Move manifests scanning to its own helper function
1 parent b943100 commit 4aaeda2

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

tools/export/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
299299
# Skip SPM sources for Mbed OS 2 builds
300300
# Directories scanned would not include the root of Mbed OS for legacy builds
301301
if 'rtos' in toolchain.config.lib_config_data:
302+
# generate_partitions_sources() is called here to prevent another scan of the file tree
302303
psa_files_dirs = generate_partitions_sources(resources.psa_manifests)
303304
psa_files_dirs.append(generate_spm_data(resources.psa_manifests, export_path))
304305
for directory in psa_files_dirs:

tools/make.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
from utils import argparse_many
5959
from utils import argparse_dir_not_parent
6060
from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
61-
from tools.spm import generate_partitions_sources
61+
from tools.spm import generate_partitions_sources, scan_for_manifests
6262

6363
if __name__ == '__main__':
6464
# Parse Options
@@ -246,12 +246,7 @@
246246
"Currently set search path: %s"
247247
%(toolchain, search_path))
248248

249-
manifests = set()
250-
for src_dir in options.source_dir:
251-
for root, dirnames, filenames in os.walk(src_dir):
252-
for filename in fnmatch.filter(filenames, '*_psa.json'):
253-
manifests.add(join(root, filename))
254-
generate_partitions_sources(list(manifests))
249+
generate_partitions_sources(scan_for_manifests(options.source_dir))
255250

256251
# Test
257252
build_data_blob = {} if options.build_data else None

tools/spm/__init__.py

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

3-
__all__ = ['generate_partitions_sources', 'generate_spm_data']
4+
__all__ = [
5+
'generate_partitions_sources',
6+
'generate_spm_data',
7+
'scan_for_manifests'
8+
]

tools/spm/generate_partition_code.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
import fnmatch
23
import glob
34
import itertools
45
import json
@@ -18,6 +19,7 @@
1819
lambda filename: '_NAME_' not in filename,
1920
glob.glob(path_join(TEMPLATES_DIR, '*.tpl'))
2021
)
22+
MANIFEST_FILE_PATTERN = '*_psa.json'
2123

2224

2325
def assert_int(num):
@@ -697,3 +699,18 @@ def generate_spm_data(manifest_files, output_dir, extra_filters=None):
697699
autogen_folder,
698700
extra_filters=extra_filters
699701
)
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: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
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
46+
from tools.spm import generate_partitions_sources, scan_for_manifests
4747

4848
if __name__ == '__main__':
4949
try:
@@ -196,12 +196,7 @@
196196
if not base_source_paths:
197197
base_source_paths = ['.']
198198

199-
manifests = set()
200-
for src_dir in base_source_paths:
201-
for root, dirnames, filenames in os.walk(src_dir):
202-
for filename in fnmatch.filter(filenames, '*_psa.json'):
203-
manifests.add(os.path.join(root, filename))
204-
generate_partitions_sources(list(manifests))
199+
generate_partitions_sources(scan_for_manifests(base_source_paths))
205200

206201
build_report = {}
207202
build_properties = {}

0 commit comments

Comments
 (0)