Skip to content

Commit 545553b

Browse files
committed
Rewrite test detection to avoid relying on "inc_dirs"
1 parent 8166889 commit 545553b

File tree

3 files changed

+53
-77
lines changed

3 files changed

+53
-77
lines changed

tools/build_api.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ def build_project(src_paths, build_path, target, toolchain_name,
480480
stats_depth - depth level for memap to display file/dirs
481481
ignore - list of paths to add to mbedignore
482482
"""
483-
484483
# Convert src_path to a list if needed
485484
if not isinstance(src_paths, list):
486485
src_paths = [src_paths]
@@ -628,6 +627,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
628627
# Convert src_path to a list if needed
629628
if not isinstance(src_paths, list):
630629
src_paths = [src_paths]
630+
src_paths = [relpath(s) for s in src_paths]
631631

632632
# Build path
633633
if archive:
@@ -679,28 +679,25 @@ def build_library(src_paths, build_path, target, toolchain_name,
679679
raise Exception(error_msg)
680680

681681
try:
682-
resources = Resources(notify).scan_with_toolchain(
682+
res = Resources(notify).scan_with_toolchain(
683683
src_paths, toolchain, dependencies_paths, inc_dirs=inc_dirs)
684684

685685
# Copy headers, objects and static libraries - all files needed for
686686
# static lib
687-
toolchain.copy_files(resources.headers, build_path, resources=resources)
688-
toolchain.copy_files(resources.objects, build_path, resources=resources)
689-
toolchain.copy_files(resources.libraries, build_path,
690-
resources=resources)
691-
toolchain.copy_files(resources.json_files, build_path,
692-
resources=resources)
693-
if resources.linker_script:
694-
toolchain.copy_files(resources.linker_script, build_path,
695-
resources=resources)
696-
697-
if resources.hex_files:
698-
toolchain.copy_files(resources.hex_files, build_path,
699-
resources=resources)
700-
687+
to_copy = (
688+
res.get_file_refs(FileType.HEADER) +
689+
res.get_file_refs(FileType.OBJECT) +
690+
res.get_file_refs(FileType.LIB) +
691+
res.get_file_refs(FileType.JSON) +
692+
res.get_file_refs(FileType.LD_SCRIPT) +
693+
res.get_file_refs(FileType.HEX) +
694+
res.get_file_refs(FileType.BIN)
695+
)
696+
toolchain.copy_files(to_copy, build_path)
701697
# Compile Sources
702-
objects = toolchain.compile_sources(resources, resources.inc_dirs)
703-
resources.objects.extend(objects)
698+
objects = toolchain.compile_sources(
699+
res, res.get_file_paths(FileType.INC_DIR))
700+
res.add_files_to_type(FileType.OBJECT, objects)
704701

705702
if archive:
706703
toolchain.build_library(objects, build_path, name)
@@ -714,8 +711,6 @@ def build_library(src_paths, build_path, target, toolchain_name,
714711
end = time()
715712
cur_result["elapsed_time"] = end - start
716713
cur_result["result"] = "OK"
717-
718-
719714
add_result_to_report(report, cur_result)
720715
return True
721716

@@ -840,8 +835,8 @@ def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
840835
inc_dirs=inc_dirs, dependencies_paths=dependencies_paths)
841836

842837
# Copy Headers
843-
toolchain.copy_files(resources.headers, build_path,
844-
resources=resources)
838+
toolchain.copy_files(
839+
resources.get_file_refs(FileType.HEADER), build_path)
845840

846841
dependencies_include_dir = Resources(notify).sacn_with_toolchain([build_path], toolchain).inc_dirs
847842

@@ -968,14 +963,18 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
968963
toolchain.set_config_data(toolchain.config.get_config_data())
969964

970965
# distribute header files
971-
toolchain.copy_files([MBED_HEADER], MBED_LIBRARIES)
966+
toolchain.copy_files(
967+
[FileRef(basename(MBED_HEADER),MBED_HEADER)], MBED_LIBRARIES)
972968
library_incdirs = [dirname(MBED_LIBRARIES), MBED_LIBRARIES]
973969

974970
for dir, dest in [(MBED_DRIVERS, MBED_LIBRARIES_DRIVERS),
975971
(MBED_PLATFORM, MBED_LIBRARIES_PLATFORM),
976972
(MBED_HAL, MBED_LIBRARIES_HAL)]:
977973
resources = Resources(notify).scan_with_toolchain([dir], toolchain)
978-
toolchain.copy_files(resources.headers, dest)
974+
toolchain.copy_files(
975+
[FileRef(basename(p), p) for p
976+
in resources.get_file_paths(FileType.HEADER)] ,
977+
dest)
979978
library_incdirs.append(dest)
980979

981980
# collect resources of the libs to compile
@@ -1011,7 +1010,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
10111010
hal_objects = toolchain.compile_sources(hal_res, incdirs + [tmp_path])
10121011

10131012
# Copy everything into the build directory
1014-
to_copy = sum([
1013+
to_copy = [FileRef(basename(p), p) for p in sum([
10151014
hal_res.headers,
10161015
hal_res.hex_files,
10171016
hal_res.bin_files,
@@ -1022,7 +1021,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
10221021
cmsis_objects,
10231022
hal_objects,
10241023
separate_objects,
1025-
], [])
1024+
], [])]
10261025
toolchain.copy_files(to_copy, build_toolchain)
10271026

10281027
if report is not None:

tools/test_api.py

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from Queue import Queue, Empty
4141
except ImportError:
4242
from queue import Queue, Empty
43-
from os.path import join, exists, basename, relpath
43+
from os.path import join, exists, basename, relpath, isdir
4444
from threading import Thread, Lock
4545
from multiprocessing import Pool, cpu_count
4646
from subprocess import Popen, PIPE
@@ -2083,49 +2083,33 @@ def find_tests(base_dir, target_name, toolchain_name, app_config=None):
20832083
commons = []
20842084

20852085
# Scan the directory for paths to probe for 'TESTS' folders
2086-
base_resources = Resources(MockNotifier())
2086+
base_resources = Resources(MockNotifier(), collect_ignores=True)
20872087
base_resources.add_directory(base_dir)
20882088

2089-
dirs = base_resources.inc_dirs
2089+
dirs = [d for d in base_resources.ignored_dirs if basename(d) == 'TESTS']
20902090
for directory in dirs:
2091-
subdirs = os.listdir(directory)
2092-
2093-
# If the directory contains a subdirectory called 'TESTS', scan it for test cases
2094-
if 'TESTS' in subdirs:
2095-
walk_base_dir = join(directory, 'TESTS')
2096-
test_resources = Resources(MockNotifier())
2097-
test_resources.add_directory(walk_base_dir, base_dir)
2098-
2099-
# Loop through all subdirectories
2100-
for d in test_resources.inc_dirs:
2101-
2102-
# If the test case folder is not called 'host_tests' or 'COMMON' and it is
2103-
# located two folders down from the main 'TESTS' folder (ex. TESTS/testgroup/testcase)
2104-
# then add it to the tests
2105-
relative_path = relpath(d, walk_base_dir)
2106-
relative_path_parts = os.path.normpath(relative_path).split(os.sep)
2107-
if len(relative_path_parts) == 2:
2108-
test_group_directory_path, test_case_directory = os.path.split(d)
2109-
test_group_directory = os.path.basename(test_group_directory_path)
2110-
2111-
# Check to make sure discoverd folder is not in a host test directory or common directory
2112-
special_dirs = ['host_tests', 'COMMON']
2113-
if test_group_directory not in special_dirs and test_case_directory not in special_dirs:
2114-
test_name = test_path_to_name(d, base_dir)
2115-
tests[(test_name, walk_base_dir, test_group_directory, test_case_directory)] = [d]
2116-
2117-
# Also find any COMMON paths, we'll add these later once we find all the base tests
2118-
if 'COMMON' in relative_path_parts:
2119-
if relative_path_parts[0] != 'COMMON':
2120-
def predicate(base_pred, group_pred, name_base_group_case):
2121-
(name, base, group, case) = name_base_group_case
2122-
return base == base_pred and group == group_pred
2123-
commons.append((functools.partial(predicate, walk_base_dir, relative_path_parts[0]), d))
2124-
else:
2125-
def predicate(base_pred, name_base_group_case):
2126-
(name, base, group, case) = name_base_group_case
2127-
return base == base_pred
2128-
commons.append((functools.partial(predicate, walk_base_dir), d))
2091+
for test_group_directory in os.listdir(directory):
2092+
grp_dir = join(directory, test_group_directory)
2093+
if not isdir(grp_dir):
2094+
continue
2095+
for test_case_directory in os.listdir(grp_dir):
2096+
d = join(directory, test_group_directory, test_case_directory)
2097+
if not isdir(d):
2098+
continue
2099+
special_dirs = ['host_tests', 'COMMON']
2100+
if test_group_directory not in special_dirs and test_case_directory not in special_dirs:
2101+
test_name = test_path_to_name(d, base_dir)
2102+
tests[(test_name, directory, test_group_directory, test_case_directory)] = [d]
2103+
if test_case_directory == 'COMMON':
2104+
def predicate(base_pred, group_pred, name_base_group_case):
2105+
(name, base, group, case) = name_base_group_case
2106+
return base == base_pred and group == group_pred
2107+
commons.append((functools.partial(predicate, directory, test_group_directory), d))
2108+
if test_group_directory == 'COMMON':
2109+
def predicate(base_pred, name_base_group_case):
2110+
(name, base, group, case) = name_base_group_case
2111+
return base == base_pred
2112+
commons.append((functools.partial(predicate, directory), grp_dir))
21292113

21302114
# Apply common directories
21312115
for pred, path in commons:

tools/toolchains/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,10 @@ def copy_files(self, files_paths, trg_path, resources=None):
290290
if not isinstance(files_paths, list):
291291
files_paths = [files_paths]
292292

293-
for source in files_paths:
294-
if source is None:
295-
files_paths.remove(source)
296-
297-
for source in files_paths:
298-
_, relative_path = split(source)
299-
300-
target = join(trg_path, relative_path)
301-
293+
for dest, source in files_paths:
294+
target = join(trg_path, dest)
302295
if (target != source) and (self.need_update(target, [source])):
303-
self.progress("copy", relative_path)
296+
self.progress("copy", dest)
304297
mkdir(dirname(target))
305298
copyfile(source, target)
306299

0 commit comments

Comments
 (0)