Class: ConfiguratorBuilder
- Defined in:
- lib/ceedling/configurator_builder.rb
Instance Method Summary collapse
- #build_accessor_methods(config, context) ⇒ Object
- #build_global_constant(elem, value) ⇒ Object
- #build_global_constants(config) ⇒ Object
- #cleanup(in_hash) ⇒ Object
- #collect_assembly(in_hash) ⇒ Object
-
#collect_existing_test_build_input(in_hash) ⇒ Object
Collect all test build code that exists in the configured paths (runners and mocks are handled at build time).
- #collect_headers(in_hash) ⇒ Object
- #collect_release_artifact_extra_link_objects(in_hash) ⇒ Object
- #collect_release_build_input(in_hash) ⇒ Object
- #collect_source(in_hash) ⇒ Object
- #collect_source_and_include_paths(in_hash) ⇒ Object
- #collect_source_include_vendor_paths(in_hash) ⇒ Object
- #collect_test_fixture_extra_link_objects(in_hash) ⇒ Object
- #collect_test_support_source_include_paths(in_hash) ⇒ Object
- #collect_test_support_source_include_vendor_paths(in_hash) ⇒ Object
- #collect_tests(in_hash) ⇒ Object
-
#collect_vendor_framework_sources(in_hash) ⇒ Object
.c files without path.
- #collect_vendor_paths(in_hash) ⇒ Object
- #expand_all_path_globs(in_hash) ⇒ Object
-
#flattenify(config) ⇒ Object
create a flattened hash from the original configuration structure.
-
#populate_with_defaults(config, defaults) ⇒ Object
If config lacks an entry present in defaults posseses, add the default entry Processes recursively.
- #set_build_paths(in_hash, logging_path) ⇒ Object
- #set_build_thread_counts(in_hash) ⇒ Object
- #set_rakefile_components(ceedling_lib_path, in_hash) ⇒ Object
- #set_release_target(in_hash) ⇒ Object
- #set_test_preprocessor_accessors(in_hash) ⇒ Object
Instance Method Details
#build_accessor_methods(config, context) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ceedling/configurator_builder.rb', line 45 def build_accessor_methods(config, context) # Fill configurator object with accessor methods config.each_pair do |key, value| # Convert key names to Ruby method names # Some key names can be C file names that can include dashes; dashes are not allowed in Ruby method names # Downcase the key names and replace any illegal dashes with legal underscores # Downcased key names create consistency and ensure no method names become Ruby constants by accident eval("def #{key.to_s.gsub('-','_').downcase}() return @project_config_hash[:#{key}] end", context) end end |
#build_global_constant(elem, value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ceedling/configurator_builder.rb', line 19 def build_global_constant(elem, value) # Convert key names to Ruby constant names # Some key names can be C file names that can include dashes # Upcase the key names to create consitency and Ruby constants by convention # Replace dashes with underscores to match handling of Ruby accessor method names formatted_key = elem.to_s.gsub('-','_').upcase # Undefine global constant if it already exists Object.send(:remove_const, formatted_key.to_sym) if @system_wrapper.constants_include?(formatted_key) # Create global constant Object.module_eval("#{formatted_key} = value") end |
#build_global_constants(config) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/ceedling/configurator_builder.rb', line 34 def build_global_constants(config) config.each_pair do |key, value| build_global_constant(key, value) end # TODO: This wants to go somewhere better Object.module_eval("TOOLS_TEST_ASSEMBLER = {}") if (not config[:test_build_use_assembly]) && !defined?(TOOLS_TEST_ASSEMBLER) Object.module_eval("TOOLS_RELEASE_ASSEMBLER = {}") if (not config[:release_build_use_assembly]) && !defined?(TOOLS_RELEASE_ASSEMBLER) end |
#cleanup(in_hash) ⇒ Object
106 107 108 109 |
# File 'lib/ceedling/configurator_builder.rb', line 106 def cleanup(in_hash) # Ensure that include files inserted into test runners have file extensions & proper ones at that in_hash[:test_runner_includes].map!{|include| include.ext(in_hash[:extension_header])} end |
#collect_assembly(in_hash) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/ceedling/configurator_builder.rb', line 342 def collect_assembly(in_hash) all_assembly = @file_wrapper.instantiate_file_list return {:collection_all_assembly => all_assembly} if ((not in_hash[:release_build_use_assembly]) && (not in_hash[:test_build_use_assembly])) # Sprinkle in all assembly files we can find in the source folders in_hash[:collection_paths_source].each do |path| all_assembly.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) end # Also add all assembly files we can find in the support folders in_hash[:collection_paths_support].each do |path| all_assembly.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) end # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) all_assembly.resolve() return { # Add / subtract files via :files ↳ :assembly :collection_all_assembly => @file_path_collection_utils.revise_filelist( all_assembly, in_hash[:files_assembly] ) } end |
#collect_existing_test_build_input(in_hash) ⇒ Object
Collect all test build code that exists in the configured paths (runners and mocks are handled at build time)
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/ceedling/configurator_builder.rb', line 438 def collect_existing_test_build_input(in_hash) all_input = @file_wrapper.instantiate_file_list # Vendor paths for frameworks paths = [] paths << in_hash[:project_build_vendor_unity_path] paths << in_hash[:project_build_vendor_cexception_path] if (in_hash[:project_use_exceptions]) paths << in_hash[:project_build_vendor_cmock_path] if (in_hash[:project_use_mocks]) # Collect vendor framework code files paths.each do |path| all_input.include( File.join(path, '*' + EXTENSION_CORE_SOURCE) ) end paths = in_hash[:collection_paths_test] + in_hash[:collection_paths_support] + in_hash[:collection_paths_source] # Collect code files paths.each do |path| all_input.include( File.join(path, "*#{in_hash[:extension_source]}") ) all_input.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) if in_hash[:test_build_use_assembly] end # Add / subtract files via :files entries revisions = in_hash[:files_test] revisions += in_hash[:files_support] revisions += in_hash[:files_source] revisions += in_hash[:files_assembly] if in_hash[:test_build_use_assembly] # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) all_input.resolve() return { :collection_existing_test_build_input => @file_path_collection_utils.revise_filelist( all_input, revisions ) } end |
#collect_headers(in_hash) ⇒ Object
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/ceedling/configurator_builder.rb', line 385 def collect_headers(in_hash) all_headers = @file_wrapper.instantiate_file_list paths = in_hash[:collection_paths_test] + in_hash[:collection_paths_support] + in_hash[:collection_paths_include] paths.each do |path| all_headers.include( File.join(path, "*#{in_hash[:extension_header]}") ) end # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) all_headers.resolve() return { # Add / subtract files via :files ↳ :include :collection_all_headers => @file_path_collection_utils.revise_filelist( all_headers, in_hash[:files_include] ) } end |
#collect_release_artifact_extra_link_objects(in_hash) ⇒ Object
478 479 480 481 482 483 484 485 |
# File 'lib/ceedling/configurator_builder.rb', line 478 def collect_release_artifact_extra_link_objects(in_hash) objects = [] # no build paths here so plugins can remap if necessary (i.e. path mapping happens at runtime) objects << CEXCEPTION_C_FILE.ext( in_hash[:extension_object] ) if (in_hash[:project_use_exceptions]) return {:collection_release_artifact_extra_link_objects => objects} end |
#collect_release_build_input(in_hash) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/ceedling/configurator_builder.rb', line 407 def collect_release_build_input(in_hash) release_input = @file_wrapper.instantiate_file_list paths = [] paths << in_hash[:project_build_vendor_cexception_path] if (in_hash[:project_use_exceptions]) # Collect vendor framework code files paths.each do |path| release_input.include( File.join(path, '*' + EXTENSION_CORE_SOURCE) ) end # Collect source files in_hash[:collection_paths_source].each do |path| release_input.include( File.join(path, "*#{in_hash[:extension_source]}") ) release_input.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) if in_hash[:release_build_use_assembly] end # Add / subtract files via :files ↳ :source & :files ↳ :assembly revisions = in_hash[:files_source] revisions += in_hash[:files_assembly] if in_hash[:release_build_use_assembly] # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) release_input.resolve() return { :collection_release_build_input => @file_path_collection_utils.revise_filelist( release_input, revisions ) } end |
#collect_source(in_hash) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/ceedling/configurator_builder.rb', line 368 def collect_source(in_hash) all_source = @file_wrapper.instantiate_file_list in_hash[:collection_paths_source].each do |path| all_source.include( File.join(path, "*#{in_hash[:extension_source]}") ) end # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) all_source.resolve() return { # Add / subtract files via :files ↳ :source :collection_all_source => @file_path_collection_utils.revise_filelist( all_source, in_hash[:files_source] ) } end |
#collect_source_and_include_paths(in_hash) ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/ceedling/configurator_builder.rb', line 279 def collect_source_and_include_paths(in_hash) return { :collection_paths_source_and_include => ( in_hash[:collection_paths_source] + in_hash[:collection_paths_include] ) } end |
#collect_source_include_vendor_paths(in_hash) ⇒ Object
288 289 290 291 292 293 294 295 296 297 |
# File 'lib/ceedling/configurator_builder.rb', line 288 def collect_source_include_vendor_paths(in_hash) extra_paths = [] extra_paths << in_hash[:project_build_vendor_cexception_path] if (in_hash[:project_use_exceptions]) return { :collection_paths_source_include_vendor => in_hash[:collection_paths_source_and_include] + extra_paths } end |
#collect_test_fixture_extra_link_objects(in_hash) ⇒ Object
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/ceedling/configurator_builder.rb', line 488 def collect_test_fixture_extra_link_objects(in_hash) sources = [] support = @file_wrapper.instantiate_file_list() paths = in_hash[:collection_paths_support] # Collect code files paths.each do |path| support.include( File.join(path, "*#{in_hash[:extension_source]}") ) support.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) if in_hash[:test_build_use_assembly] end # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) support.resolve() support = @file_path_collection_utils.revise_filelist( support, in_hash[:files_support] ) support.each { |file| sources << file } # Create object files from all the sources objects = sources.map { |file| File.basename(file) } # No build paths here so plugins can remap if necessary (i.e. path mapping happens at runtime) objects.map! { |object| object.ext(in_hash[:extension_object]) } return { :collection_all_support => sources, :collection_test_fixture_extra_link_objects => objects } end |
#collect_test_support_source_include_paths(in_hash) ⇒ Object
300 301 302 303 304 305 306 307 308 |
# File 'lib/ceedling/configurator_builder.rb', line 300 def collect_test_support_source_include_paths(in_hash) return { :collection_paths_test_support_source_include => ( in_hash[:collection_paths_test] + in_hash[:collection_paths_support] + in_hash[:collection_paths_source] + in_hash[:collection_paths_include] ) } end |
#collect_test_support_source_include_vendor_paths(in_hash) ⇒ Object
316 317 318 319 320 321 322 |
# File 'lib/ceedling/configurator_builder.rb', line 316 def collect_test_support_source_include_vendor_paths(in_hash) return { :collection_paths_test_support_source_include_vendor => get_vendor_paths(in_hash) + in_hash[:collection_paths_test_support_source_include] } end |
#collect_tests(in_hash) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/ceedling/configurator_builder.rb', line 325 def collect_tests(in_hash) all_tests = @file_wrapper.instantiate_file_list in_hash[:collection_paths_test].each do |path| all_tests.include( File.join(path, "#{in_hash[:project_test_file_prefix]}*#{in_hash[:extension_source]}") ) end # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) all_tests.resolve() return { # Add / subtract files via :files ↳ :test :collection_all_tests => @file_path_collection_utils.revise_filelist( all_tests, in_hash[:files_test] ) } end |
#collect_vendor_framework_sources(in_hash) ⇒ Object
.c files without path
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/ceedling/configurator_builder.rb', line 521 def collect_vendor_framework_sources(in_hash) sources = [] filelist = @file_wrapper.instantiate_file_list() # Vendor paths for frameworks paths = get_vendor_paths(in_hash) # Collect vendor framework code files paths.each do |path| filelist.include( File.join(path, '*' + EXTENSION_CORE_SOURCE) ) end # Force Rake::FileList to expand patterns to ensure it happens (FileList is a bit unreliable) filelist.resolve() # Extract just source file names filelist.each do |filepath| sources << File.basename(filepath) end return {:collection_vendor_framework_sources => sources} end |
#collect_vendor_paths(in_hash) ⇒ Object
311 312 313 |
# File 'lib/ceedling/configurator_builder.rb', line 311 def collect_vendor_paths(in_hash) return {:collection_paths_vendor => get_vendor_paths(in_hash)} end |
#expand_all_path_globs(in_hash) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/ceedling/configurator_builder.rb', line 261 def (in_hash) out_hash = {} path_keys = [] in_hash.each_key do |key| next if (not key.to_s[0..4] == 'paths') path_keys << key end path_keys.each do |key| _collection = "collection_#{key}".to_sym out_hash[_collection] = @file_path_collection_utils.collect_paths( in_hash[key] ) end return out_hash end |
#flattenify(config) ⇒ Object
create a flattened hash from the original configuration structure
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ceedling/configurator_builder.rb', line 58 def flattenify(config) new_hash = {} config.each_key do | parent | # Gracefully handle empty top-level entries next if (config[parent].nil?) case config[parent] when Array config[parent].each do |hash| key = "#{parent.to_s.downcase}_#{hash.keys[0].to_s.downcase}".to_sym new_hash[key] = hash[hash.keys[0]] end when Hash config[parent].each_pair do | child, value | key = "#{parent.to_s.downcase}_#{child.to_s.downcase}".to_sym new_hash[key] = value end # Handle entries with no children, only values else new_hash["#{parent.to_s.downcase}".to_sym] = config[parent] end end return new_hash end |
#populate_with_defaults(config, defaults) ⇒ Object
If config lacks an entry present in defaults posseses, add the default entry Processes recursively
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ceedling/configurator_builder.rb', line 92 def populate_with_defaults(config, defaults) defaults.each do |key, value| # If config is missing the same key, copy in the default entry if config[key].nil? config[key] = value.is_a?(Hash) ? value.deep_clone : value # Continue recursively for hash entries elsif config[key].is_a?(Hash) && value.is_a?(Hash) populate_with_defaults(config[key], value) end end end |
#set_build_paths(in_hash, logging_path) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ceedling/configurator_builder.rb', line 112 def set_build_paths(in_hash, logging_path) out_hash = {} project_build_artifacts_root = File.join(in_hash[:project_build_root], 'artifacts') project_build_tests_root = File.join(in_hash[:project_build_root], TESTS_BASE_PATH) project_build_vendor_root = File.join(in_hash[:project_build_root], 'vendor') project_build_release_root = File.join(in_hash[:project_build_root], RELEASE_BASE_PATH) paths = [ [:project_build_artifacts_root, project_build_artifacts_root, true ], [:project_build_tests_root, project_build_tests_root, true ], [:project_build_vendor_root, project_build_vendor_root, true ], [:project_build_release_root, project_build_release_root, in_hash[:project_release_build] ], [:project_test_artifacts_path, File.join(project_build_artifacts_root, TESTS_BASE_PATH), true ], [:project_test_runners_path, File.join(project_build_tests_root, 'runners'), true ], [:project_test_results_path, File.join(project_build_tests_root, 'results'), true ], [:project_test_build_output_path, File.join(project_build_tests_root, 'out'), true ], [:project_test_build_cache_path, File.join(project_build_tests_root, 'cache'), true ], [:project_test_dependencies_path, File.join(project_build_tests_root, 'dependencies'), true ], [:project_build_vendor_unity_path, File.join(project_build_vendor_root, 'unity', 'src'), true ], [:project_build_vendor_cmock_path, File.join(project_build_vendor_root, 'cmock', 'src'), in_hash[:project_use_mocks] ], [:project_build_vendor_cexception_path, File.join(project_build_vendor_root, 'c_exception', 'lib'), in_hash[:project_use_exceptions] ], [:project_release_artifacts_path, File.join(project_build_artifacts_root, RELEASE_BASE_PATH), in_hash[:project_release_build] ], [:project_release_build_cache_path, File.join(project_build_release_root, 'cache'), in_hash[:project_release_build] ], [:project_release_build_output_path, File.join(project_build_release_root, 'out'), in_hash[:project_release_build] ], [:project_release_dependencies_path, File.join(project_build_release_root, 'dependencies'), in_hash[:project_release_build] ], [:project_log_path, logging_path, true ], [:project_test_preprocess_includes_path, File.join(project_build_tests_root, 'preprocess/includes'), (in_hash[:project_use_test_preprocessor] != :none) ], [:project_test_preprocess_files_path, File.join(project_build_tests_root, 'preprocess/files'), (in_hash[:project_use_test_preprocessor] != :none) ], ] out_hash[:project_build_paths] = [] # Fetch already set mock path out_hash[:project_build_paths] << in_hash[:cmock_mock_path] if (in_hash[:project_use_mocks]) paths.each do |path| build_path_name = path[0] build_path = path[1] build_path_add_condition = path[2] # Insert path into build paths if associated with true condition out_hash[:project_build_paths] << build_path if build_path_add_condition # Set path symbol name and path for each entry in paths array out_hash[build_path_name] = build_path end return out_hash end |
#set_build_thread_counts(in_hash) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/ceedling/configurator_builder.rb', line 199 def set_build_thread_counts(in_hash) require 'etc' auto_thread_count = (Etc.nprocessors + 4) compile_threads = in_hash[:project_compile_threads] test_threads = in_hash[:project_test_threads] case compile_threads when Integer # Do nothing--value already validated when Symbol # If a symbol, it's already been validated as legal compile_threads = auto_thread_count if compile_threads == :auto end case test_threads when Integer # Do nothing--value already validated when Symbol # If a symbol, it's already been validated as legal test_threads = auto_thread_count if test_threads == :auto end return { :project_compile_threads => compile_threads, :project_test_threads => test_threads } end |
#set_rakefile_components(ceedling_lib_path, in_hash) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ceedling/configurator_builder.rb', line 168 def set_rakefile_components(ceedling_lib_path, in_hash) out_hash = { :project_rakefile_component_files => [ File.join( ceedling_lib_path, 'tasks_base.rake' ), File.join( ceedling_lib_path, 'tasks_filesystem.rake' ), File.join( ceedling_lib_path, 'tasks_tests.rake' ), File.join( ceedling_lib_path, 'rules_tests.rake' ) ] } out_hash[:project_rakefile_component_files] << File.join( ceedling_lib_path, 'rules_release.rake' ) if (in_hash[:project_release_build]) out_hash[:project_rakefile_component_files] << File.join( ceedling_lib_path, 'tasks_release.rake' ) if (in_hash[:project_release_build]) return out_hash end |
#set_release_target(in_hash) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ceedling/configurator_builder.rb', line 185 def set_release_target(in_hash) return {} if (not in_hash[:project_release_build]) release_target_file = ((in_hash[:release_build_output].nil?) ? (DEFAULT_RELEASE_TARGET_NAME.ext(in_hash[:extension_executable])) : in_hash[:release_build_output]) release_map_file = ((in_hash[:release_build_output].nil?) ? (DEFAULT_RELEASE_TARGET_NAME.ext(in_hash[:extension_map])) : in_hash[:release_build_output].ext(in_hash[:extension_map])) return { # tempted to make a helper method in file_path_utils? stop right there, pal. you'll introduce a cyclical dependency :project_release_build_target => File.join(in_hash[:project_build_release_root], release_target_file), :project_release_build_map => File.join(in_hash[:project_build_release_root], release_map_file) } end |
#set_test_preprocessor_accessors(in_hash) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/ceedling/configurator_builder.rb', line 230 def set_test_preprocessor_accessors(in_hash) accessors = {} # :project_use_test_preprocessor already validated case in_hash[:project_use_test_preprocessor] when :none accessors = { :project_use_test_preprocessor_tests => false, :project_use_test_preprocessor_mocks => false } when :all accessors = { :project_use_test_preprocessor_tests => true, :project_use_test_preprocessor_mocks => true } when :tests accessors = { :project_use_test_preprocessor_tests => true, :project_use_test_preprocessor_mocks => false } when :mocks accessors = { :project_use_test_preprocessor_tests => false, :project_use_test_preprocessor_mocks => true } end return accessors end |