ebngen 1.0.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,75 +1,75 @@
1
- require 'pathname'
2
-
3
- $CMAKE_HEADER = %Q{
4
- INCLUDE(CMakeForceCompiler)
5
- # CROSS COMPILER SETTING
6
- SET(CMAKE_SYSTEM_NAME Generic)
7
- CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
8
-
9
- # THE VERSION NUMBER
10
- SET (Tutorial_VERSION_MAJOR 1)
11
- SET (Tutorial_VERSION_MINOR 0)
12
-
13
- # ENABLE ASM
14
- ENABLE_LANGUAGE(C ASM)
15
-
16
- SET(CMAKE_STATIC_LIBRARY_PREFIX)
17
- SET(CMAKE_STATIC_LIBRARY_SUFFIX)
18
-
19
- SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
20
- SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)
21
-
22
-
23
- # CURRENT DIRECTORY
24
- SET(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR})
25
- }
26
-
27
- $CONFIG_SETTINGS = [
28
- :cp_defines ,
29
- :as_predefines,
30
- :as_defines,
31
- :as_flags,
32
- :as_preincludes ,
33
- :as_include,
34
- :cc_predefines,
35
- :cc_defines,
36
- :cc_flags,
37
- :cc_preincludes,
38
- :cc_include,
39
- :cxx_predefines,
40
- :cxx_defines,
41
- :cxx_flags,
42
- :cxx_preincludes,
43
- :cxx_include,
44
- :ld_flags,
45
- :linker_file
46
- ]
47
-
48
-
49
- module TXT
50
- def save(path, data_hash)
51
- FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
52
- File.open(path, 'w+') do |file|
53
- file.write($CMAKE_HEADER)
54
- data_hash["target"].each_key do |target|
55
- $CONFIG_SETTINGS.each do |key|
56
- next if ! data_hash["target"][target].has_key?(key.to_s)
57
- data_hash["target"][target][key.to_s].each do |line|
58
- file.puts(line)
59
- end
60
- end
61
- end
62
- binary = data_hash["document"]["project_name"]
63
- case data_hash["type"].upcase
64
- when "APPLICATION"
65
- file.puts("add_executable(#{binary}.elf")
66
- else
67
- file.puts("add_library(STATIC #{binary}.a")
68
- end
69
- data_hash["sources"].each do |line|
70
- file.puts line
71
- end
72
- file.puts(")")
73
- end
74
- end
75
- end
1
+ require 'pathname'
2
+
3
+ $CMAKE_HEADER = %Q{
4
+ INCLUDE(CMakeForceCompiler)
5
+ # CROSS COMPILER SETTING
6
+ SET(CMAKE_SYSTEM_NAME Generic)
7
+ CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
8
+
9
+ # THE VERSION NUMBER
10
+ SET (Tutorial_VERSION_MAJOR 1)
11
+ SET (Tutorial_VERSION_MINOR 0)
12
+
13
+ # ENABLE ASM
14
+ ENABLE_LANGUAGE(C ASM)
15
+
16
+ SET(CMAKE_STATIC_LIBRARY_PREFIX)
17
+ SET(CMAKE_STATIC_LIBRARY_SUFFIX)
18
+
19
+ SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
20
+ SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)
21
+
22
+
23
+ # CURRENT DIRECTORY
24
+ SET(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR})
25
+ }
26
+
27
+ $CONFIG_SETTINGS = [
28
+ :cp_defines ,
29
+ :as_predefines,
30
+ :as_defines,
31
+ :as_flags,
32
+ :as_preincludes ,
33
+ :as_include,
34
+ :cc_predefines,
35
+ :cc_defines,
36
+ :cc_flags,
37
+ :cc_preincludes,
38
+ :cc_include,
39
+ :cxx_predefines,
40
+ :cxx_defines,
41
+ :cxx_flags,
42
+ :cxx_preincludes,
43
+ :cxx_include,
44
+ :ld_flags,
45
+ :linker_file
46
+ ]
47
+
48
+
49
+ module TXT
50
+ def save(path, data_hash)
51
+ FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
52
+ File.open(path, 'w+') do |file|
53
+ file.write($CMAKE_HEADER)
54
+ data_hash["target"].each_key do |target|
55
+ $CONFIG_SETTINGS.each do |key|
56
+ next if ! data_hash["target"][target].has_key?(key.to_s)
57
+ data_hash["target"][target][key.to_s].each do |line|
58
+ file.puts(line)
59
+ end
60
+ end
61
+ end
62
+ binary = data_hash["document"]["project_name"]
63
+ case data_hash["type"].upcase
64
+ when "APPLICATION"
65
+ file.puts("add_executable(#{binary}.elf")
66
+ else
67
+ file.puts("add_library(STATIC #{binary}.a")
68
+ end
69
+ data_hash["sources"].each do |line|
70
+ file.puts line
71
+ end
72
+ file.puts(")")
73
+ end
74
+ end
75
+ end
@@ -1,460 +1,460 @@
1
-
2
- require_relative '_base'
3
- require_relative '_yml_helper'
4
- require_relative '_path_modifier'
5
- require_relative 'iar/eww'
6
- require_relative 'iar/ewp'
7
- require_relative 'iar/ewd'
8
-
9
- #replace me when yml_merger becomes gem
10
- require 'yml_merger'
11
- require 'nokogiri'
12
- require 'uri'
13
- require 'open-uri'
14
-
15
- module IAR
16
- class Project
17
- TOOLCHAIN='iar'
18
- include Base
19
- include EWP
20
- include EWD
21
- include UNI_Project
22
-
23
- def initialize(project_data, generator_variable, logger = nil)
24
- @logger = logger
25
- unless (logger)
26
- @logger = Logger.new(STDOUT)
27
- @logger.level = Logger::WARN
28
- end
29
- set_hash(project_data)
30
- @project_name = get_project_name()
31
- @board = get_board()
32
- @paths = PathModifier.new(generator_variable["paths"])
33
- @iar_project_files = {".ewp" => nil, ".dni" => nil, ".ewd" => nil, ".yml" => nil}
34
- return nil if get_template(Project::TOOLCHAIN).nil?
35
- get_template(Project::TOOLCHAIN).each do |template|
36
- @logger.info template
37
- ext = File.extname(template)
38
- if @iar_project_files.keys.include?(ext)
39
- path = @paths.fullpath("default_path",template)
40
- #begin
41
- case ext
42
- when ".ewp"
43
- doc = Nokogiri::XML(open(path))
44
- @iar_project_files[ext] = doc
45
- when ".ewd"
46
- doc = Nokogiri::XML(open(path))
47
- @iar_project_files[ext] = doc
48
- when ".dni"
49
- doc = Nokogiri::XML(open(path))
50
- @iar_project_files[ext] = doc
51
- end
52
- #rescue
53
- # @logger.info "failed to open #{template}"
54
- #end
55
- end
56
- end
57
- end
58
-
59
- def generator(filter, project_data)
60
- return if not is_toolchain_support(Project::TOOLCHAIN)
61
- create_method( Project::TOOLCHAIN)
62
- send(Project::TOOLCHAIN.to_sym, project_data)
63
- save_project()
64
- end
65
-
66
- def source()
67
- #add sources to target
68
- return if @iar_project_files['.ewp'].nil?
69
- remove_sources(@iar_project_files['.ewp'])
70
- sources = get_src_list(Project::TOOLCHAIN)
71
- o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
72
- proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
73
- add_sources(@iar_project_files['.ewp'], sources, @paths, proj_path)
74
- end
75
-
76
- def templates()
77
- #load tempaltes
78
- end
79
-
80
- def type()
81
- #set project type
82
- end
83
-
84
- def document()
85
- project_name = get_project_name()
86
-
87
- end
88
-
89
- def targets()
90
- convert_lut = {
91
- 'cx_flags' => 'cxx_flags',
92
- 'cc_define' => 'cc_defines',
93
- 'cx_define' => 'cxx_defines',
94
- 'as_define' => 'as_defines',
95
- 'cp_define' => 'cp_defines',
96
- 'ar_flags' => 'ar_flags'
97
- }
98
- get_targets(Project::TOOLCHAIN).each do |key, value|
99
- next if value.nil?
100
- #add target for ewp
101
- t = new_target(key, @iar_project_files['.ewp'])
102
- if t.nil?
103
- @logger.info "missing default debug configuration in template"
104
- return
105
- end
106
- #do the target settings
107
- value.each_key do |subkey|
108
- #for backward compatible
109
- temp_op = subkey.gsub('-', '_')
110
- if convert_lut.has_key? temp_op
111
- target_op = convert_lut[temp_op]
112
- else
113
- target_op = temp_op
114
- end
115
- methods = self.class.instance_methods(false)
116
- if methods.include?("target_#{target_op}".to_sym)
117
- send("target_#{target_op}".to_sym, t, value[subkey])
118
- else
119
- @logger.info "#{subkey} is not processed try to use the tool-chain specific"
120
- end
121
- end
122
- end
123
- remove_targets(@iar_project_files['.ewp'], get_target_list(Project::TOOLCHAIN))
124
- end
125
-
126
- # tool_chain_specific attribute for each target
127
- # Params:
128
- # - target_node: the xml node of given target
129
- # - doc: the hash that holds the data
130
- def target_tool_chain_set_spec(target_node, doc)
131
- set_specific(target_node, doc)
132
- end
133
-
134
- def target_tool_chain_add_spec(target_node, doc)
135
- add_specific(target_node, doc)
136
- end
137
-
138
- def save_project()
139
- path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
140
- save(@iar_project_files['.ewp'], File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.ewp"))
141
- end
142
-
143
- def target_cp_defines(target_node, doc)
144
- value = doc.values.join(" ")
145
- settings = {'OGChipSelectEditMenu' => {
146
- 'state' => doc.keys.join("") + "\t" + value
147
- }
148
- }
149
- set_specific(target_node, settings)
150
- settings = {'GEndianModeBE' => {
151
- 'state' => '1'
152
- }
153
- }
154
- set_specific(target_node, settings)
155
- end
156
-
157
- def target_as_predefines(target_node, doc)
158
-
159
- end
160
-
161
- def target_as_defines(target_node, doc)
162
- defines_array = Array.new
163
- doc.each do |item|
164
- if item.class == Hash
165
- item.each do |key, value|
166
- defines_array.insert(-1, "#{key}=#{value}")
167
- end
168
- else
169
- defines_array.insert(-1, item)
170
- end
171
- end
172
- settings = {'ADefines' => {
173
- 'state' => defines_array
174
- }
175
- }
176
- add_specific(target_node, settings)
177
- end
178
-
179
- def target_as_include(target_node, doc)
180
- o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
181
- proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
182
- settings = {'AUserIncludes' => {} }
183
- inc_array = Array.new
184
- doc.each do |item|
185
- if item['rootdir']
186
- full_path = @paths.fullpath(item['rootdir'],item['path'])
187
- else
188
- full_path = @paths.fullpath('default_path',item['path'])
189
- end
190
- inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
191
- end
192
- settings['AUserIncludes']['state'] = inc_array
193
- add_specific(target_node, settings)
194
- end
195
-
196
- def target_as_flags(target_node, doc)
197
- flags_array = Array.new
198
- doc.each do |item|
199
- if item.class == Hash
200
- item.each do |key, value|
201
- flags_array.insert(-1, "#{key}=#{value}")
202
- end
203
- else
204
- flags_array.insert(-1, item)
205
- end
206
- end
207
- settings = {'AExtraOptionsV2' => {
208
- 'state' => flags_array
209
- }
210
- }
211
- add_specific(target_node, settings)
212
- end
213
-
214
- def target_cc_predefines(target_node, doc)
215
-
216
- end
217
-
218
- def target_cc_preincludes(target_node, doc)
219
- o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
220
- proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
221
- settings = {'PreInclude' => {} }
222
- inc_array = Array.new
223
- doc.each do |item|
224
- if item['rootdir']
225
- full_path = @paths.fullpath(item['rootdir'],item['path'])
226
- else
227
- full_path = @paths.fullpath('default_path',item['path'])
228
- end
229
- inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
230
- end
231
- settings['PreInclude']['state'] = inc_array
232
- add_specific(target_node, settings)
233
- end
234
-
235
- def target_cc_defines(target_node, doc)
236
- defines_array = Array.new
237
- doc.each do |item, item_value|
238
- if item_value.nil?
239
- defines_array.insert(-1, "#{item}")
240
- else
241
- defines_array.insert(-1, "#{item}=#{item_value}")
242
- end
243
- end
244
- settings = {'CCDefines' => {
245
- 'state' => defines_array
246
- }
247
- }
248
- add_specific(target_node, settings)
249
- end
250
-
251
- def target_cc_include(target_node, doc)
252
- o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
253
- proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
254
- settings = {'CCIncludePath2' => {} }
255
- inc_array = Array.new
256
- doc.each do |item|
257
- if item['rootdir']
258
- full_path = @paths.fullpath(item['rootdir'],item['path'])
259
- else
260
- full_path = @paths.fullpath('default_path',item['path'])
261
- end
262
- inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
263
- end
264
- settings['CCIncludePath2']['state'] = inc_array
265
- add_specific(target_node, settings)
266
- end
267
-
268
- def target_cc_flags(target_node, doc)
269
- settings_check = { 'IExtraOptionsCheck' => {
270
- 'state' => '1'
271
- }
272
- }
273
- add_specific(target_node, settings_check)
274
- settings = {'IExtraOptions' => {
275
- 'state' => doc
276
- }
277
- }
278
- add_specific(target_node, settings)
279
- end
280
-
281
- def target_cxx_predefines(target_node, doc)
282
- target_cc_predefines(target_node, doc)
283
- end
284
-
285
- def target_cxx_preincludes(target_node, doc)
286
- target_cc_preincludes(target_node, doc)
287
- end
288
-
289
- def target_cxx_defines(target_node, doc)
290
- target_cc_defines(target_node, doc)
291
- end
292
-
293
- def target_cxx_include(target_node, doc)
294
- target_cc_include(target_node, doc)
295
- end
296
-
297
- def target_cxx_flags(target_node, doc)
298
- target_cc_flags(target_node, doc)
299
- end
300
-
301
- def target_ld_flags(target_node, doc)
302
- settings = {'IlinkConfigDefines' => {
303
- 'state' => doc
304
- }
305
- }
306
- add_specific(target_node, settings)
307
- end
308
-
309
- def target_libraries(target_node, doc)
310
- settings = {'IlinkAdditionalLibs' => {
311
- 'state' => doc
312
- }
313
- }
314
- add_specific(target_node, settings)
315
- end
316
-
317
- def target_linker_file(target_node, doc)
318
- settings_check = { 'IlinkIcfOverride' => {
319
- 'state' => 1
320
- }
321
- }
322
- add_specific(target_node, settings_check)
323
- o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
324
- proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
325
- settings = {'IlinkIcfFile' => {} }
326
- inc_array = Array.new
327
- if doc.has_key?("rootdir")
328
- full_path = @paths.fullpath(doc['rootdir'],doc['path'])
329
- else
330
- full_path = @paths.fullpath('default_path',doc['path'])
331
- end
332
- inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
333
- settings['IlinkIcfFile']['state'] = inc_array.join(" ")
334
- add_specific(target_node, settings)
335
- end
336
-
337
- def target_outdir(target_node, doc)
338
- =begin
339
- <option>
340
- <name>IlinkOutputFile</name>
341
- <state>K70_pit_drivers_test.out</state>
342
- </option>
343
- =end
344
- settings = { 'IlinkOutputFile' => {
345
- 'state' => "#{get_project_name()}.out"
346
- }
347
- }
348
- set_specific(target_node, settings)
349
- end
350
-
351
- end
352
-
353
- class Project_set
354
- include EWW
355
- include UNI_Project
356
- TOOLCHAIN='iar'
357
-
358
- # initialize EWW class
359
- # PARAMS:
360
- # - project_data: specific project data format for a application/library
361
- # - generator_variable: all dependency in hash
362
- def initialize(project_data, generator_variable, logger = nil)
363
- @logger = logger
364
- unless (logger)
365
- @logger = Logger.new(STDOUT)
366
- @logger.level = Logger::WARN
367
- end
368
- set_hash(project_data)
369
- @project_name = get_project_name()
370
- @board = get_board()
371
- @paths = PathModifier.new(generator_variable["paths"])
372
- @all_projects_hash = generator_variable["all"]
373
- @iar_project_files = {".eww" => nil}
374
- return nil if get_template(Project_set::TOOLCHAIN).nil?
375
- get_template(Project_set::TOOLCHAIN).each do |template|
376
- ext = File.extname(template)
377
- if @iar_project_files.keys.include?(ext)
378
- path = @paths.fullpath("default_path",template)
379
- doc = Nokogiri::XML(open(path))
380
- case ext
381
- when ".eww"
382
- @iar_project_files[ext] = doc
383
- else
384
- @logger.info "#{ext} not processed"
385
- end
386
- end
387
- end
388
- #clean the wrkspace in template
389
- @iar_project_files[".eww"].css("workspace/project").each do |node|
390
- node.remove
391
- end
392
- @iar_project_files[".eww"].css("workspace/batchBuild/batchDefinition").each do |node|
393
- node.remove
394
- end
395
- end
396
-
397
- def generator()
398
- return if not is_toolchain_support(Project::TOOLCHAIN)
399
- add_project_to_set()
400
- save_set()
401
- end
402
-
403
-
404
- def add_project_to_set()
405
- return if @iar_project_files.nil?
406
- return if @iar_project_files['.eww'].nil?
407
- ext = ".eww"
408
-
409
- #batch build mode is add
410
- get_target_list(Project_set::TOOLCHAIN).each do |target|
411
- add_batch_project_target(@iar_project_files[ext], "all", @project_name, target)
412
- add_batch_project_target(@iar_project_files[ext], target, @project_name, target)
413
- next if get_libraries(Project_set::TOOLCHAIN).nil?
414
- get_libraries(Project_set::TOOLCHAIN).each do |lib|
415
- add_batch_project_target(@iar_project_files[ext], "all", lib, target)
416
- add_batch_project_target(@iar_project_files[ext], target, lib, target)
417
- end
418
- end
419
- #add projects
420
- file = "#{@project_name}_#{@board}.ewp"
421
- path = File.join('$WS_DIR$',file)
422
- add_project(@iar_project_files[ext], path)
423
- #add library projects here
424
- #get from dependency['libraries'][library_name]
425
- ustruct = @all_projects_hash
426
- return if get_libraries(Project_set::TOOLCHAIN).nil?
427
- get_libraries(Project_set::TOOLCHAIN).each do |lib|
428
- if ustruct[lib].nil?
429
- @logger.info "#{lib} information is missing in all hash"
430
- next
431
- end
432
- libname = "#{@project_name}.ewp"
433
- root = @paths.rootdir_table[@ustruct[library][tool_key]['outdir']['root-dir']]
434
- lib_path = File.join(root, @ustruct[library][tool_key]['outdir']['path'], libname)
435
- if @ustruct[ project_name ][ tool_key ].has_key?('outdir')
436
- ewwpath = File.join(@output_rootdir, @ustruct[ project_name ][ tool_key ][ 'outdir' ] )
437
- else
438
- ewwpath = @output_rootdir
439
- end
440
- path = Pathname.new(lib_path).relative_path_from(Pathname.new(ewwpath))
441
- #more to come
442
- end
443
-
444
- end
445
-
446
- def save_set()
447
- path = get_output_dir(Project_set::TOOLCHAIN, @paths.rootdir_table)
448
- @logger.info @paths.rootdir_table['output_root']
449
- @logger.info path
450
- @logger.info "#{@project_name}_#{@board}.eww"
451
- if path.class == Hash
452
- save(@iar_project_files['.eww'], File.join(@paths.rootdir_table[path['rootdir']], path['path'], "#{@project_name}_#{@board}.eww"))
453
- else
454
- save(@iar_project_files['.eww'], File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.eww"))
455
- end
456
- end
457
-
458
- end
459
-
1
+
2
+ require_relative '_base'
3
+ require_relative '_yml_helper'
4
+ require_relative '_path_modifier'
5
+ require_relative 'iar/eww'
6
+ require_relative 'iar/ewp'
7
+ require_relative 'iar/ewd'
8
+
9
+ #replace me when yml_merger becomes gem
10
+ require 'yml_merger'
11
+ require 'nokogiri'
12
+ require 'uri'
13
+ require 'open-uri'
14
+
15
+ module IAR
16
+ class Project
17
+ TOOLCHAIN='iar'
18
+ include Base
19
+ include EWP
20
+ include EWD
21
+ include UNI_Project
22
+
23
+ def initialize(project_data, generator_variable, logger = nil)
24
+ @logger = logger
25
+ unless (logger)
26
+ @logger = Logger.new(STDOUT)
27
+ @logger.level = Logger::WARN
28
+ end
29
+ set_hash(project_data)
30
+ @project_name = get_project_name()
31
+ @board = get_board()
32
+ @paths = PathModifier.new(generator_variable["paths"])
33
+ @iar_project_files = {".ewp" => nil, ".dni" => nil, ".ewd" => nil, ".yml" => nil}
34
+ return nil if get_template(Project::TOOLCHAIN).nil?
35
+ get_template(Project::TOOLCHAIN).each do |template|
36
+ @logger.info template
37
+ ext = File.extname(template)
38
+ if @iar_project_files.keys.include?(ext)
39
+ path = @paths.fullpath("default_path",template)
40
+ #begin
41
+ case ext
42
+ when ".ewp"
43
+ doc = Nokogiri::XML(open(path))
44
+ @iar_project_files[ext] = doc
45
+ when ".ewd"
46
+ doc = Nokogiri::XML(open(path))
47
+ @iar_project_files[ext] = doc
48
+ when ".dni"
49
+ doc = Nokogiri::XML(open(path))
50
+ @iar_project_files[ext] = doc
51
+ end
52
+ #rescue
53
+ # @logger.info "failed to open #{template}"
54
+ #end
55
+ end
56
+ end
57
+ end
58
+
59
+ def generator(filter, project_data)
60
+ return if not is_toolchain_support(Project::TOOLCHAIN)
61
+ create_method( Project::TOOLCHAIN)
62
+ send(Project::TOOLCHAIN.to_sym, project_data)
63
+ save_project()
64
+ end
65
+
66
+ def source()
67
+ #add sources to target
68
+ return if @iar_project_files['.ewp'].nil?
69
+ remove_sources(@iar_project_files['.ewp'])
70
+ sources = get_src_list(Project::TOOLCHAIN)
71
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
72
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
73
+ add_sources(@iar_project_files['.ewp'], sources, @paths, proj_path)
74
+ end
75
+
76
+ def templates()
77
+ #load tempaltes
78
+ end
79
+
80
+ def type()
81
+ #set project type
82
+ end
83
+
84
+ def document()
85
+ project_name = get_project_name()
86
+
87
+ end
88
+
89
+ def targets()
90
+ convert_lut = {
91
+ 'cx_flags' => 'cxx_flags',
92
+ 'cc_define' => 'cc_defines',
93
+ 'cx_define' => 'cxx_defines',
94
+ 'as_define' => 'as_defines',
95
+ 'cp_define' => 'cp_defines',
96
+ 'ar_flags' => 'ar_flags'
97
+ }
98
+ get_targets(Project::TOOLCHAIN).each do |key, value|
99
+ next if value.nil?
100
+ #add target for ewp
101
+ t = new_target(key, @iar_project_files['.ewp'])
102
+ if t.nil?
103
+ @logger.info "missing default debug configuration in template"
104
+ return
105
+ end
106
+ #do the target settings
107
+ value.each_key do |subkey|
108
+ #for backward compatible
109
+ temp_op = subkey.gsub('-', '_')
110
+ if convert_lut.has_key? temp_op
111
+ target_op = convert_lut[temp_op]
112
+ else
113
+ target_op = temp_op
114
+ end
115
+ methods = self.class.instance_methods(false)
116
+ if methods.include?("target_#{target_op}".to_sym)
117
+ send("target_#{target_op}".to_sym, t, value[subkey])
118
+ else
119
+ @logger.info "#{subkey} is not processed try to use the tool-chain specific"
120
+ end
121
+ end
122
+ end
123
+ remove_targets(@iar_project_files['.ewp'], get_target_list(Project::TOOLCHAIN))
124
+ end
125
+
126
+ # tool_chain_specific attribute for each target
127
+ # Params:
128
+ # - target_node: the xml node of given target
129
+ # - doc: the hash that holds the data
130
+ def target_tool_chain_set_spec(target_node, doc)
131
+ set_specific(target_node, doc)
132
+ end
133
+
134
+ def target_tool_chain_add_spec(target_node, doc)
135
+ add_specific(target_node, doc)
136
+ end
137
+
138
+ def save_project()
139
+ path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
140
+ save(@iar_project_files['.ewp'], File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.ewp"))
141
+ end
142
+
143
+ def target_cp_defines(target_node, doc)
144
+ value = doc.values.join(" ")
145
+ settings = {'OGChipSelectEditMenu' => {
146
+ 'state' => doc.keys.join("") + "\t" + value
147
+ }
148
+ }
149
+ set_specific(target_node, settings)
150
+ settings = {'GEndianModeBE' => {
151
+ 'state' => '1'
152
+ }
153
+ }
154
+ set_specific(target_node, settings)
155
+ end
156
+
157
+ def target_as_predefines(target_node, doc)
158
+
159
+ end
160
+
161
+ def target_as_defines(target_node, doc)
162
+ defines_array = Array.new
163
+ doc.each do |item|
164
+ if item.class == Hash
165
+ item.each do |key, value|
166
+ defines_array.insert(-1, "#{key}=#{value}")
167
+ end
168
+ else
169
+ defines_array.insert(-1, item)
170
+ end
171
+ end
172
+ settings = {'ADefines' => {
173
+ 'state' => defines_array
174
+ }
175
+ }
176
+ add_specific(target_node, settings)
177
+ end
178
+
179
+ def target_as_include(target_node, doc)
180
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
181
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
182
+ settings = {'AUserIncludes' => {} }
183
+ inc_array = Array.new
184
+ doc.each do |item|
185
+ if item['rootdir']
186
+ full_path = @paths.fullpath(item['rootdir'],item['path'])
187
+ else
188
+ full_path = @paths.fullpath('default_path',item['path'])
189
+ end
190
+ inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
191
+ end
192
+ settings['AUserIncludes']['state'] = inc_array
193
+ add_specific(target_node, settings)
194
+ end
195
+
196
+ def target_as_flags(target_node, doc)
197
+ flags_array = Array.new
198
+ doc.each do |item|
199
+ if item.class == Hash
200
+ item.each do |key, value|
201
+ flags_array.insert(-1, "#{key}=#{value}")
202
+ end
203
+ else
204
+ flags_array.insert(-1, item)
205
+ end
206
+ end
207
+ settings = {'AExtraOptionsV2' => {
208
+ 'state' => flags_array
209
+ }
210
+ }
211
+ add_specific(target_node, settings)
212
+ end
213
+
214
+ def target_cc_predefines(target_node, doc)
215
+
216
+ end
217
+
218
+ def target_cc_preincludes(target_node, doc)
219
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
220
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
221
+ settings = {'PreInclude' => {} }
222
+ inc_array = Array.new
223
+ doc.each do |item|
224
+ if item['rootdir']
225
+ full_path = @paths.fullpath(item['rootdir'],item['path'])
226
+ else
227
+ full_path = @paths.fullpath('default_path',item['path'])
228
+ end
229
+ inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
230
+ end
231
+ settings['PreInclude']['state'] = inc_array
232
+ add_specific(target_node, settings)
233
+ end
234
+
235
+ def target_cc_defines(target_node, doc)
236
+ defines_array = Array.new
237
+ doc.each do |item, item_value|
238
+ if item_value.nil?
239
+ defines_array.insert(-1, "#{item}")
240
+ else
241
+ defines_array.insert(-1, "#{item}=#{item_value}")
242
+ end
243
+ end
244
+ settings = {'CCDefines' => {
245
+ 'state' => defines_array
246
+ }
247
+ }
248
+ add_specific(target_node, settings)
249
+ end
250
+
251
+ def target_cc_include(target_node, doc)
252
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
253
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
254
+ settings = {'CCIncludePath2' => {} }
255
+ inc_array = Array.new
256
+ doc.each do |item|
257
+ if item['rootdir']
258
+ full_path = @paths.fullpath(item['rootdir'],item['path'])
259
+ else
260
+ full_path = @paths.fullpath('default_path',item['path'])
261
+ end
262
+ inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
263
+ end
264
+ settings['CCIncludePath2']['state'] = inc_array
265
+ add_specific(target_node, settings)
266
+ end
267
+
268
+ def target_cc_flags(target_node, doc)
269
+ settings_check = { 'IExtraOptionsCheck' => {
270
+ 'state' => '1'
271
+ }
272
+ }
273
+ add_specific(target_node, settings_check)
274
+ settings = {'IExtraOptions' => {
275
+ 'state' => doc
276
+ }
277
+ }
278
+ add_specific(target_node, settings)
279
+ end
280
+
281
+ def target_cxx_predefines(target_node, doc)
282
+ target_cc_predefines(target_node, doc)
283
+ end
284
+
285
+ def target_cxx_preincludes(target_node, doc)
286
+ target_cc_preincludes(target_node, doc)
287
+ end
288
+
289
+ def target_cxx_defines(target_node, doc)
290
+ target_cc_defines(target_node, doc)
291
+ end
292
+
293
+ def target_cxx_include(target_node, doc)
294
+ target_cc_include(target_node, doc)
295
+ end
296
+
297
+ def target_cxx_flags(target_node, doc)
298
+ target_cc_flags(target_node, doc)
299
+ end
300
+
301
+ def target_ld_flags(target_node, doc)
302
+ settings = {'IlinkConfigDefines' => {
303
+ 'state' => doc
304
+ }
305
+ }
306
+ add_specific(target_node, settings)
307
+ end
308
+
309
+ def target_libraries(target_node, doc)
310
+ settings = {'IlinkAdditionalLibs' => {
311
+ 'state' => doc
312
+ }
313
+ }
314
+ add_specific(target_node, settings)
315
+ end
316
+
317
+ def target_linker_file(target_node, doc)
318
+ settings_check = { 'IlinkIcfOverride' => {
319
+ 'state' => 1
320
+ }
321
+ }
322
+ add_specific(target_node, settings_check)
323
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
324
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
325
+ settings = {'IlinkIcfFile' => {} }
326
+ inc_array = Array.new
327
+ if doc.has_key?("rootdir")
328
+ full_path = @paths.fullpath(doc['rootdir'],doc['path'])
329
+ else
330
+ full_path = @paths.fullpath('default_path',doc['path'])
331
+ end
332
+ inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
333
+ settings['IlinkIcfFile']['state'] = inc_array.join(" ")
334
+ add_specific(target_node, settings)
335
+ end
336
+
337
+ def target_outdir(target_node, doc)
338
+ =begin
339
+ <option>
340
+ <name>IlinkOutputFile</name>
341
+ <state>K70_pit_drivers_test.out</state>
342
+ </option>
343
+ =end
344
+ settings = { 'IlinkOutputFile' => {
345
+ 'state' => "#{get_project_name()}.out"
346
+ }
347
+ }
348
+ set_specific(target_node, settings)
349
+ end
350
+
351
+ end
352
+
353
+ class Project_set
354
+ include EWW
355
+ include UNI_Project
356
+ TOOLCHAIN='iar'
357
+
358
+ # initialize EWW class
359
+ # PARAMS:
360
+ # - project_data: specific project data format for a application/library
361
+ # - generator_variable: all dependency in hash
362
+ def initialize(project_data, generator_variable, logger = nil)
363
+ @logger = logger
364
+ unless (logger)
365
+ @logger = Logger.new(STDOUT)
366
+ @logger.level = Logger::WARN
367
+ end
368
+ set_hash(project_data)
369
+ @project_name = get_project_name()
370
+ @board = get_board()
371
+ @paths = PathModifier.new(generator_variable["paths"])
372
+ @all_projects_hash = generator_variable["all"]
373
+ @iar_project_files = {".eww" => nil}
374
+ return nil if get_template(Project_set::TOOLCHAIN).nil?
375
+ get_template(Project_set::TOOLCHAIN).each do |template|
376
+ ext = File.extname(template)
377
+ if @iar_project_files.keys.include?(ext)
378
+ path = @paths.fullpath("default_path",template)
379
+ doc = Nokogiri::XML(open(path))
380
+ case ext
381
+ when ".eww"
382
+ @iar_project_files[ext] = doc
383
+ else
384
+ @logger.info "#{ext} not processed"
385
+ end
386
+ end
387
+ end
388
+ #clean the wrkspace in template
389
+ @iar_project_files[".eww"].css("workspace/project").each do |node|
390
+ node.remove
391
+ end
392
+ @iar_project_files[".eww"].css("workspace/batchBuild/batchDefinition").each do |node|
393
+ node.remove
394
+ end
395
+ end
396
+
397
+ def generator()
398
+ return if not is_toolchain_support(Project::TOOLCHAIN)
399
+ add_project_to_set()
400
+ save_set()
401
+ end
402
+
403
+
404
+ def add_project_to_set()
405
+ return if @iar_project_files.nil?
406
+ return if @iar_project_files['.eww'].nil?
407
+ ext = ".eww"
408
+
409
+ #batch build mode is add
410
+ get_target_list(Project_set::TOOLCHAIN).each do |target|
411
+ add_batch_project_target(@iar_project_files[ext], "all", @project_name, target)
412
+ add_batch_project_target(@iar_project_files[ext], target, @project_name, target)
413
+ next if get_libraries(Project_set::TOOLCHAIN).nil?
414
+ get_libraries(Project_set::TOOLCHAIN).each do |lib|
415
+ add_batch_project_target(@iar_project_files[ext], "all", lib, target)
416
+ add_batch_project_target(@iar_project_files[ext], target, lib, target)
417
+ end
418
+ end
419
+ #add projects
420
+ file = "#{@project_name}_#{@board}.ewp"
421
+ path = File.join('$WS_DIR$',file)
422
+ add_project(@iar_project_files[ext], path)
423
+ #add library projects here
424
+ #get from dependency['libraries'][library_name]
425
+ ustruct = @all_projects_hash
426
+ return if get_libraries(Project_set::TOOLCHAIN).nil?
427
+ get_libraries(Project_set::TOOLCHAIN).each do |lib|
428
+ if ustruct[lib].nil?
429
+ @logger.info "#{lib} information is missing in all hash"
430
+ next
431
+ end
432
+ libname = "#{@project_name}.ewp"
433
+ root = @paths.rootdir_table[@ustruct[library][tool_key]['outdir']['root-dir']]
434
+ lib_path = File.join(root, @ustruct[library][tool_key]['outdir']['path'], libname)
435
+ if @ustruct[ project_name ][ tool_key ].has_key?('outdir')
436
+ ewwpath = File.join(@output_rootdir, @ustruct[ project_name ][ tool_key ][ 'outdir' ] )
437
+ else
438
+ ewwpath = @output_rootdir
439
+ end
440
+ path = Pathname.new(lib_path).relative_path_from(Pathname.new(ewwpath))
441
+ #more to come
442
+ end
443
+
444
+ end
445
+
446
+ def save_set()
447
+ path = get_output_dir(Project_set::TOOLCHAIN, @paths.rootdir_table)
448
+ @logger.info @paths.rootdir_table['output_root']
449
+ @logger.info path
450
+ @logger.info "#{@project_name}_#{@board}.eww"
451
+ if path.class == Hash
452
+ save(@iar_project_files['.eww'], File.join(@paths.rootdir_table[path['rootdir']], path['path'], "#{@project_name}_#{@board}.eww"))
453
+ else
454
+ save(@iar_project_files['.eww'], File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.eww"))
455
+ end
456
+ end
457
+
458
+ end
459
+
460
460
  end # end Module IAR