ebngen 1.0.0 → 1.0.1

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.
@@ -0,0 +1,291 @@
1
+
2
+ require_relative '_base'
3
+ require_relative '_yml_helper'
4
+ require_relative '_path_modifier'
5
+ require_relative 'cmake/txt'
6
+
7
+
8
+ #replace me when yml_merger becomes gem
9
+ require 'yml_merger'
10
+ require 'nokogiri'
11
+ require 'uri'
12
+ require 'open-uri'
13
+
14
+ module CMAKE
15
+ class Project
16
+ TOOLCHAIN='cmake'
17
+ include Base
18
+ include TXT
19
+ include UNI_Project
20
+
21
+ def initialize(project_data, generator_variable)
22
+ set_hash(project_data)
23
+ @project_name = get_project_name()
24
+ @board = get_board()
25
+ @paths = PathModifier.new(generator_variable["paths"])
26
+ @cmake_project_files = {".txt" => nil, ".bat" => nil, ".sh" => nil}
27
+ @project = Hash.new if @project.nil?
28
+ @project["document"] = {"project_name" => @project_name, "board" => @board }
29
+ end
30
+
31
+ def generator(filter, project_data)
32
+ create_method(Project::TOOLCHAIN)
33
+ send(Project::TOOLCHAIN.to_sym, project_data)
34
+ save_project()
35
+ end
36
+
37
+ def source()
38
+ #add sources to target
39
+ sources = get_src_list(Project::TOOLCHAIN)
40
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
41
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
42
+ @project['sources'] = Array.new
43
+ sources.each do |src|
44
+ if src['rootdir']
45
+ full_path = @paths.fullpath(src['rootdir'],src['path'])
46
+ else
47
+ full_path = @paths.fullpath('default_path',src['path'])
48
+ end
49
+ ipath = File.join("$ProjDirPath$", @paths.relpath(proj_path, full_path))
50
+ @project['sources'].insert(-1, ipath)
51
+ end
52
+
53
+ end
54
+
55
+ def templates()
56
+ #load tempaltes
57
+ end
58
+
59
+ def type()
60
+ @project['type'] = get_type(Project::TOOLCHAIN)
61
+ end
62
+
63
+ def outdir()
64
+ puts "#{get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)}"
65
+ end
66
+
67
+ def targets()
68
+ get_targets(Project::TOOLCHAIN).each do |key, value|
69
+ return if value.nil?
70
+ @project["target"] = Hash.new if @project["target"].nil?
71
+ ta = key.upcase
72
+ @project["target"][ta] = Hash.new if @project["target"][ta].nil?
73
+ #do the target settings
74
+ value.each_key do |subkey|
75
+ methods = self.class.instance_methods(false)
76
+ if methods.include?("target_#{subkey}".to_sym)
77
+ send("target_#{subkey}".to_sym, key, value[subkey])
78
+ else
79
+ puts "#{key} is not processed"
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ # tool_chain_specific attribute for each target
86
+ # Params:
87
+ # - target: the name for the target
88
+ # - doc: the hash that holds the data
89
+ def target_tool_chain_specific(target, doc)
90
+ #no specific for cmake
91
+ end
92
+
93
+ def save_project()
94
+ path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
95
+ save(File.join(@paths.rootdir_table['output_root'], path, "CMakeLists.txt"), @project)
96
+ end
97
+
98
+ def target_cp_defines(target, doc)
99
+ ta = target.upcase
100
+ @project["target"][ta]['cp_defines'] = Array.new
101
+ doc.each do |d, v|
102
+ if v.nil?
103
+ st_def = "SET(CMAKE_C_FLAGS_#{ta} \"${CMAKE_C_FLAGS_#{ta}} -D#{d} \""
104
+ else
105
+ st_def = "SET(CMAKE_C_FLAGS_#{ta} \"${CMAKE_C_FLAGS_#{ta}} -D#{d}=#{v} \""
106
+ end
107
+ @project["target"][ta]['cp_defines'].insert(-1, st_def)
108
+ end
109
+ end
110
+
111
+ def target_as_predefines(target, doc)
112
+
113
+ end
114
+
115
+ def target_as_defines(target, doc)
116
+ ta = target.upcase
117
+ @project["target"][ta]['as_defines'] = Array.new
118
+ doc.each do | d, v|
119
+ if v.nil?
120
+ st_def = "SET(CMAKE_ASM_FLAGS_#{ta} \"${CMAKE_ASM_FLAGS_#{ta}} -D#{d} \""
121
+ else
122
+ st_def = "SET(CMAKE_ASM_FLAGS_#{ta} \"${CMAKE_ASM_FLAGS_#{ta}} -D#{d}=#{v} \""
123
+ end
124
+ @project["target"][ta]['as_defines'].insert(-1, st_def)
125
+ end
126
+ end
127
+
128
+ def target_as_include(target, doc)
129
+ ta = target.upcase
130
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
131
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
132
+ @project["target"][ta]['as_include'] = Array.new
133
+ doc.each do |inc|
134
+ if inc['rootdir']
135
+ full_path = @paths.fullpath(inc['rootdir'],inc['path'])
136
+ else
137
+ full_path = @paths.fullpath('default_path',inc['path'])
138
+ end
139
+ ipath = File.join("$ProjDirPath$", @paths.relpath(proj_path, full_path))
140
+ inc_str = "include_directories(#{ipath})"
141
+ @project["target"][ta]['as_include'].insert(-1, inc_str)
142
+ end
143
+ end
144
+
145
+ def target_as_flags(target, doc)
146
+ ta = target.upcase
147
+ @project["target"][ta]['as_flags'] = Array.new
148
+ doc.each do |flag|
149
+ @project["target"][ta]['as_flags'].insert(-1, "SET(CMAKE_ASM_FLAGS_#{ta} \"\$\{CMAKE_ASM_FLAGS_#{ta}\} #{flag}\")")
150
+ end
151
+ end
152
+
153
+ def target_cc_predefines(target, doc)
154
+
155
+ end
156
+
157
+ def target_cc_preincludes(target, doc)
158
+
159
+ end
160
+
161
+ def target_cc_defines(target, doc)
162
+ ta = target.upcase
163
+ @project["target"][ta]['cc_defines'] = Array.new
164
+ doc.each do |d, v|
165
+ if v.nil?
166
+ st_def = "SET(CMAKE_C_FLAGS_#{ta} \"${CMAKE_C_FLAGS_#{ta}} -D#{d} \""
167
+ else
168
+ st_def = "SET(CMAKE_C_FLAGS_#{ta} \"${CMAKE_C_FLAGS_#{ta}} -D#{d}=#{v} \""
169
+ end
170
+ @project["target"][ta]['cc_defines'].insert(-1, st_def)
171
+ end
172
+ end
173
+
174
+ def target_cc_include(target, doc)
175
+ ta = target.upcase
176
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
177
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
178
+ @project["target"][ta]['cc_include'] = Array.new
179
+ doc.each do |inc|
180
+ if inc['rootdir']
181
+ full_path = @paths.fullpath(inc['rootdir'],inc['path'])
182
+ else
183
+ full_path = @paths.fullpath('default_path',inc['path'])
184
+ end
185
+ ipath = File.join("$ProjDirPath$", @paths.relpath(proj_path, full_path))
186
+ inc_str = "include_directories(#{ipath})"
187
+ @project["target"][ta]['cc_include'].insert(-1, inc_str)
188
+ end
189
+ end
190
+
191
+ def target_cc_flags(target, doc)
192
+ ta = target.upcase
193
+ @project["target"][ta]['cc_flags'] = Array.new
194
+ doc.each do |flag|
195
+ @project["target"][ta]['cc_flags'].insert(-1, "SET(CMAKE_C_FLAGS_#{ta} \"\$\{CMAKE_C_FLAGS_#{ta}\} #{flag}\")")
196
+ end
197
+ end
198
+
199
+ def target_cxx_predefines(target, doc)
200
+
201
+ end
202
+
203
+ def target_cxx_preincludes(target, doc)
204
+
205
+ end
206
+
207
+ def target_cxx_defines(target, doc)
208
+ ta = target.upcase
209
+ @project["target"][ta]['cxx_defines'] = Array.new
210
+ doc.each do |d, v|
211
+ if v.nil?
212
+ st_def = "SET(CMAKE_CXX_FLAGS_#{ta} \"${CMAKE_CXX_FLAGS_#{ta}} -D#{d} \""
213
+ else
214
+ st_def = "SET(CMAKE_CXX_FLAGS_#{ta} \"${CMAKE_CXX_FLAGS_#{ta}} -D#{d}=#{v} \""
215
+ end
216
+ @project["target"][ta]['cxx_defines'].insert(-1, st_def)
217
+ end
218
+ end
219
+
220
+ def target_cxx_include(target, doc)
221
+ ta = target.upcase
222
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
223
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
224
+ @project["target"][ta]['cxx_include'] = Array.new
225
+ doc.each do |inc|
226
+ if inc['rootdir']
227
+ full_path = @paths.fullpath(inc['rootdir'],inc['path'])
228
+ else
229
+ full_path = @paths.fullpath('default_path',inc['path'])
230
+ end
231
+ ipath = File.join("$ProjDirPath$", @paths.relpath(proj_path, full_path))
232
+ inc_str = "include_directories(#{ipath})"
233
+ @project["target"][ta]['cxx_include'].insert(-1, inc_str)
234
+ end
235
+ end
236
+
237
+ def target_cxx_flags(target, doc)
238
+ ta = target.upcase
239
+ @project["target"][ta]['cxx_flags'] = Array.new
240
+ doc.each do |flag|
241
+ @project["target"][ta]['cxx_flags'].insert(-1, "SET(CMAKE_CXX_FLAGS_#{ta} \"\$\{CMAKE_CXX_FLAGS_#{ta}\} #{flag}\")")
242
+ end
243
+ end
244
+
245
+ def target_ld_flags(target, doc)
246
+ ta = target.upcase
247
+ @project["target"][ta]['ld_flags'] = Array.new
248
+ doc.each do |flag|
249
+ @project["target"][ta]['ld_flags'].insert(-1, "SET(CMAKE_EXE_LINKER_FLAGS_#{ta} \"\$\{CMAKE_EXE_LINKER_FLAGS_#{ta}\} #{flag}\")")
250
+ end
251
+ end
252
+
253
+ def target_libraries(target, doc)
254
+ ta = target.upcase
255
+ convert_string = {'DEBUG' => 'debug', 'RELEASE' => 'optimized'}
256
+ @project["target"][ta]['libraries'] = Array.new
257
+ header = "TARGET_LINK_LIBRARIES(#{project_name}.elf -Wl,--start-group)"
258
+ @project["target"][ta]['libraries'].insert(-1, header)
259
+ doc.each do |library|
260
+ lib = "target_link_libraries(#{project_name}.elf #{convert_string[ta]} #{library})"
261
+ @project["target"][ta]['libraries'].insert(-1, lib)
262
+ end
263
+ footer = "TARGET_LINK_LIBRARIES(#{project_name}.elf -Wl,--end-group)"
264
+ @project["target"][ta]['libraries'].insert(-1, footer)
265
+ end
266
+
267
+ def target_linker_file(target, doc)
268
+ ta = target.upcase
269
+ o_path = get_output_dir(Project::TOOLCHAIN, @paths.rootdir_table)
270
+ proj_path = File.join(@paths.rootdir_table['output_root'], o_path)
271
+ @project["target"][ta]['linker_file'] = Array.new
272
+ if doc['rootdir']
273
+ full_path = @paths.fullpath(doc['rootdir'],doc['path'])
274
+ else
275
+ full_path = @paths.fullpath('default_path',doc['path'])
276
+ end
277
+ link = File.join("${ProjDirPath}", @paths.relpath(proj_path, full_path))
278
+ linkstr = "set(CMAKE_EXE_LINKER_FLAGS_#{ta} \"${CMAKE_EXE_LINKER_FLAGS_#{ta}} -T#{link} -static\")"
279
+ @project["target"][ta]['linker_file'].insert(-1, linkstr)
280
+ end
281
+
282
+ def target_binary_file(target, doc)
283
+ ta= target.upcase
284
+ @project["target"][ta]["binary_file"] = doc
285
+ end
286
+
287
+ def target_outdir(target, doc)
288
+
289
+ end
290
+ end
291
+ end # end Module IAR
@@ -0,0 +1,6 @@
1
+
2
+
3
+ module EWD
4
+
5
+
6
+ end
@@ -0,0 +1,250 @@
1
+ require 'nokogiri'
2
+ require 'pathname'
3
+ #require 'FileUtils'
4
+
5
+ class Hash
6
+ def to_xml(doc)
7
+ return if doc.nil?
8
+ self.each do |key, value|
9
+ if doc.css("/#{key}").count == 0
10
+ mynode = Nokogiri::XML::Node.new key, doc
11
+ else
12
+ mynode = doc.css("/#{key}")[0]
13
+ end
14
+ doc.add_child mynode
15
+ value.to_xml(mynode) if value.class == Hash
16
+ mynode.content = value if value.class == String or value.class == Fixnum
17
+ end
18
+ return doc
19
+ end #end to_xml
20
+ end #end Hash
21
+
22
+ module EWP
23
+ def load_node(doc, xpath)
24
+ return doc.xpath(xpath)
25
+ end
26
+
27
+ def new_target(target, doc, name = 'debug')
28
+ nset = load_node(doc, "/project/configuration")
29
+ #use existing one
30
+ nset.each do |element|
31
+ if element.xpath("name").text.downcase == target.downcase
32
+ return element
33
+ end
34
+ end
35
+ #create new one
36
+ nset.each do |element|
37
+ #use the first available configuration
38
+ t = element.dup
39
+ t.xpath('name').text = target
40
+ #doc.xpath("/project") << t
41
+ element.add_previous_sibling(t)
42
+ return t
43
+ end
44
+ nil
45
+ end
46
+
47
+ # remove_targets remove unused targets
48
+ # Params:
49
+ # - doc: the xml node project file
50
+ # - targets_in: used target array
51
+ def remove_targets(doc, targets_in)
52
+ #remove the target that not in the targets_in
53
+ nset = load_node(doc, "//project/configuration")
54
+ targets_in.collect{|x| x.downcase}
55
+ nset.each do |element|
56
+ target = element.xpath("name").text.downcase
57
+ if !targets_in.include?(target)
58
+ element.remove
59
+ end
60
+ end
61
+ end
62
+
63
+ def remove_sources(doc)
64
+ puts "remove source"
65
+ groups = load_node(doc, "//group")
66
+ groups.each do |ele|
67
+ ele.remove
68
+ end
69
+ files = load_node(doc, "//file")
70
+ files.each do |ele|
71
+ ele.remove
72
+ end
73
+ end
74
+
75
+ def remove_unused(doc, xpath, **names)
76
+ nset = load_node(doc, xpath)
77
+ nset.each do |element|
78
+ names.each do |key, value|
79
+ if element.xpath(key).text.downcase == value.downcase
80
+ element.remove
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ def create_node(doc, hash_value)
87
+ hash_value.to_xml(doc)
88
+ end
89
+
90
+ def add_specific(target_node, doc)
91
+ doc.each do |key, value|
92
+ checked = false
93
+ options = target_node.xpath("//option")
94
+ options.each do |option|
95
+ if option.css('name').text == key
96
+ value.each do |subkey, subvalue|
97
+ if subvalue.class == String
98
+ if option.css(subkey)[0].content.nil?
99
+ option.css(subkey)[0].content = subvalue
100
+ else
101
+ create_node(option, {subkey => subvalue})
102
+ end
103
+ elsif subvalue.class == Array
104
+ subvalue.each do |line|
105
+ create_node(option, {subkey => line})
106
+ end
107
+ else
108
+ puts "not supported format must be string or array"
109
+ next
110
+ end
111
+ end
112
+ #processing done
113
+ checked = true
114
+ break
115
+ end
116
+ end
117
+ if !checked
118
+ #not an exist option need create new node
119
+ data_node = target_node.xpath('data')
120
+ option_node = create_node(data_node, "option" => nil)
121
+ create_node(option_node, {"name" => key})
122
+ value.each do |subkey, subvalue|
123
+ if subvalue.class == String
124
+ create_node(option_node, {subkey => subvalue})
125
+ elsif subvalue.class == Array
126
+ subvalue.each do |line|
127
+ create_node(option_node, {subkey => line})
128
+ end
129
+ else
130
+ puts "not supported format must be string or array"
131
+ next
132
+ end
133
+ end
134
+ end
135
+ if !checked
136
+ puts "can not find match for #{key}"
137
+ end
138
+ end
139
+ end
140
+
141
+ def set_specific(target_node, doc)
142
+ doc.each do |key, value|
143
+ checked = false
144
+ options = target_node.xpath("//option")
145
+ options.each do |option|
146
+ if option.css('name').text == key
147
+ value.each do |subkey, subvalue|
148
+ if subvalue.class == String
149
+ if option.css(subkey)[0].content.nil?
150
+ option.css(subkey)[0].content = subvalue
151
+ else
152
+ create_node(option, {subkey => subvalue})
153
+ end
154
+ elsif subvalue.class == Array
155
+ subvalue.each do |line|
156
+ create_node(node, {subkey => line})
157
+ end
158
+ else
159
+ puts "not supported format must be string or array"
160
+ next
161
+ end
162
+ end
163
+ #processing done
164
+ checked = true
165
+ break
166
+ end
167
+ end
168
+ if !checked
169
+ #not an exist option need create new node
170
+ #not an exist option need create new node
171
+ data_node = target_node.xpath('data')
172
+ option_node = create_node(data_node, "option" => nil)
173
+ create_node(option_node, {"name" => key})
174
+ value.each do |subkey, subvalue|
175
+ if subvalue.class == String
176
+ create_node(option_node, {subkey => subvalue})
177
+ elsif subvalue.class == Array
178
+ subvalue.each do |line|
179
+ create_node(option_node, {subkey => line})
180
+ end
181
+ else
182
+ puts "not supported format must be string or array"
183
+ next
184
+ end
185
+ end
186
+ end
187
+ if !checked
188
+ puts "can not find match for #{key}"
189
+ end
190
+ end
191
+ end
192
+
193
+ def save(xml, path)
194
+ Core.assert(path.is_a?(String)) do
195
+ "param is not a string #{path.class.name}"
196
+ end
197
+ FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
198
+ File.write(path, xml.to_xml)
199
+ end
200
+
201
+ def add_sources(doc, source_hash, path_mod, proj_path)
202
+ groups_existing = Array.new
203
+ files_hash = Hash.new
204
+ source_hash.each do |src|
205
+ rootdir = src['rootdir']
206
+ virtual_dir = src['virtual_dir']
207
+ path = src['path']
208
+ if virtual_dir
209
+ if ! groups_existing.include?(virtual_dir)
210
+ groups_existing.insert(-1, virtual_dir)
211
+ node = Nokogiri::XML::Node.new 'group', doc
212
+ node << "<name>#{virtual_dir}</name>"
213
+ doc.root << node
214
+ end
215
+ files_hash[virtual_dir] = Array.new if files_hash[virtual_dir].nil?
216
+ files_hash[virtual_dir].insert(-1, {'path' => path, 'rootdir' => rootdir})
217
+ else
218
+ files_hash["_"] = Array.new if files_hash["_"].nil?
219
+ files_hash["_"].insert(-1, {'path' => path, 'rootdir' => rootdir})
220
+ end
221
+ end #end source_hash
222
+ doc.css("//group").each do |node|
223
+ files_hash[node.text].each do |file|
224
+ gfiles = Nokogiri::XML::Node.new('file', node)
225
+ sfile = Nokogiri::XML::Node.new('name', gfiles)
226
+ if file['rootdir']
227
+ full_path = path_mod.fullpath(file['rootdir'],file['path'])
228
+ else
229
+ full_path = path_mod.fullpath('default_path',file['path'])
230
+ end
231
+ sfile.content = File.join("$PROJ_DIR$", path_mod.relpath(proj_path, full_path))
232
+ gfiles << sfile
233
+ node << gfiles
234
+ end
235
+ end
236
+ return if files_hash["_"].nil?
237
+ files_hash["_"].each do |file|
238
+ gfiles = Nokogiri::XML::Node.new('file', doc)
239
+ sfile = Nokogiri::XML::Node.new('name', gfiles)
240
+ if file['rootdir']
241
+ full_path = path_mod.fullpath(file['rootdir'],file['path'])
242
+ else
243
+ full_path = path_mod.fullpath('default_path',file['path'])
244
+ end
245
+ sfile.content = File.join("$PROJ_DIR$", path_mod.relpath(proj_path, full_path))
246
+ gfiles << sfile
247
+ doc.root << gfiles
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,62 @@
1
+
2
+ require 'nokogiri'
3
+
4
+
5
+ module EWW
6
+
7
+ def add_batch_project_target(xml, batchname, project, target)
8
+ definition_node = xml.at_xpath("/workspace/batchBuild/batchDefinition[name[text()='#{batchname}']]")
9
+ unless (definition_node)
10
+ build_node = xml.at_xpath("/workspace/batchBuild")
11
+ unless (build_node)
12
+ workspace_node = xml.at_xpath("/workspace")
13
+ Core.assert(workspace_node, "no <workspace> present")
14
+ # <batchBuild>
15
+ build_node = Nokogiri::XML::Node.new("batchBuild", xml)
16
+ workspace_node << build_node
17
+ end
18
+ # <batchDefinition>
19
+ definition_node = Nokogiri::XML::Node.new("batchDefinition", xml)
20
+ build_node << definition_node
21
+ # <name>
22
+ name_node = Nokogiri::XML::Node.new("name", xml)
23
+ name_node.content = batchname
24
+ definition_node << name_node
25
+ end
26
+ # <member>
27
+ member_node = Nokogiri::XML::Node.new("member", xml)
28
+ definition_node << member_node
29
+ # <project>
30
+ project_node = Nokogiri::XML::Node.new("project", xml)
31
+ project_node.content = project
32
+ member_node << project_node
33
+ # <configuration>
34
+ configuration_node = Nokogiri::XML::Node.new("configuration", xml)
35
+ configuration_node.content = target
36
+ member_node << configuration_node
37
+ end
38
+
39
+
40
+ def add_project(xml , project_path)
41
+ # find <ProjectWorkspace>
42
+ workspace_node = xml.at_xpath('/workspace')
43
+ # add <project>
44
+ project_node = Nokogiri::XML::Node.new("project", xml)
45
+ workspace_node << project_node
46
+ # add <PathAndName>
47
+ path_node = Nokogiri::XML::Node.new("path", xml)
48
+ path_node.content = project_path
49
+ project_node << path_node
50
+ # add project into existing lists
51
+ #@projects[ project_path ] = project_node
52
+ end
53
+
54
+ def save(xml, path)
55
+ Core.assert(path.is_a?(String)) do
56
+ "param is not a string #{path.class.name}"
57
+ end
58
+ FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
59
+ File.write(path, xml.to_xml)
60
+ end
61
+
62
+ end