Skip to content

Fix minor bugs in secure targets file filtering #9652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from tools.notifier.term import TerminalNotifier
from tools.utils import argparse_filestring_type, args_error, argparse_many
from tools.utils import argparse_filestring_type, argparse_dir_not_parent
from tools.paths import is_relative_to_root

if __name__ == '__main__':
start = time()
Expand Down Expand Up @@ -188,19 +189,11 @@
mcu = TARGET_MAP[target]
profile = extract_profile(parser, options, toolchain)

if mcu.is_PSA_secure_target:
lib_build_res = build_library(
ROOT, options.build_dir, mcu, toolchain,
jobs=options.jobs,
clean=options.clean,
archive=(not options.no_archive),
macros=options.macros,
name=options.artifact_name,
build_profile=profile,
ignore=options.ignore,
notify=notifier,
)
elif options.source_dir:
if mcu.is_PSA_secure_target and \
not is_relative_to_root(options.source_dir):
options.source_dir = ROOT

if options.source_dir:
lib_build_res = build_library(
options.source_dir, options.build_dir, mcu, toolchain,
jobs=options.jobs,
Expand Down
6 changes: 4 additions & 2 deletions tools/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from tools.paths import RPC_LIBRARY
from tools.paths import USB_LIBRARIES
from tools.paths import DSP_LIBRARIES
from tools.paths import is_relative_to_root
from tools.tests import TESTS, Test, TEST_MAP
from tools.tests import TEST_MBED_LIB
from tools.tests import test_known, test_name_known
Expand Down Expand Up @@ -307,8 +308,9 @@ def wrapped_build_project(src_dir, build_dir, mcu, *args, **kwargs):
args_error(parser, "argument -t/--tool is required")
toolchain = options.tool[0]

if Target.get_target(mcu).is_PSA_secure_target:
options.source_dir = ROOT
if Target.get_target(mcu).is_PSA_secure_target and \
not is_relative_to_root(options.source_dir):
options.source_dir = ROOT

if (options.program is None) and (not options.source_dir):
args_error(parser, "one of -p, -n, or --source is required")
Expand Down
10 changes: 9 additions & 1 deletion tools/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
from os.path import join
from os.path import join, commonprefix, realpath
from os import getenv

# Conventions about the directory structure
Expand Down Expand Up @@ -85,3 +85,11 @@
CPPUTEST_TESTRUNNER_INC = join(TEST_DIR, "utest", "testrunner")

CPPUTEST_LIBRARY = join(BUILD_DIR, "cpputest")


def is_relative_to_root(dirs):
if not isinstance(dirs, list):
dirs = [dirs]
dirs = [realpath(d) for d in dirs]
out = commonprefix(dirs + [ROOT])
return out == ROOT
7 changes: 6 additions & 1 deletion tools/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from copy import copy
from itertools import chain
from os import walk, sep
from os.path import (join, splitext, dirname, relpath, basename, split, normcase,
from os.path import (join, splitext, dirname, relpath, basename, split, normpath,
abspath, exists)

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

self._ignoreset = MbedIgnoreSet()

# make sure mbed-os root is added as include directory
script_dir = dirname(abspath(__file__))
mbed_os_root_dir = normpath(join(script_dir, '..', '..'))
self.add_file_ref(FileType.INC_DIR, mbed_os_root_dir, mbed_os_root_dir)

def ignore_dir(self, directory):
if self._collect_ignores:
self.ignored_dirs.append(directory)
Expand Down
4 changes: 3 additions & 1 deletion tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
from tools.settings import CLI_COLOR_MAP
from tools.settings import ROOT
from tools.targets import Target
from tools.paths import is_relative_to_root

if __name__ == '__main__':
try:
# Parse Options
Expand Down Expand Up @@ -211,7 +213,7 @@
if not options.build_dir:
args_error(parser, "argument --build is required")

if mcu_secured:
if mcu_secured and not is_relative_to_root(options.source_dir):
base_source_paths = ROOT
else:
base_source_paths = options.source_dir
Expand Down