From 7311a610e5a094729881c8d36b3e460d69db5dca Mon Sep 17 00:00:00 2001 From: Volodymyr Medvid Date: Tue, 5 Feb 2019 18:28:57 +0200 Subject: [PATCH 1/2] PSOC6: enable export to CMake The approach for the hex_files subset selection is identical to makefile exporter: https://github.com/ARMmbed/mbed-os/pull/9466 Single hex file should be passed to srec_cat when hex_filename is set in targets.json or mbed_app.json. --- tools/export/cmake/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/export/cmake/__init__.py b/tools/export/cmake/__init__.py index 5cf7caa95d..10c5de002b 100644 --- a/tools/export/cmake/__init__.py +++ b/tools/export/cmake/__init__.py @@ -44,7 +44,8 @@ class CMake(Exporter): "MCU_NRF51Code.binary_hook", "TEENSY3_1Code.binary_hook", "LPCTargetCode.lpc_patch", - "LPC4088Code.binary_hook" + "LPC4088Code.binary_hook", + "PSOC6Code.complete" ]) @classmethod @@ -74,6 +75,12 @@ class CMake(Exporter): # sort includes reverse, so the deepest dir comes first (ensures short includes) includes = sorted([re.sub(r'^[.]/', '', l) for l in self.resources.inc_dirs], reverse=True) + # select dependant hex files to merge into compiled hex image + hex_files = self.resources.hex_files + if hasattr(self.toolchain.target, 'hex_filename'): + hex_filename = self.toolchain.target.hex_filename + hex_files = list(f for f in hex_files if basename(f) == hex_filename) + ctx = { 'name': self.project_name, 'target': self.target, @@ -83,7 +90,7 @@ class CMake(Exporter): 'include_paths': includes, 'library_paths': sorted([re.sub(r'^[.]/', '', l) for l in self.resources.lib_dirs]), 'linker_script': self.resources.linker_script, - 'hex_files': self.resources.hex_files, + 'hex_files': hex_files, 'ar': basename(self.toolchain.ar), 'cc': basename(self.toolchain.cc[0]), 'cc_flags': " ".join(flag for flag in self.toolchain.cc[1:] if not flag == "-c"), From cf0ea921046c4c4eb8102f7e9cc72dec86ec6242 Mon Sep 17 00:00:00 2001 From: Volodymyr Medvid Date: Tue, 19 Feb 2019 20:03:00 +0200 Subject: [PATCH 2/2] tools/export: move hex_files selection to base Exporter class CMake and makefile exporters share a common logic for hex file selection. Factor it as a common property in the base class to avoid code duplication. --- tools/export/cmake/__init__.py | 8 +------- tools/export/exporters.py | 9 +++++++++ tools/export/makefile/__init__.py | 7 +------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tools/export/cmake/__init__.py b/tools/export/cmake/__init__.py index 10c5de002b..67216544e1 100644 --- a/tools/export/cmake/__init__.py +++ b/tools/export/cmake/__init__.py @@ -75,12 +75,6 @@ class CMake(Exporter): # sort includes reverse, so the deepest dir comes first (ensures short includes) includes = sorted([re.sub(r'^[.]/', '', l) for l in self.resources.inc_dirs], reverse=True) - # select dependant hex files to merge into compiled hex image - hex_files = self.resources.hex_files - if hasattr(self.toolchain.target, 'hex_filename'): - hex_filename = self.toolchain.target.hex_filename - hex_files = list(f for f in hex_files if basename(f) == hex_filename) - ctx = { 'name': self.project_name, 'target': self.target, @@ -90,7 +84,7 @@ class CMake(Exporter): 'include_paths': includes, 'library_paths': sorted([re.sub(r'^[.]/', '', l) for l in self.resources.lib_dirs]), 'linker_script': self.resources.linker_script, - 'hex_files': hex_files, + 'hex_files': self.hex_files, 'ar': basename(self.toolchain.ar), 'cc': basename(self.toolchain.cc[0]), 'cc_flags': " ".join(flag for flag in self.toolchain.cc[1:] if not flag == "-c"), diff --git a/tools/export/exporters.py b/tools/export/exporters.py index 61e91f48a0..a1d46c43e3 100644 --- a/tools/export/exporters.py +++ b/tools/export/exporters.py @@ -123,6 +123,15 @@ class Exporter(object): return [l for l in self.resources.get_file_names(FileType.LIB) if l.endswith(self.toolchain.LIBRARY_EXT)] + @property + def hex_files(self): + """Returns a list of hex files to include in the exported project""" + hex_files = self.resources.hex_files + if hasattr(self.toolchain.target, 'hex_filename'): + hex_filename = self.toolchain.target.hex_filename + hex_files = [f for f in hex_files if basename(f) == hex_filename] + return hex_files + def toolchain_flags(self, toolchain): """Returns a dictionary of toolchain flags. Keys of the dictionary are: diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index c4d7412a0a..830c2cb252 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -84,11 +84,6 @@ class Makefile(Exporter): sys_libs = [self.prepare_sys_lib(lib) for lib in self.toolchain.sys_libs] - hex_files = self.resources.hex_files - if hasattr(self.toolchain.target, 'hex_filename'): - hex_filename = self.toolchain.target.hex_filename - hex_files = list(f for f in hex_files if basename(f) == hex_filename) - ctx = { 'name': self.project_name, 'to_be_compiled': to_be_compiled, @@ -98,7 +93,7 @@ class Makefile(Exporter): 'linker_script': self.resources.linker_script, 'libraries': libraries, 'ld_sys_libs': sys_libs, - 'hex_files': hex_files, + 'hex_files': self.hex_files, 'vpath': (["../../.."] if (basename(dirname(dirname(self.export_dir))) == "projectfiles")