Skip to content

IAR folder structure in project when exporting. #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 72 additions & 6 deletions workspace_tools/export/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
"""
from exporters import Exporter

import re

class IAREmbeddedWorkbench(Exporter):
NAME = 'IAR'
Expand Down Expand Up @@ -69,24 +69,90 @@ class IAREmbeddedWorkbench(Exporter):
]

def generate(self):

sources = []
sources += self.resources.c_sources
sources += self.resources.cpp_sources
sources += self.resources.s_sources
# binaries = ""
# if resources.bin_files is not None:
# binaries = resources.bin_files

iar_files = IAR_FOLDER("","",[])
for source in sources:
iar_files.insert_file(source)

ctx = {
'name': self.program_name,
'include_paths': self.resources.inc_dirs,
'linker_script': self.resources.linker_script,
'object_files': self.resources.objects,
'libraries': self.resources.libraries,
'symbols': self.get_symbols(),
'source_files': sources,
'source_files': iar_files.__str__(),
'binary_files': self.resources.bin_files,
}
self.gen_file('iar_%s.ewp.tmpl' % self.target.lower(), ctx, '%s.ewp' % self.program_name)
self.gen_file('iar.eww.tmpl', ctx, '%s.eww' % self.program_name)
self.gen_file('iar_%s.ewd.tmpl' % self.target.lower(), ctx, '%s.ewd' % self.program_name)

class IAR_FOLDER:
#input:
#folder_level : folder path to current folder
#folder_name : name of current folder
#source_files : list of source_files (all must be in same directory)
def __init__(self, folder_level, folder_name, source_files):
self.folder_level = folder_level
self.folder_name = folder_name
self.source_files = source_files
self.sub_folders = {};

def __str__(self):
group_start = ""
group_end = ""
if self.folder_name != "":
group_start = "<group>\n<name>%s</name>\n" %(self.folder_name)
group_end = "</group>\n"

str_content = group_start
#Add files in current folder
if self.source_files:
for src in self.source_files:
str_content += "<file>\n<name>$PROJ_DIR$\\%s</name>\n</file>\n" % src
##Add sub folders
if self.sub_folders:
for folder_name in self.sub_folders.iterkeys():
str_content += self.sub_folders[folder_name].__str__()

str_content += group_end
return str_content


def insert_file(self, source_input):
if self.source_files:
dir_sources = IAR_FOLDER.get_directory(self.source_files[0]) ##All source_files in a IAR_FOLDER must be in same directory.
if not self.folder_level == dir_sources: ## Check if sources are already at their deepest level.
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
folder_name = re.match( _reg_exp, dir_sources).group(1)
self.sub_folders[folder_name] = IAR_FOLDER(self.folder_level + "\\" + folder_name, folder_name, self.source_files)
self.source_files = []

dir_input = IAR_FOLDER.get_directory(source_input)
if dir_input == self.folder_level:
self.source_files.append(source_input)
else:
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
folder_name = re.match( _reg_exp, dir_input).group(1)
if self.sub_folders.has_key(folder_name):
self.sub_folders[folder_name].insert_file(source_input)
else:
if self.folder_level == "": #Top level exception
self.sub_folders[folder_name] = IAR_FOLDER(folder_name, folder_name, [source_input])
else:
self.sub_folders[folder_name] = IAR_FOLDER(self.folder_level + "\\" + folder_name, folder_name, [source_input])

@staticmethod
def get_directory(file_path):
dir_Match = re.match( r'(.*)[/\\][^/\\]+', file_path)
if dir_Match is not None:
return dir_Match.group(1)
else:
return ""


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_arch_ble.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -950,11 +950,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_arch_pro.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1823,11 +1823,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_delta_dfcm_nnn40.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -950,11 +950,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_hrm1017.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -950,11 +950,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_k20d50m.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_k22f.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_k64f.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_kl05z.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_kl25z.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_kl46z.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc1114.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc11u24.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc11u35_401.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc11u35_501.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc1347.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -953,11 +953,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc1549.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc1768.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1823,11 +1823,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc4088.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc4088_dm.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc812.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpc824.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


6 changes: 1 addition & 5 deletions workspace_tools/export/iar_lpccappuccino.ewp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,7 @@
<data/>
</settings>
</configuration>
{% for files in source_files %}
<file>
<name>$PROJ_DIR$\{{files}}</name>
</file>
{% endfor %}
{{source_files}}
</project>


Loading