Skip to content

Commit f04d51b

Browse files
author
Cruz Monrreal
authored
Merge pull request #9652 from kfnta/tools_fixes
Fix minor bugs in secure targets file filtering
2 parents 760aadf + 6fa47bd commit f04d51b

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

tools/build.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from tools.notifier.term import TerminalNotifier
4444
from tools.utils import argparse_filestring_type, args_error, argparse_many
4545
from tools.utils import argparse_filestring_type, argparse_dir_not_parent
46+
from tools.paths import is_relative_to_root
4647

4748
if __name__ == '__main__':
4849
start = time()
@@ -188,19 +189,11 @@
188189
mcu = TARGET_MAP[target]
189190
profile = extract_profile(parser, options, toolchain)
190191

191-
if mcu.is_PSA_secure_target:
192-
lib_build_res = build_library(
193-
ROOT, options.build_dir, mcu, toolchain,
194-
jobs=options.jobs,
195-
clean=options.clean,
196-
archive=(not options.no_archive),
197-
macros=options.macros,
198-
name=options.artifact_name,
199-
build_profile=profile,
200-
ignore=options.ignore,
201-
notify=notifier,
202-
)
203-
elif options.source_dir:
192+
if mcu.is_PSA_secure_target and \
193+
not is_relative_to_root(options.source_dir):
194+
options.source_dir = ROOT
195+
196+
if options.source_dir:
204197
lib_build_res = build_library(
205198
options.source_dir, options.build_dir, mcu, toolchain,
206199
jobs=options.jobs,

tools/make.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from tools.paths import RPC_LIBRARY
3535
from tools.paths import USB_LIBRARIES
3636
from tools.paths import DSP_LIBRARIES
37+
from tools.paths import is_relative_to_root
3738
from tools.tests import TESTS, Test, TEST_MAP
3839
from tools.tests import TEST_MBED_LIB
3940
from tools.tests import test_known, test_name_known
@@ -307,8 +308,9 @@ def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
307308
args_error(parser, "argument -t/--tool is required")
308309
toolchain = options.tool[0]
309310

310-
if Target.get_target(mcu).is_PSA_secure_target:
311-
options.source_dir = ROOT
311+
if Target.get_target(mcu).is_PSA_secure_target and \
312+
not is_relative_to_root(options.source_dir):
313+
options.source_dir = ROOT
312314

313315
if (options.program is None) and (not options.source_dir):
314316
args_error(parser, "one of -p, -n, or --source is required")

tools/paths.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
from os.path import join
17+
from os.path import join, commonprefix, realpath
1818
from os import getenv
1919

2020
# Conventions about the directory structure
@@ -85,3 +85,11 @@
8585
CPPUTEST_TESTRUNNER_INC = join(TEST_DIR, "utest", "testrunner")
8686

8787
CPPUTEST_LIBRARY = join(BUILD_DIR, "cpputest")
88+
89+
90+
def is_relative_to_root(dirs):
91+
if not isinstance(dirs, list):
92+
dirs = [dirs]
93+
dirs = [realpath(d) for d in dirs]
94+
out = commonprefix(dirs + [ROOT])
95+
return out == ROOT

tools/resources/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from copy import copy
3939
from itertools import chain
4040
from os import walk, sep
41-
from os.path import (join, splitext, dirname, relpath, basename, split, normcase,
41+
from os.path import (join, splitext, dirname, relpath, basename, split, normpath,
4242
abspath, exists)
4343

4444
from .ignore import MbedIgnoreSet, IGNORE_FILENAME
@@ -148,6 +148,11 @@ def __init__(self, notify, collect_ignores=False):
148148

149149
self._ignoreset = MbedIgnoreSet()
150150

151+
# make sure mbed-os root is added as include directory
152+
script_dir = dirname(abspath(__file__))
153+
mbed_os_root_dir = normpath(join(script_dir, '..', '..'))
154+
self.add_file_ref(FileType.INC_DIR, mbed_os_root_dir, mbed_os_root_dir)
155+
151156
def ignore_dir(self, directory):
152157
if self._collect_ignores:
153158
self.ignored_dirs.append(directory)

tools/test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
from tools.settings import CLI_COLOR_MAP
4646
from tools.settings import ROOT
4747
from tools.targets import Target
48+
from tools.paths import is_relative_to_root
49+
4850
if __name__ == '__main__':
4951
try:
5052
# Parse Options
@@ -211,7 +213,7 @@
211213
if not options.build_dir:
212214
args_error(parser, "argument --build is required")
213215

214-
if mcu_secured:
216+
if mcu_secured and not is_relative_to_root(options.source_dir):
215217
base_source_paths = ROOT
216218
else:
217219
base_source_paths = options.source_dir

0 commit comments

Comments
 (0)