ebngen 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ebngen/adapter/_base.rb +1 -0
- data/lib/ebngen/adapter/_yml_helper.rb +8 -0
- data/lib/ebngen/adapter/iar/ewp.rb +1 -1
- data/lib/ebngen/adapter/mdk.rb +480 -0
- data/lib/ebngen/adapter/mdk/uvmwp.rb +91 -0
- data/lib/ebngen/adapter/mdk/uvprojx.rb +278 -0
- data/lib/ebngen/generate.rb +3 -2
- data/lib/ebngen/translate.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca05259fd29ecf16276a0c7d20b0e7cdfc77e420
|
4
|
+
data.tar.gz: 6eb40d9714cd4afb60aebc293af7ac00513497db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87cab787174215e871041cc02ae5514864b9f442462a0fb9d63785669e72d61a127c36278caf14f68aece6e0c9302cde9eb5a3106fb8d8b071dcf8559eaffaa7
|
7
|
+
data.tar.gz: a5909d15f594d785ac7c5e1f426358cc42e17f71220b70d3d3e39ac9c8c81b9ae96d0f2b9a83f559032070be32ee065822f31b8673c8f0c9a6503f1f8ae89166
|
data/lib/ebngen/adapter/_base.rb
CHANGED
@@ -46,4 +46,12 @@ module UNI_Project
|
|
46
46
|
def get_template(toolchain)
|
47
47
|
return @projects_hash[toolchain]['templates']
|
48
48
|
end
|
49
|
+
|
50
|
+
def get_default_projectset_settings(toolchain)
|
51
|
+
return @projects_hash[toolchain]['projectset_settings']
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_default_project_settings(toolchain)
|
55
|
+
return @projects_hash[toolchain]['project_settings']
|
56
|
+
end
|
49
57
|
end
|
@@ -0,0 +1,480 @@
|
|
1
|
+
|
2
|
+
require_relative '_base'
|
3
|
+
require_relative '_yml_helper'
|
4
|
+
require_relative '_path_modifier'
|
5
|
+
require_relative 'mdk/uvmwp'
|
6
|
+
require_relative 'mdk/uvprojx'
|
7
|
+
|
8
|
+
#replace me when yml_merger becomes gem
|
9
|
+
require 'yml_merger'
|
10
|
+
require 'nokogiri'
|
11
|
+
require 'uri'
|
12
|
+
require 'open-uri'
|
13
|
+
require 'xsd_populator'
|
14
|
+
require 'xsd_reader'
|
15
|
+
|
16
|
+
module MDK
|
17
|
+
class Project
|
18
|
+
TOOLCHAIN='mdk'
|
19
|
+
include Base
|
20
|
+
include UVPROJX
|
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
|
+
@mdk_project_files = {"project_projx"=> nil,".yml" => nil, ".uvprojx" => 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 @mdk_project_files.keys.include?(ext)
|
39
|
+
path = @paths.fullpath("default_path",template)
|
40
|
+
#begin
|
41
|
+
case ext
|
42
|
+
when ".uvprojx"
|
43
|
+
#fn = File.basename(path, ".uvprojx")
|
44
|
+
#if fn == "project_projx"
|
45
|
+
doc = Nokogiri::XML(open(path))
|
46
|
+
#string_xml = XsdPopulator.new(:xsd => path).populated_xml
|
47
|
+
#doc = Nokogiri::XML(string_xml)
|
48
|
+
@mdk_project_files["project_projx"] = doc
|
49
|
+
#init_project(doc, get_default_project_settings(Project_set::TOOLCHAIN))
|
50
|
+
#end
|
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
|
+
=begin
|
69
|
+
return if @mdk_project_files['project_projx'].nil?
|
70
|
+
remove_sources(@mdk_project_files['project_projx'])
|
71
|
+
sources = get_src_list(Project::TOOLCHAIN)
|
72
|
+
o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
|
73
|
+
proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
|
74
|
+
add_sources(@mdk_project_files['project_projx'], sources, @paths, proj_path)
|
75
|
+
=end
|
76
|
+
end
|
77
|
+
|
78
|
+
def templates()
|
79
|
+
#load tempaltes
|
80
|
+
end
|
81
|
+
|
82
|
+
def type()
|
83
|
+
#set project type
|
84
|
+
end
|
85
|
+
|
86
|
+
def document()
|
87
|
+
project_name = get_project_name()
|
88
|
+
end
|
89
|
+
|
90
|
+
def targets()
|
91
|
+
convert_lut = {
|
92
|
+
'cx_flags' => 'cxx_flags',
|
93
|
+
'cc_define' => 'cc_defines',
|
94
|
+
'cx_define' => 'cxx_defines',
|
95
|
+
'as_define' => 'as_defines',
|
96
|
+
'cp_define' => 'cp_defines',
|
97
|
+
'ar_flags' => 'ar_flags'
|
98
|
+
}
|
99
|
+
get_targets(Project::TOOLCHAIN).each do |key, value|
|
100
|
+
next if value.nil?
|
101
|
+
#add target for uvproj
|
102
|
+
t = new_target(key, @mdk_project_files['project_projx'])
|
103
|
+
if t.nil?
|
104
|
+
@logger.info "missing default debug configuration in template"
|
105
|
+
return
|
106
|
+
end
|
107
|
+
#do the target settings
|
108
|
+
value.each_key do |subkey|
|
109
|
+
#for backward compatible
|
110
|
+
temp_op = subkey.gsub('-', '_')
|
111
|
+
if convert_lut.has_key? temp_op
|
112
|
+
target_op = convert_lut[temp_op]
|
113
|
+
else
|
114
|
+
target_op = temp_op
|
115
|
+
end
|
116
|
+
methods = self.class.instance_methods(false)
|
117
|
+
if methods.include?("target_#{target_op}".to_sym)
|
118
|
+
send("target_#{target_op}".to_sym, t, value[subkey])
|
119
|
+
else
|
120
|
+
@logger.info "#{subkey} is not processed try to use the tool-chain specific"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
#for mdk sources are added pre-target
|
124
|
+
remove_sources(t)
|
125
|
+
sources = get_src_list(Project::TOOLCHAIN)
|
126
|
+
o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
|
127
|
+
proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
|
128
|
+
add_sources(t.at_xpath("Groups"), sources, @paths, proj_path)
|
129
|
+
end
|
130
|
+
remove_targets(@mdk_project_files['project_projx'], get_target_list(Project::TOOLCHAIN))
|
131
|
+
end
|
132
|
+
|
133
|
+
# tool_chain_specific attribute for each target
|
134
|
+
# Params:
|
135
|
+
# - target_node: the xml node of given target
|
136
|
+
# - doc: the hash that holds the data
|
137
|
+
def target_tool_chain_set_spec(target_node, doc)
|
138
|
+
set_specific(target_node, doc)
|
139
|
+
end
|
140
|
+
|
141
|
+
def target_tool_chain_add_spec(target_node, doc)
|
142
|
+
add_specific(target_node, doc)
|
143
|
+
end
|
144
|
+
|
145
|
+
def save_project()
|
146
|
+
path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
|
147
|
+
@logger.info "save as #{File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.uvprojx")}"
|
148
|
+
save(@mdk_project_files['project_projx'], File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.uvprojx"))
|
149
|
+
end
|
150
|
+
|
151
|
+
def target_cp_defines(target_node, doc)
|
152
|
+
cpdefines = []
|
153
|
+
doc.each do |key, value|
|
154
|
+
cpdefines.insert(-1, "#{key}=#{value}")
|
155
|
+
end
|
156
|
+
settings = {'Cads' =>
|
157
|
+
{ 'VariousControls' =>
|
158
|
+
{
|
159
|
+
'Define' => cpdefines
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
set_specific(target_node, settings)
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
def target_as_predefines(target_node, doc)
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
def target_as_defines(target_node, doc)
|
172
|
+
asdefines = []
|
173
|
+
doc.each do |key, value|
|
174
|
+
asdefines.insert(-1, "#{key}=#{value}")
|
175
|
+
end
|
176
|
+
settings = {'Aads' =>
|
177
|
+
{ 'VariousControls' =>
|
178
|
+
{
|
179
|
+
'Define' => asdefines
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
set_specific(target_node, settings)
|
184
|
+
end
|
185
|
+
|
186
|
+
def target_as_include(target_node, doc)
|
187
|
+
o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
|
188
|
+
proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
|
189
|
+
|
190
|
+
inc_array = Array.new
|
191
|
+
doc.each do |item|
|
192
|
+
if item['rootdir']
|
193
|
+
full_path = @paths.fullpath(item['rootdir'],item['path'])
|
194
|
+
else
|
195
|
+
full_path = @paths.fullpath('default_path',item['path'])
|
196
|
+
end
|
197
|
+
inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
|
198
|
+
end
|
199
|
+
settings = {'Aads' =>
|
200
|
+
{ 'VariousControls' =>
|
201
|
+
{
|
202
|
+
'IncludePath' => inc_array
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
add_specific(target_node, settings)
|
207
|
+
end
|
208
|
+
|
209
|
+
def target_as_flags(target_node, doc)
|
210
|
+
flags_array = Array.new
|
211
|
+
doc.each do |item|
|
212
|
+
if item.class == Hash
|
213
|
+
item.each do |key, value|
|
214
|
+
flags_array.insert(-1, "#{key}=#{value}")
|
215
|
+
end
|
216
|
+
else
|
217
|
+
flags_array.insert(-1, item)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
settings = {'Aads' =>
|
221
|
+
{ 'VariousControls' =>
|
222
|
+
{
|
223
|
+
'MiscControls' => flags_array
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
add_specific(target_node, settings)
|
228
|
+
end
|
229
|
+
|
230
|
+
def target_cc_predefines(target_node, doc)
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
def target_cc_preincludes(target_node, doc)
|
235
|
+
end
|
236
|
+
|
237
|
+
def target_cc_defines(target_node, doc)
|
238
|
+
defines_array = Array.new
|
239
|
+
doc.each do |item, item_value|
|
240
|
+
if item_value.nil?
|
241
|
+
defines_array.insert(-1, "#{item}")
|
242
|
+
else
|
243
|
+
defines_array.insert(-1, "#{item}=#{item_value}")
|
244
|
+
end
|
245
|
+
end
|
246
|
+
settings = {'Cads' =>
|
247
|
+
{ 'VariousControls' =>
|
248
|
+
{
|
249
|
+
'Define' => defines_array
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
add_specific(target_node, settings)
|
254
|
+
end
|
255
|
+
|
256
|
+
def target_cc_include(target_node, doc)
|
257
|
+
o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
|
258
|
+
proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
|
259
|
+
inc_array = Array.new
|
260
|
+
doc.each do |item|
|
261
|
+
if item['rootdir']
|
262
|
+
full_path = @paths.fullpath(item['rootdir'],item['path'])
|
263
|
+
else
|
264
|
+
full_path = @paths.fullpath('default_path',item['path'])
|
265
|
+
end
|
266
|
+
inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
|
267
|
+
end
|
268
|
+
settings = {'Cads' =>
|
269
|
+
{ 'VariousControls' =>
|
270
|
+
{
|
271
|
+
'IncludePath' => inc_array
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
add_specific(target_node, settings)
|
276
|
+
end
|
277
|
+
|
278
|
+
def target_cc_flags(target_node, doc)
|
279
|
+
flags_array = Array.new
|
280
|
+
doc.each do |item|
|
281
|
+
if item.class == Hash
|
282
|
+
item.each do |key, value|
|
283
|
+
flags_array.insert(-1, "#{key}=#{value}")
|
284
|
+
end
|
285
|
+
else
|
286
|
+
flags_array.insert(-1, item)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
settings = {'Cads' =>
|
290
|
+
{ 'VariousControls' =>
|
291
|
+
{
|
292
|
+
'MiscControls' => flags_array
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
add_specific(target_node, settings)
|
297
|
+
end
|
298
|
+
|
299
|
+
def target_cxx_predefines(target_node, doc)
|
300
|
+
target_cc_predefines(target_node, doc)
|
301
|
+
end
|
302
|
+
|
303
|
+
def target_cxx_preincludes(target_node, doc)
|
304
|
+
target_cc_preincludes(target_node, doc)
|
305
|
+
end
|
306
|
+
|
307
|
+
def target_cxx_defines(target_node, doc)
|
308
|
+
target_cc_defines(target_node, doc)
|
309
|
+
end
|
310
|
+
|
311
|
+
def target_cxx_include(target_node, doc)
|
312
|
+
target_cc_include(target_node, doc)
|
313
|
+
end
|
314
|
+
|
315
|
+
def target_cxx_flags(target_node, doc)
|
316
|
+
target_cc_flags(target_node, doc)
|
317
|
+
end
|
318
|
+
|
319
|
+
def target_ld_flags(target_node, doc)
|
320
|
+
flags_array = Array.new
|
321
|
+
doc.each do |item|
|
322
|
+
if item.class == Hash
|
323
|
+
item.each do |key, value|
|
324
|
+
flags_array.insert(-1, "#{key}=#{value}")
|
325
|
+
end
|
326
|
+
else
|
327
|
+
flags_array.insert(-1, item)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
settings = {'LDads' =>
|
331
|
+
{ 'Misc' => flags_array }
|
332
|
+
}
|
333
|
+
add_specific(target_node, settings)
|
334
|
+
end
|
335
|
+
|
336
|
+
def target_libraries(target_node, doc)
|
337
|
+
flags_array = Array.new
|
338
|
+
doc.each do |item|
|
339
|
+
if item.class == Hash
|
340
|
+
item.each do |key, value|
|
341
|
+
flags_array.insert(-1, "#{key}=#{value}")
|
342
|
+
end
|
343
|
+
else
|
344
|
+
flags_array.insert(-1, item)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
settings = {'LDads' =>
|
348
|
+
{ 'Misc' => flags_array }
|
349
|
+
}
|
350
|
+
add_specific(target_node, settings)
|
351
|
+
end
|
352
|
+
|
353
|
+
def target_linker_file(target_node, doc)
|
354
|
+
o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
|
355
|
+
proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
|
356
|
+
inc_array = Array.new
|
357
|
+
if doc.has_key?("rootdir")
|
358
|
+
full_path = @paths.fullpath(doc['rootdir'],doc['path'])
|
359
|
+
else
|
360
|
+
full_path = @paths.fullpath('default_path',doc['path'])
|
361
|
+
end
|
362
|
+
inc_array.insert(-1, File.join("$PROJ_DIR$", @paths.relpath(proj_path, full_path)))
|
363
|
+
settings = {'LDads' =>
|
364
|
+
{ 'ScatterFile' => inc_array.join(" ") }
|
365
|
+
}
|
366
|
+
add_specific(target_node, settings)
|
367
|
+
end
|
368
|
+
|
369
|
+
def target_outdir(target_node, doc)
|
370
|
+
=begin
|
371
|
+
<option>
|
372
|
+
<name>IlinkOutputFile</name>
|
373
|
+
<state>K70_pit_drivers_test.out</state>
|
374
|
+
</option>
|
375
|
+
=end
|
376
|
+
settings = { 'OutputDirectory' => "#{get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)}"}
|
377
|
+
set_specific(target_node, settings)
|
378
|
+
settings = { 'OutputName' => "#{get_project_name()}"}
|
379
|
+
set_specific(target_node, settings)
|
380
|
+
end
|
381
|
+
|
382
|
+
end
|
383
|
+
|
384
|
+
class Project_set
|
385
|
+
include UVMWP
|
386
|
+
include UNI_Project
|
387
|
+
TOOLCHAIN='mdk'
|
388
|
+
|
389
|
+
# initialize EWW class
|
390
|
+
# PARAMS:
|
391
|
+
# - project_data: specific project data format for a application/library
|
392
|
+
# - generator_variable: all dependency in hash
|
393
|
+
def initialize(project_data, generator_variable, logger = nil)
|
394
|
+
@logger = logger
|
395
|
+
unless (logger)
|
396
|
+
@logger = Logger.new(STDOUT)
|
397
|
+
@logger.level = Logger::WARN
|
398
|
+
end
|
399
|
+
set_hash(project_data)
|
400
|
+
@project_name = get_project_name()
|
401
|
+
@board = get_board()
|
402
|
+
@paths = PathModifier.new(generator_variable["paths"])
|
403
|
+
@all_projects_hash = generator_variable["all"]
|
404
|
+
@mdk_project_files = {"project_mpw" => nil,".xsd" => nil}
|
405
|
+
return nil if get_template(Project_set::TOOLCHAIN).nil?
|
406
|
+
get_template(Project_set::TOOLCHAIN).each do |template|
|
407
|
+
ext = File.extname(template)
|
408
|
+
if @mdk_project_files.keys.include?(ext)
|
409
|
+
path = @paths.fullpath("default_path",template)
|
410
|
+
case ext
|
411
|
+
when ".xsd"
|
412
|
+
fn = File.basename(path, ".xsd")
|
413
|
+
@logger.info "#{fn} processing"
|
414
|
+
if fn == "project_mpw"
|
415
|
+
#doc = Nokogiri::XML(open(path))
|
416
|
+
string_xml = XsdPopulator.new(:xsd => path).populated_xml
|
417
|
+
doc = Nokogiri::XML(string_xml)
|
418
|
+
@mdk_project_files['project_mpw'] = doc
|
419
|
+
init_project_set(doc, get_default_projectset_settings(Project_set::TOOLCHAIN))
|
420
|
+
end
|
421
|
+
else
|
422
|
+
@logger.info "#{ext} not processed"
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
def generator()
|
429
|
+
return if not is_toolchain_support(Project::TOOLCHAIN)
|
430
|
+
add_project_to_set()
|
431
|
+
save_set()
|
432
|
+
end
|
433
|
+
|
434
|
+
|
435
|
+
def add_project_to_set()
|
436
|
+
return if @mdk_project_files.nil?
|
437
|
+
return if @mdk_project_files['project_mpw'].nil?
|
438
|
+
ext = "project_mpw"
|
439
|
+
#add projects
|
440
|
+
file = "#{@project_name}_#{@board}.uvprojx"
|
441
|
+
add_project(@mdk_project_files[ext], file)
|
442
|
+
#add library projects here
|
443
|
+
#get from dependency['libraries'][library_name]
|
444
|
+
ustruct = @all_projects_hash
|
445
|
+
return if get_libraries(Project_set::TOOLCHAIN).nil?
|
446
|
+
get_libraries(Project_set::TOOLCHAIN).each do |lib|
|
447
|
+
if ustruct[lib].nil?
|
448
|
+
@logger.info "#{lib} information is missing in all hash"
|
449
|
+
next
|
450
|
+
end
|
451
|
+
libname = "#{@project_name}"
|
452
|
+
root = @paths.rootdir_table[@ustruct[library][tool_key]['outdir']['root-dir']]
|
453
|
+
lib_path = File.join(root, @ustruct[library][tool_key]['outdir']['path'], libname)
|
454
|
+
if @ustruct[ project_name ][ tool_key ].has_key?('outdir')
|
455
|
+
wspath = File.join(@output_rootdir, @ustruct[ project_name ][ tool_key ][ 'outdir' ] )
|
456
|
+
else
|
457
|
+
wspath = @output_rootdir
|
458
|
+
end
|
459
|
+
path = Pathname.new(lib_path).relative_path_from(Pathname.new(wspath))
|
460
|
+
|
461
|
+
add_project(@mdk_project_files[ext], path)
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|
465
|
+
|
466
|
+
def save_set()
|
467
|
+
path = get_output_dir(Project_set::TOOLCHAIN, @paths.rootdir_table)
|
468
|
+
@logger.info @paths.rootdir_table['output_root']
|
469
|
+
@logger.info path
|
470
|
+
@logger.info "#{@project_name}_#{@board}"
|
471
|
+
if path.class == Hash
|
472
|
+
save(@mdk_project_files['project_mpw'], File.join(@paths.rootdir_table[path['rootdir']], path['path'], "#{@project_name}_#{@board}.uvmpw"))
|
473
|
+
else
|
474
|
+
save(@mdk_project_files['project_mpw'], File.join(@paths.rootdir_table['output_root'], path, "#{@project_name}_#{@board}.uvmpw"))
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
end
|
479
|
+
|
480
|
+
end # end Module MDK
|
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
|
5
|
+
module UVMWP
|
6
|
+
@@data_provider = {
|
7
|
+
"SchemaVersion" => "2.1",
|
8
|
+
"Header" => "### uVision Project, (C) Keil Software",
|
9
|
+
"WorkspaceName" => "WorkSpace"
|
10
|
+
}
|
11
|
+
@@data_remove = ["Sle7"]
|
12
|
+
def add_node(pnode, hash_data, use_old: false)
|
13
|
+
hash_data.each do |key,value|
|
14
|
+
if use_old
|
15
|
+
sv = pnode.at_xpath(key)
|
16
|
+
end
|
17
|
+
unless (sv)
|
18
|
+
sv = Nokogiri::XML::Node.new(key, xml)
|
19
|
+
pnode << sv
|
20
|
+
end
|
21
|
+
if value.class == Hash
|
22
|
+
add_node(sv, value, use_old)
|
23
|
+
elsif value.class == Array
|
24
|
+
value.each do |va|
|
25
|
+
nsv = Nokogiri::XML::Node.new(key, xml)
|
26
|
+
sv << nsv
|
27
|
+
nsv.content = va
|
28
|
+
end
|
29
|
+
else
|
30
|
+
sv.content = value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def travesernode(node)
|
36
|
+
if node.children
|
37
|
+
tname = node.name
|
38
|
+
if @@data_provider.has_key?(tname)
|
39
|
+
node.content = @@data_provider[tname]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
node.children.each do |subnode|
|
43
|
+
next if subnode.nil?
|
44
|
+
travesernode(subnode)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def init_project_set(xml, settings)
|
48
|
+
workspace_node = xml.at_xpath("ProjectWorkspace")
|
49
|
+
travesernode(workspace_node)
|
50
|
+
workspace_node.set_attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
|
51
|
+
workspace_node.set_attribute("xsi:noNamespaceSchemaLocation","project_mpw.xsd")
|
52
|
+
dummy_project = workspace_node.at_xpath("/ProjectWorkspace/project")
|
53
|
+
dummy_project.set_attribute("template","1")
|
54
|
+
@@data_remove.each do |node|
|
55
|
+
nt = workspace_node.at_xpath(node)
|
56
|
+
nt.remove if ! nt.nil?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def add_project(xml , project_path)
|
62
|
+
# find <ProjectWorkspace>
|
63
|
+
workspace_node = xml.at_xpath("/ProjectWorkspace")
|
64
|
+
Core.assert(workspace_node, "no <workspace> present")
|
65
|
+
templat_project = workspace_node.at_xpath("project[@template='1']")
|
66
|
+
new_project = templat_project.dup
|
67
|
+
# add <PathAndName>
|
68
|
+
path_node = new_project.at_xpath("PathAndName")
|
69
|
+
path_node.content = project_path
|
70
|
+
workspace_node << new_project
|
71
|
+
new_project.at_xpath("NodeIsActive").content = 0
|
72
|
+
new_project.at_xpath("NodeIsExpanded").content = 0
|
73
|
+
new_project.remove_attribute("template")
|
74
|
+
# add project into existing lists
|
75
|
+
#@projects[ project_path ] = project_node
|
76
|
+
end
|
77
|
+
|
78
|
+
def save(xml, path)
|
79
|
+
Core.assert(path.is_a?(String)) do
|
80
|
+
"param is not a string #{path.class.name}"
|
81
|
+
end
|
82
|
+
workspace_node = xml.at_xpath("/ProjectWorkspace")
|
83
|
+
Core.assert(workspace_node, "no <workspace> present")
|
84
|
+
#remove old project
|
85
|
+
templat_project = workspace_node.at_xpath("project[@template='1']")
|
86
|
+
templat_project.remove if ! templat_project.nil?
|
87
|
+
FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
|
88
|
+
File.write(path, xml.to_xml)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
class Hash
|
5
|
+
def to_xml(doc)
|
6
|
+
return if doc.nil?
|
7
|
+
self.each do |key, value|
|
8
|
+
mynode = Nokogiri::XML::Node.new key, doc
|
9
|
+
doc.add_child mynode
|
10
|
+
value.to_xml(mynode) if value.class == Hash
|
11
|
+
mynode.content = value if value.class == String or value.class == Fixnum
|
12
|
+
end
|
13
|
+
return doc
|
14
|
+
end #end to_xml
|
15
|
+
def to_xml!(doc)
|
16
|
+
return if doc.nil?
|
17
|
+
self.each do |key, value|
|
18
|
+
if doc.css("/#{key}").count == 0
|
19
|
+
mynode = Nokogiri::XML::Node.new key, doc
|
20
|
+
else
|
21
|
+
mynode = doc.css("/#{key}")[0]
|
22
|
+
end
|
23
|
+
doc.add_child mynode
|
24
|
+
value.to_xml(mynode) if value.class == Hash
|
25
|
+
mynode.content = value if value.class == String or value.class == Fixnum
|
26
|
+
end
|
27
|
+
return doc
|
28
|
+
end #end to_xml!
|
29
|
+
end #end Hash
|
30
|
+
|
31
|
+
module UVPROJX
|
32
|
+
def travesernode(node)
|
33
|
+
if node.children
|
34
|
+
content = node.content
|
35
|
+
if @@data_provider.has_key?(content.strip)
|
36
|
+
node.content = @@data_provider[content.strip]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
node.children.each do |subnode|
|
40
|
+
next if subnode.nil?
|
41
|
+
travesernode(subnode)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
def init_project(xml, settings)
|
46
|
+
project_node = xml.at_xpath("Project")
|
47
|
+
travesernode(project_node)
|
48
|
+
#puts workspace_node
|
49
|
+
#puts xml
|
50
|
+
#mdkProvider.take(:title) # => 'The Monkey Wrench Gang'
|
51
|
+
#mdkProvider.take(:author) # => 'Edward Abbey'
|
52
|
+
#mdkProvider.take(:display_title) # => 'Edward Abbey - The Monkey Wrench Gang'
|
53
|
+
#mdkProvider.take(:price) # => 9.99
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_node(doc, xpath)
|
57
|
+
return doc.xpath(xpath)
|
58
|
+
end
|
59
|
+
|
60
|
+
def new_target(target, doc, name = 'debug')
|
61
|
+
nset = load_node(doc, "//Targets/Target")
|
62
|
+
#use existing one
|
63
|
+
nset.each do |element|
|
64
|
+
if element.css("TargetName").text.downcase == target.downcase
|
65
|
+
puts "find existing #{element.css("/TargetName").text.downcase}"
|
66
|
+
return element
|
67
|
+
end
|
68
|
+
end
|
69
|
+
#create new one
|
70
|
+
nset.each do |element|
|
71
|
+
#use the first available configuration
|
72
|
+
@logger.info "add target #{target}"
|
73
|
+
t = element.dup
|
74
|
+
t.at_css("TargetName").content = target
|
75
|
+
#doc.xpath("/project") << t
|
76
|
+
element.add_previous_sibling(t)
|
77
|
+
return t
|
78
|
+
end
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
|
82
|
+
# remove_targets remove unused targets
|
83
|
+
# Params:
|
84
|
+
# - doc: the xml node project file
|
85
|
+
# - targets_in: used target array (will keep)
|
86
|
+
def remove_targets(doc, targets_in)
|
87
|
+
#remove the target that not in the targets_in
|
88
|
+
nset = load_node(doc, "//Targets/Target")
|
89
|
+
targets_in.collect{|x| x.downcase}
|
90
|
+
nset.each do |element|
|
91
|
+
target = element.xpath("TargetName").text.downcase
|
92
|
+
if !targets_in.include?(target)
|
93
|
+
element.remove
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# remove_sources remove source files
|
99
|
+
# Params:
|
100
|
+
# - doc: the xml node project file
|
101
|
+
def remove_sources(doc)
|
102
|
+
groups = load_node(doc, "//Group")
|
103
|
+
groups.each do |ele|
|
104
|
+
ele.remove
|
105
|
+
end
|
106
|
+
files = load_node(doc, "//File")
|
107
|
+
files.each do |ele|
|
108
|
+
ele.remove
|
109
|
+
end
|
110
|
+
end
|
111
|
+
# remove_sources remove unused node
|
112
|
+
# Params:
|
113
|
+
# - doc: the xml node project file
|
114
|
+
# - xpath: xpath to the node
|
115
|
+
# - **names: node attribute that need to remove defined in hash
|
116
|
+
def remove_unused(doc, xpath, **names)
|
117
|
+
nset = load_node(doc, xpath)
|
118
|
+
nset.each do |element|
|
119
|
+
names.each do |key, value|
|
120
|
+
if element.xpath(key).text.downcase == value.downcase
|
121
|
+
element.remove
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# create_node convert hash to xml and add to doc
|
128
|
+
# Params:
|
129
|
+
# - doc: the xml node project file
|
130
|
+
# - hash_value: hash that defines the nodes structure
|
131
|
+
def create_node(doc, hash_value)
|
132
|
+
hash_value.to_xml!(doc)
|
133
|
+
end
|
134
|
+
|
135
|
+
# append_node convert hash to xml and append to doc
|
136
|
+
# Params:
|
137
|
+
# - doc: the xml node project file
|
138
|
+
# - hash_value: hash that defines the nodes structure
|
139
|
+
def append_node(doc, hash_value)
|
140
|
+
hash_value.to_xml(doc)
|
141
|
+
end
|
142
|
+
|
143
|
+
# add_specific
|
144
|
+
# Params:
|
145
|
+
# - doc: hash to add to target
|
146
|
+
# - target_node: node to be added to
|
147
|
+
# - note:
|
148
|
+
# can not add none exist node for mdk xml
|
149
|
+
def add_specific(target_node, doc)
|
150
|
+
doc.each do |key, value|
|
151
|
+
options = target_node.xpath(key)
|
152
|
+
options.each do |option|
|
153
|
+
if value.class == Hash
|
154
|
+
value.each do |subnode|
|
155
|
+
add_specific(option, subnode)
|
156
|
+
end
|
157
|
+
elsif value.class == String
|
158
|
+
option.content += ";#{value}"
|
159
|
+
elsif value.class == Array
|
160
|
+
value.each do |line|
|
161
|
+
option.content += ";#{line}"
|
162
|
+
end
|
163
|
+
else
|
164
|
+
puts "not support by set_specific #{value}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
# set_specific
|
170
|
+
# Params:
|
171
|
+
# - doc: hash to add to target
|
172
|
+
# - target_node: node to be added to
|
173
|
+
# - note:
|
174
|
+
# can not add none exist node for mdk xml
|
175
|
+
def set_specific(target_node, doc)
|
176
|
+
doc.each do |key, value|
|
177
|
+
options = target_node.xpath(key)
|
178
|
+
options.each do |option|
|
179
|
+
if value.class == Hash
|
180
|
+
value.each do |subnode|
|
181
|
+
add_specific(option, subnode)
|
182
|
+
end
|
183
|
+
elsif value.class == String
|
184
|
+
option.content = value
|
185
|
+
break
|
186
|
+
elsif value.class == Array
|
187
|
+
option.content = ""
|
188
|
+
value.each do |line|
|
189
|
+
option.content += ";#{line}"
|
190
|
+
end
|
191
|
+
break
|
192
|
+
else
|
193
|
+
puts "not support by set_specific #{value}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def save(xml, path)
|
200
|
+
Core.assert(path.is_a?(String)) do
|
201
|
+
"param is not a string #{path.class.name}"
|
202
|
+
end
|
203
|
+
FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
|
204
|
+
File.write(path, xml.to_xml)
|
205
|
+
end
|
206
|
+
|
207
|
+
def add_sources(doc, source_hash, path_mod, proj_path)
|
208
|
+
groups_existing = Array.new
|
209
|
+
files_hash = Hash.new
|
210
|
+
source_hash.each do |src|
|
211
|
+
rootdir = src['rootdir']
|
212
|
+
virtual_dir = src['virtual_dir'] if src.has_key? 'virtual_dir'
|
213
|
+
virtual_dir = src['virtual-dir'] if src.has_key? 'virtual-dir'
|
214
|
+
if src.has_key?('path')
|
215
|
+
path = src['path']
|
216
|
+
else
|
217
|
+
path = src['source']
|
218
|
+
end
|
219
|
+
if virtual_dir
|
220
|
+
if ! groups_existing.include?(virtual_dir)
|
221
|
+
groups_existing.insert(-1, virtual_dir)
|
222
|
+
node = Nokogiri::XML::Node.new 'Group', doc
|
223
|
+
node << "<GroupName>#{virtual_dir}</GroupName>"
|
224
|
+
doc << node
|
225
|
+
end
|
226
|
+
files_hash[virtual_dir] = Array.new if files_hash[virtual_dir].nil?
|
227
|
+
files_hash[virtual_dir].insert(-1, {'path' => path, 'rootdir' => rootdir})
|
228
|
+
else
|
229
|
+
#create a common src group
|
230
|
+
if ! groups_existing.include?("_src")
|
231
|
+
groups_existing.insert(-1, "_src")
|
232
|
+
node = Nokogiri::XML::Node.new 'Group', doc
|
233
|
+
node << "<GroupName>_src</GroupName>"
|
234
|
+
doc << node
|
235
|
+
end
|
236
|
+
files_hash["_src"] = Array.new if files_hash["_src"].nil?
|
237
|
+
files_hash["_src"].insert(-1, {'path' => path, 'rootdir' => rootdir})
|
238
|
+
end
|
239
|
+
end #end source_hash
|
240
|
+
doc.css("Group").each do |node|
|
241
|
+
files_hash[node.at_css("GroupName").text].each do |file|
|
242
|
+
gfiles = Nokogiri::XML::Node.new('Files', node)
|
243
|
+
gfile = Nokogiri::XML::Node.new('File', gfiles)
|
244
|
+
sfile = Nokogiri::XML::Node.new('FileName', gfiles)
|
245
|
+
spfile = Nokogiri::XML::Node.new('FilePath', gfiles)
|
246
|
+
if file['rootdir']
|
247
|
+
full_path = path_mod.fullpath(file['rootdir'],file['path'])
|
248
|
+
else
|
249
|
+
full_path = path_mod.fullpath('default_path',file['path'])
|
250
|
+
end
|
251
|
+
sfile.content = File.basename(file['path'])
|
252
|
+
spfile.content = File.join("$PROJ_DIR$", path_mod.relpath(proj_path, full_path))
|
253
|
+
gfile << sfile
|
254
|
+
gfile << spfile
|
255
|
+
gfiles << gfile
|
256
|
+
node << gfiles
|
257
|
+
end
|
258
|
+
end
|
259
|
+
return if files_hash["_src"].nil?
|
260
|
+
files_hash["_src"].each do |file|
|
261
|
+
gfiles = Nokogiri::XML::Node.new('File', doc)
|
262
|
+
gfile = Nokogiri::XML::Node.new('File', gfiles)
|
263
|
+
sfile = Nokogiri::XML::Node.new('FileName', gfiles)
|
264
|
+
spfile = Nokogiri::XML::Node.new('FilePath', gfiles)
|
265
|
+
if file['rootdir']
|
266
|
+
full_path = path_mod.fullpath(file['rootdir'],file['path'])
|
267
|
+
else
|
268
|
+
full_path = path_mod.fullpath('default_path',file['path'])
|
269
|
+
end
|
270
|
+
spfile.content = File.join("$PROJ_DIR$", path_mod.relpath(proj_path, full_path))
|
271
|
+
sfile.content = File.basename(file['path'])
|
272
|
+
gfile << sfile
|
273
|
+
gfile << spfile
|
274
|
+
gfiles << gfile
|
275
|
+
node << gfiles
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
data/lib/ebngen/generate.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
require_relative 'adapter/iar'
|
3
3
|
require_relative 'adapter/cmake'
|
4
|
+
require_relative 'adapter/mdk'
|
4
5
|
require 'logger'
|
5
6
|
|
6
7
|
class Generator
|
@@ -28,7 +29,7 @@ class Generator
|
|
28
29
|
when 'iar'
|
29
30
|
IAR::Project.new(project_data, @generator_variable, @logger).generator(filter, project_data)
|
30
31
|
when 'mdk'
|
31
|
-
@logger.
|
32
|
+
MDK::Project.new(project_data, @generator_variable, @logger).generator(filter, project_data)
|
32
33
|
when 'cmake'
|
33
34
|
CMAKE::Project.new(project_data, @generator_variable, @logger).generator(filter, project_data)
|
34
35
|
end
|
@@ -39,7 +40,7 @@ class Generator
|
|
39
40
|
when 'iar'
|
40
41
|
IAR::Project_set.new(project_data, @generator_variable, @logger).generator()
|
41
42
|
when 'mdk'
|
42
|
-
@logger.
|
43
|
+
MDK::Project_set.new(project_data, @generator_variable, @logger).generator()
|
43
44
|
when 'cmake'
|
44
45
|
@logger.info "cmake TBD"
|
45
46
|
end
|
data/lib/ebngen/translate.rb
CHANGED
@@ -235,7 +235,7 @@ class Translator
|
|
235
235
|
@data_out[proj]['type'] = @data_in[proj]['section-type']
|
236
236
|
end
|
237
237
|
convert_rules(proj,'iar')
|
238
|
-
|
238
|
+
convert_rules(proj,'mdk')
|
239
239
|
convert_rules(proj,'cmake')
|
240
240
|
#convert_rules(proj,'armgcc')
|
241
241
|
#convert_rules(proj,'kds')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebngen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hake Huang
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: embedded project generator
|
15
15
|
email: hakehuang@gmail.com
|
@@ -29,6 +29,9 @@ files:
|
|
29
29
|
- lib/ebngen/adapter/iar/ewd.rb
|
30
30
|
- lib/ebngen/adapter/iar/ewp.rb
|
31
31
|
- lib/ebngen/adapter/iar/eww.rb
|
32
|
+
- lib/ebngen/adapter/mdk.rb
|
33
|
+
- lib/ebngen/adapter/mdk/uvmwp.rb
|
34
|
+
- lib/ebngen/adapter/mdk/uvprojx.rb
|
32
35
|
- lib/ebngen/assembly.rb
|
33
36
|
- lib/ebngen/ebngen.rb
|
34
37
|
- lib/ebngen/generate.rb
|