mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			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.pull/9756/head
							parent
							
								
									7311a610e5
								
							
						
					
					
						commit
						cf0ea92104
					
				| 
						 | 
					@ -75,12 +75,6 @@ class CMake(Exporter):
 | 
				
			||||||
        # sort includes reverse, so the deepest dir comes first (ensures short includes)
 | 
					        # 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)
 | 
					        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 = {
 | 
					        ctx = {
 | 
				
			||||||
            'name': self.project_name,
 | 
					            'name': self.project_name,
 | 
				
			||||||
            'target': self.target,
 | 
					            'target': self.target,
 | 
				
			||||||
| 
						 | 
					@ -90,7 +84,7 @@ class CMake(Exporter):
 | 
				
			||||||
            'include_paths': includes,
 | 
					            'include_paths': includes,
 | 
				
			||||||
            'library_paths': sorted([re.sub(r'^[.]/', '', l) for l in self.resources.lib_dirs]),
 | 
					            'library_paths': sorted([re.sub(r'^[.]/', '', l) for l in self.resources.lib_dirs]),
 | 
				
			||||||
            'linker_script': self.resources.linker_script,
 | 
					            'linker_script': self.resources.linker_script,
 | 
				
			||||||
            'hex_files': hex_files,
 | 
					            'hex_files': self.hex_files,
 | 
				
			||||||
            'ar': basename(self.toolchain.ar),
 | 
					            'ar': basename(self.toolchain.ar),
 | 
				
			||||||
            'cc': basename(self.toolchain.cc[0]),
 | 
					            'cc': basename(self.toolchain.cc[0]),
 | 
				
			||||||
            'cc_flags': " ".join(flag for flag in self.toolchain.cc[1:] if not flag == "-c"),
 | 
					            'cc_flags': " ".join(flag for flag in self.toolchain.cc[1:] if not flag == "-c"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -123,6 +123,15 @@ class Exporter(object):
 | 
				
			||||||
        return [l for l in self.resources.get_file_names(FileType.LIB)
 | 
					        return [l for l in self.resources.get_file_names(FileType.LIB)
 | 
				
			||||||
                if l.endswith(self.toolchain.LIBRARY_EXT)]
 | 
					                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):
 | 
					    def toolchain_flags(self, toolchain):
 | 
				
			||||||
        """Returns a dictionary of toolchain flags.
 | 
					        """Returns a dictionary of toolchain flags.
 | 
				
			||||||
        Keys of the dictionary are:
 | 
					        Keys of the dictionary are:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,11 +84,6 @@ class Makefile(Exporter):
 | 
				
			||||||
        sys_libs = [self.prepare_sys_lib(lib) for lib
 | 
					        sys_libs = [self.prepare_sys_lib(lib) for lib
 | 
				
			||||||
                    in self.toolchain.sys_libs]
 | 
					                    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 = {
 | 
					        ctx = {
 | 
				
			||||||
            'name': self.project_name,
 | 
					            'name': self.project_name,
 | 
				
			||||||
            'to_be_compiled': to_be_compiled,
 | 
					            'to_be_compiled': to_be_compiled,
 | 
				
			||||||
| 
						 | 
					@ -98,7 +93,7 @@ class Makefile(Exporter):
 | 
				
			||||||
            'linker_script': self.resources.linker_script,
 | 
					            'linker_script': self.resources.linker_script,
 | 
				
			||||||
            'libraries': libraries,
 | 
					            'libraries': libraries,
 | 
				
			||||||
            'ld_sys_libs': sys_libs,
 | 
					            'ld_sys_libs': sys_libs,
 | 
				
			||||||
            'hex_files': hex_files,
 | 
					            'hex_files': self.hex_files,
 | 
				
			||||||
            'vpath': (["../../.."]
 | 
					            'vpath': (["../../.."]
 | 
				
			||||||
                      if (basename(dirname(dirname(self.export_dir)))
 | 
					                      if (basename(dirname(dirname(self.export_dir)))
 | 
				
			||||||
                          == "projectfiles")
 | 
					                          == "projectfiles")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue