ebngen 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ebngen/unifmt.rb CHANGED
@@ -1,290 +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
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.5
4
+ version: 1.0.6
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-06-16 00:00:00.000000000 Z
12
+ date: 2017-06-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: embedded project generator
15
15
  email: hakehuang@gmail.com
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 2.6.6
59
+ rubygems_version: 2.6.7
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: ebngen