Skip to content

Commit cf0ea92

Browse files
committed
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.
1 parent 7311a61 commit cf0ea92

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

tools/export/cmake/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ def generate(self):
7575
# sort includes reverse, so the deepest dir comes first (ensures short includes)
7676
includes = sorted([re.sub(r'^[.]/', '', l) for l in self.resources.inc_dirs], reverse=True)
7777

78-
# select dependant hex files to merge into compiled hex image
79-
hex_files = self.resources.hex_files
80-
if hasattr(self.toolchain.target, 'hex_filename'):
81-
hex_filename = self.toolchain.target.hex_filename
82-
hex_files = list(f for f in hex_files if basename(f) == hex_filename)
83-
8478
ctx = {
8579
'name': self.project_name,
8680
'target': self.target,
@@ -90,7 +84,7 @@ def generate(self):
9084
'include_paths': includes,
9185
'library_paths': sorted([re.sub(r'^[.]/', '', l) for l in self.resources.lib_dirs]),
9286
'linker_script': self.resources.linker_script,
93-
'hex_files': hex_files,
87+
'hex_files': self.hex_files,
9488
'ar': basename(self.toolchain.ar),
9589
'cc': basename(self.toolchain.cc[0]),
9690
'cc_flags': " ".join(flag for flag in self.toolchain.cc[1:] if not flag == "-c"),

tools/export/exporters.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ def libraries(self):
123123
return [l for l in self.resources.get_file_names(FileType.LIB)
124124
if l.endswith(self.toolchain.LIBRARY_EXT)]
125125

126+
@property
127+
def hex_files(self):
128+
"""Returns a list of hex files to include in the exported project"""
129+
hex_files = self.resources.hex_files
130+
if hasattr(self.toolchain.target, 'hex_filename'):
131+
hex_filename = self.toolchain.target.hex_filename
132+
hex_files = [f for f in hex_files if basename(f) == hex_filename]
133+
return hex_files
134+
126135
def toolchain_flags(self, toolchain):
127136
"""Returns a dictionary of toolchain flags.
128137
Keys of the dictionary are:

tools/export/makefile/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ def generate(self):
8484
sys_libs = [self.prepare_sys_lib(lib) for lib
8585
in self.toolchain.sys_libs]
8686

87-
hex_files = self.resources.hex_files
88-
if hasattr(self.toolchain.target, 'hex_filename'):
89-
hex_filename = self.toolchain.target.hex_filename
90-
hex_files = list(f for f in hex_files if basename(f) == hex_filename)
91-
9287
ctx = {
9388
'name': self.project_name,
9489
'to_be_compiled': to_be_compiled,
@@ -98,7 +93,7 @@ def generate(self):
9893
'linker_script': self.resources.linker_script,
9994
'libraries': libraries,
10095
'ld_sys_libs': sys_libs,
101-
'hex_files': hex_files,
96+
'hex_files': self.hex_files,
10297
'vpath': (["../../.."]
10398
if (basename(dirname(dirname(self.export_dir)))
10499
== "projectfiles")

0 commit comments

Comments
 (0)