14
14
See the License for the specific language governing permissions and
15
15
limitations under the License.
16
16
"""
17
- from exporters import Exporter
17
+ from workspace_tools . export . exporters import Exporter
18
18
import re
19
19
import os
20
- from os .path import join , dirname
21
20
class IAREmbeddedWorkbench (Exporter ):
21
+ """
22
+ Exporter class for IAR Systems.
23
+ """
22
24
NAME = 'IAR'
23
25
TOOLCHAIN = 'IAR'
24
26
@@ -71,15 +73,18 @@ class IAREmbeddedWorkbench(Exporter):
71
73
]
72
74
73
75
def generate (self ):
76
+ """
77
+ Generates the project files
78
+ """
74
79
sources = []
75
80
sources += self .resources .c_sources
76
81
sources += self .resources .cpp_sources
77
82
sources += self .resources .s_sources
78
-
79
- iar_files = IAR_FOLDER ("" ,"" ,[])
83
+
84
+ iar_files = IarFolder ("" , "" , [])
80
85
for source in sources :
81
86
iar_files .insert_file (source )
82
-
87
+
83
88
ctx = {
84
89
'name' : self .program_name ,
85
90
'include_paths' : self .resources .inc_dirs ,
@@ -94,18 +99,31 @@ def generate(self):
94
99
self .gen_file ('iar.eww.tmpl' , ctx , '%s.eww' % self .program_name )
95
100
self .gen_file ('iar_%s.ewd.tmpl' % self .target .lower (), ctx , '%s.ewd' % self .program_name )
96
101
97
- class IAR_FOLDER :
98
- #input:
99
- #folder_level : folder path to current folder
100
- #folder_name : name of current folder
101
- #source_files : list of source_files (all must be in same directory)
102
+ class IarFolder ():
103
+ """
104
+ This is a recursive folder object.
105
+ To present the folder structure in the IDE as it is presented on the disk.
106
+ This can be used for uvision as well if you replace the __str__ method.
107
+ Example:
108
+ files: ./main.cpp, ./apis/I2C.h, ./mbed/common/I2C.cpp
109
+ in the project this would look like:
110
+ main.cpp
111
+ common/I2C.cpp
112
+ input:
113
+ folder_level : folder path to current folder
114
+ folder_name : name of current folder
115
+ source_files : list of source_files (all must be in same directory)
116
+ """
102
117
def __init__ (self , folder_level , folder_name , source_files ):
103
118
self .folder_level = folder_level
104
119
self .folder_name = folder_name
105
120
self .source_files = source_files
106
- self .sub_folders = {};
107
-
121
+ self .sub_folders = {}
122
+
108
123
def __str__ (self ):
124
+ """
125
+ converts the folder structue to IAR project format.
126
+ """
109
127
group_start = ""
110
128
group_end = ""
111
129
if self .folder_name != "" :
@@ -117,41 +135,46 @@ def __str__(self):
117
135
if self .source_files :
118
136
for src in self .source_files :
119
137
str_content += "<file>\n <name>$PROJ_DIR$/%s</name>\n </file>\n " % src
120
- ## Add sub folders
138
+ #Add sub folders
121
139
if self .sub_folders :
122
140
for folder_name in self .sub_folders .iterkeys ():
123
141
str_content += self .sub_folders [folder_name ].__str__ ()
124
-
142
+
125
143
str_content += group_end
126
144
return str_content
127
-
128
-
145
+
129
146
def insert_file (self , source_input ):
130
-
131
- if self .source_files :
132
- dir_sources = IAR_FOLDER .get_directory (self .source_files [0 ]) ##All source_files in a IAR_FOLDER must be in same directory.
133
- if not self .folder_level == dir_sources : ## Check if sources are already at their deepest level.
147
+ """
148
+ Inserts a source file into the folder tree
149
+ """
150
+ if self .source_files :
151
+ #All source_files in a IarFolder must be in same directory.
152
+ dir_sources = IarFolder .get_directory (self .source_files [0 ])
153
+ #Check if sources are already at their deepest level.
154
+ if not self .folder_level == dir_sources :
134
155
_reg_exp = r"^" + re .escape (self .folder_level ) + r"[/\\]?([^/\\]+)"
135
- folder_name = re .match ( _reg_exp , dir_sources ).group (1 )
136
- self .sub_folders [folder_name ] = IAR_FOLDER (os .path .join (self .folder_level ,folder_name ), folder_name , self .source_files )
156
+ folder_name = re .match (_reg_exp , dir_sources ).group (1 )
157
+ self .sub_folders [folder_name ] = IarFolder (os .path .join (self .folder_level , folder_name ), folder_name , self .source_files )
137
158
self .source_files = []
138
-
139
- dir_input = IAR_FOLDER .get_directory (source_input )
159
+
160
+ dir_input = IarFolder .get_directory (source_input )
140
161
if dir_input == self .folder_level :
141
162
self .source_files .append (source_input )
142
163
else :
143
164
_reg_exp = r"^" + re .escape (self .folder_level ) + r"[/\\]?([^/\\]+)"
144
- folder_name = re .match ( _reg_exp , dir_input ).group (1 )
165
+ folder_name = re .match (_reg_exp , dir_input ).group (1 )
145
166
if self .sub_folders .has_key (folder_name ):
146
167
self .sub_folders [folder_name ].insert_file (source_input )
147
168
else :
148
- if self .folder_level == "" : #Top level exception
149
- self .sub_folders [folder_name ] = IAR_FOLDER (folder_name , folder_name , [source_input ])
169
+ if self .folder_level == "" :
170
+ #Top level exception
171
+ self .sub_folders [folder_name ] = IarFolder (folder_name , folder_name , [source_input ])
150
172
else :
151
- self .sub_folders [folder_name ] = IAR_FOLDER (os .path .join (self .folder_level ,folder_name ), folder_name , [source_input ])
173
+ self .sub_folders [folder_name ] = IarFolder (os .path .join (self .folder_level , folder_name ), folder_name , [source_input ])
152
174
153
- @staticmethod
175
+ @staticmethod
154
176
def get_directory (file_path ):
177
+ """
178
+ Returns the directory of the file
179
+ """
155
180
return os .path .dirname (file_path )
156
-
157
-
0 commit comments