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,238 @@
1
+ require 'deep_merge'
2
+ require 'rubygems'
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ module Utils_set
7
+ def nodes_exist?(node, subnodes)
8
+ return if subnodes.class != 'Array'
9
+ subnodes.each do |key|
10
+ return false if ! node.has_key?(key)
11
+ end
12
+ return true
13
+ end
14
+ end
15
+
16
+ class Translator
17
+ attr_accessor :data_in, :data_out, :reference_path
18
+
19
+ include Utils_set
20
+
21
+ def initialize(node, logger: nil)
22
+ @data_in = deep_copy(node)
23
+ @data_in_component = deep_copy(node)
24
+ @data_out = Hash.new
25
+ merge_by_add(@data_in)
26
+ end
27
+
28
+ def deep_copy(o)
29
+ Marshal.load(Marshal.dump(o))
30
+ end
31
+
32
+ def deep_add_merge(struct, subnode, addon)
33
+ return if Hash != struct.class
34
+ if struct[addon]['__add__'].nil?
35
+ #we do not want the addon module to change the status
36
+ struct[addon]['attribute'] = ""
37
+ struct[subnode] = struct[subnode].deep_merge(deep_copy(struct[addon]))
38
+ struct[addon]['attribute'] = 'required'
39
+ return
40
+ end
41
+ #if has more addon
42
+ if struct[addon]['__add__'].count != 0
43
+ struct[addon]['__add__'].each do |submodule|
44
+ deep_add_merge(struct, addon, submodule)
45
+ end
46
+ else
47
+ struct[addon]['attribute'] = ""
48
+ struct[subnode] = struct[subnode].deep_merge(deep_copy(struct[addon]))
49
+ struct[addon]['attribute'] = 'required'
50
+ end
51
+ end
52
+
53
+ # perform merge by "__add__" node only applys to application type
54
+ def merge_by_add(struct)
55
+ #only scan the top level
56
+ return if Hash != struct.class
57
+ struct.each_key do |subnode|
58
+ if struct[subnode]['__add__'] != nil
59
+ struct[subnode]['__add__'].each do |addon|
60
+ next if struct[addon].class != Hash
61
+ begin
62
+ next if struct[subnode]['configuration']['section-type'] != "application"
63
+ if struct[addon]['configuration']['section-type'] != "component"
64
+ puts "WARNING #{addon} is required as component but has not a component attribute"
65
+ end
66
+ rescue
67
+ puts "error with the merge_by_add with #{subnode} add #{addon}"
68
+ end
69
+ deep_add_merge(struct, subnode, addon)
70
+ end
71
+ #struct[subnode].delete('__add__')
72
+ end
73
+ end
74
+ end
75
+
76
+ def translate
77
+ translate_project()
78
+ return [@data_out, @data_in_component, @data_in]
79
+ #puts @data_out.to_yaml
80
+ end
81
+
82
+ private
83
+
84
+ def convert_rules(proj, comp = 'iar')
85
+ if @data_in[proj]['configuration']['section-type'] == "virtual-library"
86
+ if @data_in[proj].has_key?(comp)
87
+ @data_out[proj] = @data_in[proj]
88
+ board = @data_in[proj]['configuration']['board']
89
+ path = @data_out[proj][comp]['outdir']['path']
90
+ return if ! @data_out[proj].has_key?('chip-convert')
91
+ @data_out[proj][comp]['outdir']['path'] = path + @data_out[proj]['chip-convert'][board]
92
+ return
93
+ end
94
+ end
95
+
96
+ if @data_in[proj]['configuration']['section-type'] == "component"
97
+ return
98
+ end
99
+
100
+ if @data_in[proj]['configuration'].has_key?('meta_components')
101
+ @data_out[proj]['meta_components'] = @data_in[proj]['configuration']['meta_components']
102
+ end
103
+
104
+ if @data_in[proj]['configuration']['tools'].has_key?(comp)
105
+ compiler = @data_in[proj]['configuration']['tools'][comp]
106
+ @data_out[proj][comp] = Hash.new
107
+ @data_out[proj][comp]['targets'] = Hash.new
108
+ @data_out[proj][comp]['type'] = @data_in[proj]['configuration']['section-type']
109
+
110
+ @data_out[proj][comp]['templates'] = compiler['project-templates']
111
+ if compiler.has_key?("group")
112
+ @data_out[proj][comp]['group'] = compiler['group']
113
+ end
114
+
115
+ if @data_in[proj].has_key?('outdir')
116
+ board = @data_in[proj]['configuration']['board']
117
+ if @data_out[proj][comp]['type'] == "library"
118
+ if comp == 'uv4'
119
+ @data_out[proj][comp]['outdir'] = File.join(@data_in[proj]['outdir'], proj, "mdk")
120
+ else
121
+ @data_out[proj][comp]['outdir'] = File.join(@data_in[proj]['outdir'], proj, comp)
122
+ end
123
+ else
124
+ if comp == "uv4"
125
+ @data_out[proj][comp]['outdir'] = File.join(@data_in[proj]['outdir'], "mdk", board)
126
+ else
127
+ @data_out[proj][comp]['outdir'] = File.join(@data_in[proj]['outdir'], comp, board)
128
+ end
129
+ end
130
+ end
131
+ compiler['config'].each_key do |target|
132
+ next if compiler['load-to'].nil?
133
+ next if compiler['load-to'][target].nil?
134
+ create_and_deep_merge(@data_out[proj][comp]['targets'], target, compiler['config'][target])
135
+ @data_out[proj][comp]['targets'][target]['linker_file'] = Hash.new
136
+ @data_out[proj][comp]['targets'][target]['linker_file']['path'] = compiler['load-to'][target]['linker-file']
137
+ @data_out[proj][comp]['targets'][target]['linker_file']['rootdir'] = compiler['load-to'][target]['rootdir']
138
+ create_and_deep_merge(@data_out[proj][comp]['targets'][target]['binary_file'], target, compiler['binary-file'])
139
+ @data_out[proj][comp]['targets'][target]['identifier'] = compiler['load-to'][target]['identifier']
140
+ @data_out[proj][comp]['targets'][target]['config'] = compiler['load-to'][target]['config']
141
+ @data_out[proj][comp]['targets'][target]['target'] = compiler['load-to'][target]['target']
142
+ @data_out[proj][comp]['targets'][target]['libraries'] = Array.new
143
+ if ! @data_in[proj]['configuration']['section-depends'].nil?
144
+ @data_in[proj]['configuration']['section-depends'].each do |dep|
145
+ @data_out[proj][comp]['targets'][target]['libraries'].insert(-1, dep)
146
+ end
147
+ end
148
+ end
149
+ #now translate the source
150
+ return if ! @data_in[proj].has_key?('modules')
151
+
152
+ if @data_in[proj].has_key?('tools')
153
+ #process compile depend files here
154
+ if @data_in[proj]['tools'].has_key?(comp) and @data_in[proj].has_key?('modules') and @data_in[proj]["configuration"]["section-type"] == "application"
155
+ @data_in[proj]['tools'][comp]['files'].each do |file|
156
+ puts file
157
+ next ! file.has_key?("virtual-dir")
158
+ file['virtual_dir'] = file.delete "virtual-dir"
159
+ end
160
+ create_and_deep_merge(@data_out[proj][comp], 'source', @data_in[proj]['tools'][comp]['files'])
161
+ end
162
+ end
163
+ @data_in[proj]['modules'].each_key do |mod|
164
+ if @data_in[proj]['modules'][mod].class == Hash and @data_in[proj]['modules'][mod].has_key?('virtual-dir')
165
+ temp = Marshal.load(Marshal.dump(@data_in[proj]['modules'][mod]['files']))
166
+ temp.each do |file|
167
+ #puts "old virtual-dir is #{mod} #{file['virtual-dir']}"
168
+ #puts "current #{@data_in[proj]['modules'][mod]['virtual-dir'].to_s}"
169
+ if file['virtual-dir'] == nil
170
+ file['virtual-dir'] = @data_in[proj]['modules'][mod]['virtual-dir'].to_s
171
+ else
172
+ if ! file.has_key?("processed")
173
+ #puts proj,mod,file
174
+ #puts file['virtual-dir']
175
+ #puts @data_in[proj]['modules'][mod]['virtual-dir'].to_s
176
+ file['virtual-dir'] = "#{@data_in[proj]['modules'][mod]['virtual-dir']}:#{file['virtual-dir']}"
177
+ file['processed'] = "true"
178
+ end
179
+ end
180
+ #puts "new virtual-dir is #{file['virtual-dir']} for #{proj}"
181
+ if comp == 'uv4' || comp == 'mdk'
182
+ file['virtual-dir'] = file['virtual-dir'].gsub(':','-')
183
+ end
184
+ file['virtual_dir'] = file.delete "virtual-dir"
185
+ end
186
+ create_and_deep_merge(@data_out[proj][comp], 'source', temp)
187
+
188
+ else
189
+ if @data_in[proj]['modules'][mod].class == Hash and @data_in[proj]['modules'][mod].has_key?('files')
190
+ @data_in[proj]['modules'][mod]['files'].each do |file|
191
+ next ! file.has_key?("virtual-dir")
192
+ file['virtual_dir'] = file.delete "virtual-dir"
193
+ end
194
+ create_and_deep_merge(@data_out[proj][comp], 'source', @data_in[proj]['modules'][mod]['files'])
195
+ end
196
+ end
197
+ end
198
+
199
+ if @data_in[proj].has_key?('document')
200
+ create_and_deep_merge(@data_out[proj][comp],'document', @data_in[proj]['document'])
201
+ end
202
+ end
203
+ end
204
+
205
+ def create_and_deep_merge(a, b, c)
206
+ return if c == nil
207
+ if c.class == Array
208
+ a[b] = Array.new if a[b] == nil
209
+ a[b] = a[b] + c.dup
210
+ else
211
+ a[b] = Hash.new if a[b] == nil
212
+ a[b].deep_merge(c)
213
+ end
214
+ end
215
+
216
+ def translate_project
217
+ @data_in.each_key do |proj|
218
+ next if @data_in[proj].nil?
219
+ if @data_in[proj].has_key?('configuration')
220
+ next if @data_in[proj]['configuration']['section-type'] == "component"
221
+ end
222
+ @data_out[proj] = Hash.new
223
+ if @data_in[proj].has_key?('section-type')
224
+ @data_out[proj]['type'] = @data_in[proj]['section-type']
225
+ end
226
+ convert_rules(proj,'iar')
227
+ #convert_rules(proj,'uv4')
228
+ convert_rules(proj,'cmake')
229
+ #convert_rules(proj,'armgcc')
230
+ #convert_rules(proj,'kds')
231
+ #convert_rules(proj,'atl')
232
+ #convert_rules(proj,'lpcx')
233
+ end
234
+ @data_in_component.each_key do |proj|
235
+ # puts "#{proj} TBD"
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,290 @@
1
+ require 'pathname'
2
+ require "deep_merge"
3
+ #this is for contraucture a uniformat input hierarchy hash
4
+ require_relative 'settings/tool_chains'
5
+ require_relative 'settings/target_types'
6
+
7
+ class UfBaseClass
8
+ def self.attr_accessor(*vars)
9
+ @attributes ||= []
10
+ @attributes.concat vars
11
+ super(*vars)
12
+ end
13
+
14
+ def self.attributes
15
+ @attributes
16
+ end
17
+
18
+ def attributes
19
+ self.class.attributes
20
+ end
21
+ end
22
+
23
+ module Validate
24
+ def validate_array(name)
25
+ @validate_hash = Hash.new if @validate_hash.nil?
26
+ @validate_hash[name] = Array
27
+ end
28
+
29
+ def validate_string(name)
30
+ @validate_hash = Hash.new if @validate_hash.nil?
31
+ @validate_hash[name] = String
32
+ end
33
+
34
+ def validate_hash(name)
35
+ @validate_hash = Hash.new if @validate_hash.nil?
36
+ @validate_hash[name] = Hash
37
+ end
38
+
39
+ def validate(name, value)
40
+ if @validate_hash.has_key?(name)
41
+ return @validate_hash[name] == value.class
42
+ end
43
+ true
44
+ end
45
+
46
+ def get_validate(name)
47
+ if @validate_hash.has_key?(name)
48
+ return @validate_hash[name]
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ class Unifmt < UfBaseClass
55
+ #the soc definitons
56
+ attr_accessor :cp_defines
57
+ #the asm defintions
58
+ attr_accessor :as_predefines, :as_preincludes, :as_defines, :as_include, :as_flags
59
+ #the c code definitons
60
+ attr_accessor :cc_predefines, :cc_preincludes, :cc_defines, :cc_include, :cc_flags
61
+ #the Cxx code difintios
62
+ attr_accessor :cxx_predefines, :cxx_preincludes, :cxx_defines, :cxx_include, :cxx_flags
63
+ #link flags
64
+ attr_accessor :ld_flags
65
+ #dependant libraries information
66
+ attr_accessor :libraries
67
+ #link files
68
+ attr_accessor :linker_file
69
+ #meta_components dependency
70
+ attr_accessor :meta_components
71
+ #source
72
+ attr_accessor :sources
73
+ #template
74
+ attr_accessor :templates
75
+ #project_name
76
+ attr_accessor :project_name
77
+ #project_name
78
+ attr_accessor :outdir
79
+ #tool_chain_set_spec
80
+ attr_accessor :tool_chain_set_spec
81
+ #tool_chain_add_apec
82
+ attr_accessor :tool_chain_add_spec
83
+ #binary_file
84
+ attr_accessor :binary_file
85
+
86
+ #the keys that used in the uniformat
87
+ @@UNIFY_KEYS = ["meta_components",
88
+ "targets",
89
+ "path",
90
+ "rootdir",
91
+ "type",
92
+ "templates",
93
+ "outdir",
94
+ "source",
95
+ "virtual_dir",
96
+ "document",
97
+ "board",
98
+ "identifier",
99
+ "linker_file",
100
+ "sectiontype",
101
+ "binaryfile",
102
+ "release_dir"]
103
+
104
+ @@CONFIG_SETTINGS = [
105
+ :cp_defines ,
106
+ :as_predefines,
107
+ :as_defines,
108
+ :as_flags,
109
+ :as_preincludes ,
110
+ :as_include,
111
+ :cc_predefines,
112
+ :cc_defines,
113
+ :cc_flags,
114
+ :cc_preincludes,
115
+ :cc_include,
116
+ :cxx_predefines,
117
+ :cxx_defines,
118
+ :cxx_flags,
119
+ :cxx_preincludes,
120
+ :cxx_include,
121
+ :ld_flags,
122
+ :linker_file,
123
+ :outdir,
124
+ :binary_file,
125
+ :tool_chain_set_spec,
126
+ :tool_chain_add_spec
127
+ ]
128
+
129
+ extend Validate
130
+
131
+ #constrains of the variables
132
+ validate_hash :cp_defines
133
+ validate_hash :as_predefines
134
+ validate_hash :as_defines
135
+ validate_array :as_flags
136
+ validate_array :as_preincludes
137
+ validate_array :as_include
138
+
139
+ validate_hash :cc_predefines
140
+ validate_hash :cc_defines
141
+ validate_array :cc_flags
142
+ validate_array :cc_preincludes
143
+ validate_array :cc_include
144
+
145
+ validate_hash :cxx_predefines
146
+ validate_hash :cxx_defines
147
+ validate_array :cxx_flags
148
+ validate_array :cxx_preincludes
149
+ validate_array :cxx_include
150
+
151
+ validate_array :ld_flags
152
+ validate_array :meta_components
153
+
154
+ validate_array :libraries
155
+
156
+ validate_hash :linker_file
157
+
158
+
159
+ validate_hash :sources
160
+
161
+ validate_array :templates
162
+
163
+ validate_string :project_name
164
+ validate_string :outdir
165
+ validate_string :binary_file
166
+ validate_hash :tool_chain_set_spec
167
+ validate_hash :tool_chain_add_spec
168
+
169
+ def initialize(options)
170
+ @options_default = {
171
+ :config => "debug",
172
+ :tool_chain => "iar",
173
+ :type => "application",
174
+ :board => "dummy_board",
175
+ :project_name => "dummy_project",
176
+ :project_root_dir => nil,
177
+ }
178
+
179
+ if options.class.to_s != "Hash" and not options.nil?
180
+ puts "#{options} shall be in hash format like { :targets => [\"release\", \"debug\"]}"
181
+ return
182
+ end
183
+ options.each do |key, value|
184
+ @options_default[key] = value
185
+ end
186
+
187
+ @projects_hash = Hash.new
188
+ @projects_hash[@options_default[:project_name]] = Hash.new
189
+
190
+ if not $TARGET_TYPES.include?(@options_default[:type])
191
+ puts "Error type #{@options_default[:type]} is not in allowable list, should be #{$TARGET_TYPES}"
192
+ return
193
+ end
194
+
195
+ if not $TOOL_CHAINS.include?(@options_default[:tool_chain])
196
+ puts "Error tool_chain #{@options_default[:tool_chain]} is not supported"
197
+ return
198
+ end
199
+
200
+
201
+ self.attributes.each do |item|
202
+ if @@CONFIG_SETTINGS.include?(item)
203
+ instance_variable_set("@#{item}",Unifmt.get_validate(item).new)
204
+ #@projects_hash[tc]["targets"][config][item.to_s] = instance_variable_get("@#{item}")
205
+ end
206
+ end
207
+ end
208
+
209
+ def update
210
+ #some mandatory sections
211
+ @subhash = @projects_hash[@options_default[:project_name]]
212
+ @subhash["document"] = Hash.new
213
+ @subhash["document"]["board"] = @options_default[:board]
214
+ @subhash["document"]["project_name"] = @options_default[:project_name]
215
+ @subhash["document"]["project_root_dir"] = @options_default[:project_root_dir]
216
+ tc = @options_default[:tool_chain]
217
+ @subhash[tc] = Hash.new
218
+ @subhash[tc]["targets"] = Hash.new
219
+ @subhash[tc]["templates"] = instance_variable_get("@templates")
220
+ @subhash[tc]["type"] = @options_default[:type]
221
+ config = @options_default[:config]
222
+ if not $CONFIG_TYPES.include?(config)
223
+ puts "the config type #{config} is not supported"
224
+ return
225
+ end
226
+ @subhash[tc]["targets"][config] = Hash.new
227
+ self.attributes.each do |item|
228
+ if @@CONFIG_SETTINGS.include?(item)
229
+ @subhash[tc]["targets"][config][item.to_s] = instance_variable_get("@#{item}")
230
+ end
231
+ end
232
+ #other need special process features
233
+ @subhash[tc]["source"] = instance_variable_get("@sources")
234
+ @subhash[tc]["outdir"] = instance_variable_get("@outdir")
235
+ @subhash[tc]["libraries"] = instance_variable_get("@libraries")
236
+ end
237
+
238
+ def output_info
239
+ @projects_hash
240
+ end
241
+
242
+ def merge_target(project_data)
243
+ @projects_hash.deep_merge(project_data)
244
+ end
245
+
246
+ def <<(other)
247
+ @projects_hash.deep_merge(other.output_info)
248
+ end
249
+
250
+ def load(project_data)
251
+ @projects_hash = project_data
252
+ end
253
+
254
+ def help
255
+ puts @@UNIFY_KEYS
256
+ end
257
+
258
+
259
+ def as_preincludes_unit
260
+ return {"path" => "", "rootdir" => ""}
261
+ end
262
+
263
+ def as_include_unit
264
+ return {"path" => "", "rootdir" => ""}
265
+ end
266
+
267
+ def cc_preincludes_unit
268
+ return {"path" => "", "rootdir" => ""}
269
+ end
270
+
271
+ def cc_include_unit
272
+ return {"path" => "", "rootdir" => ""}
273
+ end
274
+
275
+ def cxx_preincludes_unit
276
+ return {"path" => "", "rootdir" => ""}
277
+ end
278
+
279
+ def cxx_include_unit
280
+ return {"path" => "", "rootdir" => ""}
281
+ end
282
+
283
+ def linker_file_unit
284
+ return {"path" => "", "rootdir" => ""}
285
+ end
286
+
287
+ def sources_unit
288
+ return {"source" => "", "virtual_dir" => "" ,"rootdir" => "", "release_dir" => ""}
289
+ end
290
+ end
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.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hake Huang
@@ -18,6 +18,24 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/ebngen.rb
21
+ - lib/ebngen/adapter/_assert.rb
22
+ - lib/ebngen/adapter/_base.rb
23
+ - lib/ebngen/adapter/_path_modifier.rb
24
+ - lib/ebngen/adapter/_yml_helper.rb
25
+ - lib/ebngen/adapter/cmake.rb
26
+ - lib/ebngen/adapter/cmake/CMakeList.txt
27
+ - lib/ebngen/adapter/cmake/txt.rb
28
+ - lib/ebngen/adapter/iar.rb
29
+ - lib/ebngen/adapter/iar/ewd.rb
30
+ - lib/ebngen/adapter/iar/ewp.rb
31
+ - lib/ebngen/adapter/iar/eww.rb
32
+ - lib/ebngen/assembly.rb
33
+ - lib/ebngen/ebngen.rb
34
+ - lib/ebngen/generate.rb
35
+ - lib/ebngen/settings/target_types.rb
36
+ - lib/ebngen/settings/tool_chains.rb
37
+ - lib/ebngen/translate.rb
38
+ - lib/ebngen/unifmt.rb
21
39
  homepage: http://rubygems.org/gems/ebngen
22
40
  licenses:
23
41
  - Apache-2.0