Skip to content

Commit 0ca2615

Browse files
author
Oren Cohen
committed
Check source relative to ROOT on secure targets
When building secure targets, we would like compile only files that are in the the mbe-os root folder. This Fixes an issue when sending multiple --source parameters that are all inside the mbed-os tree
1 parent 8fb2467 commit 0ca2615

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-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/test.py

Lines changed: 4 additions & 2 deletions
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,8 +213,8 @@
211213
if not options.build_dir:
212214
args_error(parser, "argument --build is required")
213215

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

0 commit comments

Comments
 (0)