Class: Unifmt

Inherits:
UfBaseClass show all
Extended by:
Validate
Defined in:
lib/ebngen/unifmt.rb

Constant Summary collapse

@@UNIFY_KEYS =

the keys that used in the uniformat

["meta_components", 
         "targets",
         "path",
         "rootdir",
         "type",
"templates",
"outdir", 
"source", 
"virtual_dir", 
"document", 
"board", 
"identifier", 
"linker_file", 
"sectiontype", 
"binaryfile", 
"release_dir"]
@@CONFIG_SETTINGS =
[
:cp_defines ,
:as_predefines,
:as_defines,
:as_flags,
:as_preincludes ,
:as_include,
:cc_predefines,
:cc_defines,
:cc_flags,
:cc_preincludes,
:cc_include,
:cxx_predefines,
:cxx_defines,
:cxx_flags,
:cxx_preincludes,
:cxx_include,
:ld_flags,
:linker_file,
:outdir,
   :binary_file,
   :tool_chain_set_spec,
   :tool_chain_add_spec
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validate

get_validate, validate, validate_array, validate_hash, validate_string

Methods inherited from UfBaseClass

attr_accessor, attributes, #attributes

Constructor Details

#initialize(options) ⇒ Unifmt

Returns a new instance of Unifmt.



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/ebngen/unifmt.rb', line 169

def initialize(options)
	@options_default = {
	:config => "debug",
	:tool_chain => "iar",
	:type => "application",
	:board => "dummy_board",
	:project_name => "dummy_project",
	:project_root_dir => nil,
	}

	if options.class.to_s != "Hash" and not options.nil?
		puts "#{options} shall be in hash format like { :targets => [\"release\", \"debug\"]}"
		return
	end
	options.each do |key, value|
		@options_default[key] = value
	end

	@projects_hash = Hash.new
	@projects_hash[@options_default[:project_name]] = Hash.new

	if not $TARGET_TYPES.include?(@options_default[:type])
		puts "Error type #{@options_default[:type]} is not in allowable list, should be #{$TARGET_TYPES}"
		return
	end

	if not $TOOL_CHAINS.include?(@options_default[:tool_chain])
		puts "Error tool_chain #{@options_default[:tool_chain]} is not supported"
		return
	end

   	
   	self.attributes.each do |item|
   		if @@CONFIG_SETTINGS.include?(item)
   		  instance_variable_set("@#{item}",Unifmt.get_validate(item).new)
   		  #@projects_hash[tc]["targets"][config][item.to_s] = instance_variable_get("@#{item}")
   	    end
   	end
end

Instance Attribute Details

#as_definesObject

the asm defintions



58
59
60
# File 'lib/ebngen/unifmt.rb', line 58

def as_defines
  @as_defines
end

#as_flagsObject

the asm defintions



58
59
60
# File 'lib/ebngen/unifmt.rb', line 58

def as_flags
  @as_flags
end

#as_includeObject

the asm defintions



58
59
60
# File 'lib/ebngen/unifmt.rb', line 58

def as_include
  @as_include
end

#as_predefinesObject

the asm defintions



58
59
60
# File 'lib/ebngen/unifmt.rb', line 58

def as_predefines
  @as_predefines
end

#as_preincludesObject

the asm defintions



58
59
60
# File 'lib/ebngen/unifmt.rb', line 58

def as_preincludes
  @as_preincludes
end

#binary_fileObject

binary_file



84
85
86
# File 'lib/ebngen/unifmt.rb', line 84

def binary_file
  @binary_file
end

#cc_definesObject

the c code definitons



60
61
62
# File 'lib/ebngen/unifmt.rb', line 60

def cc_defines
  @cc_defines
end

#cc_flagsObject

the c code definitons



60
61
62
# File 'lib/ebngen/unifmt.rb', line 60

def cc_flags
  @cc_flags
end

#cc_includeObject

the c code definitons



60
61
62
# File 'lib/ebngen/unifmt.rb', line 60

def cc_include
  @cc_include
end

#cc_predefinesObject

the c code definitons



60
61
62
# File 'lib/ebngen/unifmt.rb', line 60

def cc_predefines
  @cc_predefines
end

#cc_preincludesObject

the c code definitons



60
61
62
# File 'lib/ebngen/unifmt.rb', line 60

def cc_preincludes
  @cc_preincludes
end

#cp_definesObject

the soc definitons



56
57
58
# File 'lib/ebngen/unifmt.rb', line 56

def cp_defines
  @cp_defines
end

#cxx_definesObject

the Cxx code difintios



62
63
64
# File 'lib/ebngen/unifmt.rb', line 62

def cxx_defines
  @cxx_defines
end

#cxx_flagsObject

the Cxx code difintios



62
63
64
# File 'lib/ebngen/unifmt.rb', line 62

def cxx_flags
  @cxx_flags
end

#cxx_includeObject

the Cxx code difintios



62
63
64
# File 'lib/ebngen/unifmt.rb', line 62

def cxx_include
  @cxx_include
end

#cxx_predefinesObject

the Cxx code difintios



62
63
64
# File 'lib/ebngen/unifmt.rb', line 62

def cxx_predefines
  @cxx_predefines
end

#cxx_preincludesObject

the Cxx code difintios



62
63
64
# File 'lib/ebngen/unifmt.rb', line 62

def cxx_preincludes
  @cxx_preincludes
end

#ld_flagsObject

link flags



64
65
66
# File 'lib/ebngen/unifmt.rb', line 64

def ld_flags
  @ld_flags
end

#librariesObject

dependant libraries information



66
67
68
# File 'lib/ebngen/unifmt.rb', line 66

def libraries
  @libraries
end

#linker_fileObject

link files



68
69
70
# File 'lib/ebngen/unifmt.rb', line 68

def linker_file
  @linker_file
end

#meta_componentsObject

meta_components dependency



70
71
72
# File 'lib/ebngen/unifmt.rb', line 70

def meta_components
  @meta_components
end

#outdirObject

project_name



78
79
80
# File 'lib/ebngen/unifmt.rb', line 78

def outdir
  @outdir
end

#project_nameObject

project_name



76
77
78
# File 'lib/ebngen/unifmt.rb', line 76

def project_name
  @project_name
end

#sourcesObject

source



72
73
74
# File 'lib/ebngen/unifmt.rb', line 72

def sources
  @sources
end

#templatesObject

template



74
75
76
# File 'lib/ebngen/unifmt.rb', line 74

def templates
  @templates
end

#tool_chain_add_specObject

tool_chain_add_apec



82
83
84
# File 'lib/ebngen/unifmt.rb', line 82

def tool_chain_add_spec
  @tool_chain_add_spec
end

#tool_chain_set_specObject

tool_chain_set_spec



80
81
82
# File 'lib/ebngen/unifmt.rb', line 80

def tool_chain_set_spec
  @tool_chain_set_spec
end

Instance Method Details

#<<(other) ⇒ Object



246
247
248
# File 'lib/ebngen/unifmt.rb', line 246

def <<(other)
	@projects_hash.deep_merge(other.output_info)
end

#as_include_unitObject



263
264
265
# File 'lib/ebngen/unifmt.rb', line 263

def as_include_unit
	return {"path" => "",  "rootdir" => ""}
end

#as_preincludes_unitObject



259
260
261
# File 'lib/ebngen/unifmt.rb', line 259

def as_preincludes_unit
	return {"path" => "",  "rootdir" => ""}
end

#cc_include_unitObject



271
272
273
# File 'lib/ebngen/unifmt.rb', line 271

def cc_include_unit
	return {"path" => "",  "rootdir" => ""}
end

#cc_preincludes_unitObject



267
268
269
# File 'lib/ebngen/unifmt.rb', line 267

def cc_preincludes_unit
	return {"path" => "",  "rootdir" => ""}
end

#cxx_include_unitObject



279
280
281
# File 'lib/ebngen/unifmt.rb', line 279

def cxx_include_unit
	return {"path" => "",  "rootdir" => ""}
end

#cxx_preincludes_unitObject



275
276
277
# File 'lib/ebngen/unifmt.rb', line 275

def cxx_preincludes_unit
	return {"path" => "",  "rootdir" => ""}
end

#helpObject



254
255
256
# File 'lib/ebngen/unifmt.rb', line 254

def help
	puts @@UNIFY_KEYS
end

#linker_file_unitObject



283
284
285
# File 'lib/ebngen/unifmt.rb', line 283

def linker_file_unit
	return {"path" => "",  "rootdir" => ""}
end

#load(project_data) ⇒ Object



250
251
252
# File 'lib/ebngen/unifmt.rb', line 250

def load(project_data)
	@projects_hash = project_data
end

#merge_target(project_data) ⇒ Object



242
243
244
# File 'lib/ebngen/unifmt.rb', line 242

def merge_target(project_data)
	@projects_hash.deep_merge(project_data)
end

#output_infoObject



238
239
240
# File 'lib/ebngen/unifmt.rb', line 238

def output_info
	@projects_hash
end

#sources_unitObject



287
288
289
# File 'lib/ebngen/unifmt.rb', line 287

def sources_unit
	return {"source" => "", "virtual_dir" => "" ,"rootdir" => "", "release_dir" => ""}
end

#updateObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/ebngen/unifmt.rb', line 209

def update
	#some mandatory sections
	@subhash = @projects_hash[@options_default[:project_name]]
	@subhash["document"] = Hash.new
	@subhash["document"]["board"] = @options_default[:board]
	@subhash["document"]["project_name"] = @options_default[:project_name]
	@subhash["document"]["project_root_dir"] = @options_default[:project_root_dir]
	tc = @options_default[:tool_chain]
	@subhash[tc] = Hash.new
	@subhash[tc]["targets"] = Hash.new
	@subhash[tc]["templates"] = instance_variable_get("@templates")
       @subhash[tc]["type"] = @options_default[:type]
    config = @options_default[:config]
   	if not $CONFIG_TYPES.include?(config)
   		puts "the config type #{config} is not supported"
   		return
   	end
	@subhash[tc]["targets"][config] = Hash.new
	self.attributes.each do |item|
   		if @@CONFIG_SETTINGS.include?(item)
   		  @subhash[tc]["targets"][config][item.to_s] = instance_variable_get("@#{item}")
   	    end
   	end
   	#other need special process features
   	@subhash[tc]["source"] = instance_variable_get("@sources")
   	@subhash[tc]["outdir"] = instance_variable_get("@outdir")
   	@subhash[tc]["libraries"] = instance_variable_get("@libraries")
end