Skip to content

Commit 189a6f2

Browse files
committed
Fix Mbed OS 2 build for Public/Internal headers relocating
Modify compilation API to provide a list of paths to exclude from the build.
1 parent 1168a66 commit 189a6f2

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

tools/build_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
10751075
# Build Things
10761076
notify.info("Building library %s (%s, %s)" %
10771077
('MBED', target.name, toolchain_name))
1078-
objects = toolchain.compile_sources(
1078+
objects = toolchain.compile_legacy_sources(
10791079
mbed_resources, incdirs, exclude_paths
10801080
)
10811081
separate_objects = []

tools/toolchains/mbed_toolchain.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -395,29 +395,48 @@ def get_arch_file(self, objects):
395395
cmd_list = (c.replace("\\", "/") for c in objects if c)
396396
return self.make_option_file(list(cmd_list), ".archive_files.txt")
397397

398+
def compile_legacy_sources(
399+
self, resources, inc_dirs=None, exclude_dirs=None
400+
):
401+
"""Compile source files with option to exclude some directories.
402+
403+
This method only exists to not break API compatibility and provide a
404+
way to exclude directories for Mbed OS 2 builds.
405+
"""
406+
return self._compile_sources(
407+
resources, inc_dirs=inc_dirs, exclude_dirs=exclude_dirs
408+
)
409+
398410
# THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
399411
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
400-
def compile_sources(self, resources, inc_dirs=None, exclude_paths=None):
412+
def compile_sources(self, resources, inc_dirs=None):
413+
"""Compile source files."""
414+
return self._compile_sources(resources, inc_dirs=inc_dirs)
415+
416+
def _exclude_files_from_build(self, files_to_compile, exclude_dirs):
417+
"""Remove files from dirs to be excluded for the build."""
418+
return [
419+
file_to_compile
420+
for file_to_compile in files_to_compile
421+
if all(
422+
exclude_dir not in file_to_compile.path
423+
for exclude_dir in exclude_dirs
424+
)
425+
]
426+
427+
def _compile_sources(self, resources, inc_dirs=None, exclude_dirs=None):
401428
# Web IDE progress bar for project build
402429
files_to_compile = (
403430
resources.get_file_refs(FileType.ASM_SRC) +
404431
resources.get_file_refs(FileType.C_SRC) +
405432
resources.get_file_refs(FileType.CPP_SRC)
406433
)
407-
# Remove files from paths to be excluded from the build and create
408-
# a compilation queue.
409-
compile_queue = (
434+
compilation_queue = (
410435
files_to_compile
411-
if not exclude_paths
412-
else [
413-
file_to_compile
414-
for exclude_path in exclude_paths
415-
for file_to_compile in files_to_compile
416-
if exclude_path not in file_to_compile.path
417-
]
436+
if not exclude_dirs
437+
else self._exclude_files_from_build(files_to_compile, exclude_dirs)
418438
)
419-
420-
self.to_be_compiled = len(compile_queue)
439+
self.to_be_compiled = len(compilation_queue)
421440
self.compiled = 0
422441

423442
self.notify.cc_verbose("Macros: " + ' '.join([
@@ -447,8 +466,8 @@ def compile_sources(self, resources, inc_dirs=None, exclude_paths=None):
447466
self.dump_build_profile()
448467

449468
# Sort compile queue for consistency
450-
compile_queue.sort()
451-
for source in compile_queue:
469+
compilation_queue.sort()
470+
for source in compilation_queue:
452471
object = self.relative_object_path(self.build_dir, source)
453472

454473
# Queue mode (multiprocessing)

0 commit comments

Comments
 (0)