Class: Bake::Blocks::Compile
- Defined in:
- lib/blocks/compile.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#include_list ⇒ Object
readonly
Returns the value of attribute include_list.
-
#object_files ⇒ Object
readonly
Returns the value of attribute object_files.
-
#object_files_ignored_in_lib ⇒ Object
readonly
Returns the value of attribute object_files_ignored_in_lib.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#source_files ⇒ Object
readonly
Returns the value of attribute source_files.
-
#source_files_compiled ⇒ Object
readonly
Returns the value of attribute source_files_compiled.
-
#source_files_ignored_in_lib ⇒ Object
readonly
Returns the value of attribute source_files_ignored_in_lib.
Attributes inherited from BlockBase
Class Method Summary collapse
- .read_depfile(dep_filename, projDir, lineType, command = "") ⇒ Object
-
.write_depfile(source, deps, dep_filename_conv, projDir) ⇒ Object
todo: move to toolchain util file.
Instance Method Summary collapse
- #calcCmdlineFile(object) ⇒ Object
- #calcDefines ⇒ Object
- #calcDepFile(object, type) ⇒ Object
- #calcDepFileConv(dep_filename) ⇒ Object
- #calcFlags ⇒ Object
- #calcIncludes ⇒ Object
- #calcIncludesInternal(block) ⇒ Object
- #calcObjectBasename(object) ⇒ Object
- #calcObjects ⇒ Object
- #calcSources(cleaning = false, keep = false) ⇒ Object
- #clean ⇒ Object
- #compileFile(source) ⇒ Object
- #execute ⇒ Object
- #get_object_file(source) ⇒ Object
- #get_source_type(source) ⇒ Object
- #getDefines(compiler) ⇒ Object
- #getFlags(compiler) ⇒ Object
- #ignore?(type) ⇒ Boolean
-
#initialize(block, config, referencedConfigs) ⇒ Compile
constructor
A new instance of Compile.
- #mutex ⇒ Object
- #needed?(source, object, type, dep_filename_conv) ⇒ Boolean
- #prepareIncludes ⇒ Object
Methods inherited from BlockBase
#calcFileCmd, #check_config_file, #cleanProjectDir, #config_changed?, #defaultToolchainTime, isCmdLineEqual?, prepareOutput, #printCmd, #process_console_output, #process_result, writeCmdLineFile
Constructor Details
#initialize(block, config, referencedConfigs) ⇒ Compile
Returns a new instance of Compile.
61 62 63 64 65 66 67 68 |
# File 'lib/blocks/compile.rb', line 61 def initialize(block, config, referencedConfigs) super(block, config, referencedConfigs) @objects = [] @object_files = {} @system_includes = Set.new end |
Instance Attribute Details
#include_list ⇒ Object (readonly)
Returns the value of attribute include_list.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def include_list @include_list end |
#object_files ⇒ Object (readonly)
Returns the value of attribute object_files.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def object_files @object_files end |
#object_files_ignored_in_lib ⇒ Object (readonly)
Returns the value of attribute object_files_ignored_in_lib.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def object_files_ignored_in_lib @object_files_ignored_in_lib end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def objects @objects end |
#source_files ⇒ Object (readonly)
Returns the value of attribute source_files.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def source_files @source_files end |
#source_files_compiled ⇒ Object (readonly)
Returns the value of attribute source_files_compiled.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def source_files_compiled @source_files_compiled end |
#source_files_ignored_in_lib ⇒ Object (readonly)
Returns the value of attribute source_files_ignored_in_lib.
55 56 57 |
# File 'lib/blocks/compile.rb', line 55 def source_files_ignored_in_lib @source_files_ignored_in_lib end |
Class Method Details
.read_depfile(dep_filename, projDir, lineType, command = "") ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/blocks/compile.rb', line 356 def self.read_depfile(dep_filename, projDir, lineType, command = "") deps = [] begin lineType = :single if command.include?("cafeCC") if lineType == :single File.readlines(dep_filename).each do |line| splitted = line.split(": ") if splitted.length > 1 deps << splitted[1].gsub(/[\\]/,'/') else splitted = line.split(":\t") # right now only for tasking compiler if splitted.length > 1 dep = splitted[1].gsub(/[\\]/,'/').strip dep = dep[1..-2] if dep.start_with?("\"") deps << dep end end end elsif lineType == :multi deps_string = File.read(dep_filename) deps_string = deps_string.gsub(/\\\n/,'') dep_splitted = deps_string.split(/([^\\]) /).each_slice(2).map(&:join)[2..-1] deps = dep_splitted.map { |d| d.gsub(/[\\] /,' ').gsub(/\\:\\/,':\\').gsub(/[\\]/,'/').strip }.delete_if {|d| d == "" } elsif lineType == :plain firstLine = true File.readlines(dep_filename).each do |line| if firstLine firstLine = false else deps << line end end end rescue Exception => ex1 if !Bake..dry Bake.formatter.printWarning("Could not read '#{dep_filename}'", projDir) puts ex1. if Bake..debug end return nil end deps end |
.write_depfile(source, deps, dep_filename_conv, projDir) ⇒ Object
todo: move to toolchain util file
400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/blocks/compile.rb', line 400 def self.write_depfile(source, deps, dep_filename_conv, projDir) if deps && !Bake..dry begin File.open(dep_filename_conv, 'wb') do |f| deps.each do |dep| f.puts(dep) end end rescue Exception Bake.formatter.printWarning("Could not write '#{dep_filename_conv}'", projDir) return nil end end end |
Instance Method Details
#calcCmdlineFile(object) ⇒ Object
140 141 142 |
# File 'lib/blocks/compile.rb', line 140 def calcCmdlineFile(object) File.(calcObjectBasename(object) + ".cmdline", @projectDir) end |
#calcDefines ⇒ Object
772 773 774 775 776 777 |
# File 'lib/blocks/compile.rb', line 772 def calcDefines @define_array = {} [:CPP, :C, :ASM].each do |type| @define_array[type] = getDefines(@block.tcs[:COMPILER][type]) end end |
#calcDepFile(object, type) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/blocks/compile.rb', line 144 def calcDepFile(object, type) dep_filename = nil if type != :ASM dep_filename = calcObjectBasename(object) + ".d" end dep_filename end |
#calcDepFileConv(dep_filename) ⇒ Object
152 153 154 |
# File 'lib/blocks/compile.rb', line 152 def calcDepFileConv(dep_filename) dep_filename + ".bake" end |
#calcFlags ⇒ Object
778 779 780 781 782 783 |
# File 'lib/blocks/compile.rb', line 778 def calcFlags @flag_array = {} [:CPP, :C, :ASM].each do |type| @flag_array[type] = getFlags(@block.tcs[:COMPILER][type]) end end |
#calcIncludes ⇒ Object
681 682 683 684 685 686 687 688 689 |
# File 'lib/blocks/compile.rb', line 681 def calcIncludes @blocksRead = Set.new @include_set = Set.new @include_list = [] @include_merge = {} @system_includes = Set.new calcIncludesInternal(@block) # includeDir and child dependencies with inherit: true @include_list = @include_list.flatten.uniq end |
#calcIncludesInternal(block) ⇒ Object
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'lib/blocks/compile.rb', line 639 def calcIncludesInternal(block) noDeps = @blocksRead.include?(block) @blocksRead << block block.bes.each do |be| if Metamodel::IncludeDir === be if be.inherit == true || block == @block if Bake..abs_path_in mappedInc = be.name else mappedInc = File.rel_from_to_project(@projectDir,be.name,false) mappedInc = "." if mappedInc.empty? end if !@include_set.include?(mappedInc) @include_list << mappedInc @include_set << mappedInc if !@include_merge.has_key?(mappedInc) if be.parent.mergeInc == "no" @include_merge[mappedInc] = false elsif @config.mergeInc == "all" @include_merge[mappedInc] = true elsif @block.config != be.parent && @config.mergeInc == "yes" @include_merge[mappedInc] = true else @include_merge[mappedInc] = false end end @system_includes << mappedInc if be.system end end elsif Metamodel::Dependency === be if (!noDeps) childBlock = Blocks::ALL_BLOCKS[be.name + "," + be.config] if block.projectName == be.parent.parent.name && block.configName == be.parent.name next if @blocksRead.include?(childBlock) end calcIncludesInternal(childBlock) end end end end |
#calcObjectBasename(object) ⇒ Object
136 137 138 |
# File 'lib/blocks/compile.rb', line 136 def calcObjectBasename(object) object.chomp(File.extname(object)) end |
#calcObjects ⇒ Object
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/blocks/compile.rb', line 525 def calcObjects @object_files_ignored_in_lib = [] @source_files.map! do |source| type = get_source_type(source) if not type.nil? object = get_object_file(source) if Bake..abs_path_in object = File.(object, @projectDir) source = File.(source, @projectDir) end if @objects.include?object @object_files.each do |k,v| if (v == object) # will be found exactly once Bake.formatter.printError("Source files '#{k}' and '#{source}' would result in the same object file", source) raise SystemCommandFailed.new end end end @object_files[source] = object if @source_files_ignored_in_lib.include?(source) if @source_files_link_directly.include?(source) @object_files_ignored_in_lib << object end else @objects << object end end source end end |
#calcSources(cleaning = false, keep = false) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/blocks/compile.rb', line 558 def calcSources(cleaning = false, keep = false) return @source_files if @source_files && !@source_files.empty? @source_files = [] @source_files_ignored_in_lib = [] @source_files_link_directly = [] @fileTcs = {} exclude_files = Set.new @config.excludeFiles.each do |pr| Dir.glob_dir(pr.name, @projectDir).each {|f| exclude_files << f} end source_files = Set.new @config.files.each do |sources| pr = sources.name pr = pr[2..-1] if pr.start_with?"./" res = Dir.glob_dir(pr, @projectDir).select {|f| !get_source_type(f).nil?}.sort if res.length == 0 and cleaning == false if not pr.include?"*" and not pr.include?"?" Bake.formatter.printError("Source file '#{pr}' not found", sources) raise SystemCommandFailed.new elsif Bake..verbose >= 1 Bake.formatter.printInfo("Source file pattern '#{pr}' does not match to any file", sources) end end if (sources.define.length > 0 or sources.flags.length > 0) icf = integrateCompilerFile(Utils.deep_copy(@block.tcs),sources) end res.each do |f| singleFile = res.length == 1 && res[0] == pr fTcs = (Bake..abs_path_in ? File.(f, @projectDir) : f) if ((!@fileTcs.has_key?(fTcs)) || singleFile) @fileTcs[fTcs] = icf end if source_files.include?(f) || exclude_files.include?(f) if (singleFile) @source_files_ignored_in_lib << f if sources.compileOnly || sources.linkDirectly @source_files_link_directly << f if sources.linkDirectly end next end source_files << f @source_files << f @source_files_ignored_in_lib << f if sources.compileOnly || sources.linkDirectly @source_files_link_directly << f if sources.linkDirectly end end if Bake..filename @source_files.keep_if do |source| source.include?Bake..filename end if @source_files.length == 0 and cleaning == false and @config.files.length > 0 and Bake..verbose >= 2 Bake.formatter.printInfo("#{Bake..filename} does not match to any source", @config) end end if Bake..eclipseOrder # directories reverse order, files in directories in alphabetical order dirs = [] filemap = {} @source_files.sort.reverse.each do |o| d = File.dirname(o) if filemap.include?(d) filemap[d] << o else filemap[d] = [o] dirs << d end end @source_files = [] dirs.each do |d| filemap[d].reverse.each do |f| @source_files << f end end end return @source_files end |
#clean ⇒ 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 518 519 520 521 522 523 |
# File 'lib/blocks/compile.rb', line 488 def clean if (Bake..filename or Bake..analyze) Dir.chdir(@projectDir) do calcSources(true) @source_files.each do |source| type = get_source_type(source) next if type.nil? object = get_object_file(source) if File.exist?object puts "Deleting file #{object}" if Bake..verbose >= 2 if !Bake..dry FileUtils.rm_rf(object) end end if not Bake..analyze dep_filename = calcDepFile(object, type) if dep_filename and File.exist?dep_filename puts "Deleting file #{dep_filename}" if Bake..verbose >= 2 if !Bake..dry FileUtils.rm_rf(dep_filename) end end cmdLineFile = calcCmdlineFile(object) if File.exist?cmdLineFile puts "Deleting file #{cmdLineFile}" if Bake..verbose >= 2 if !Bake..dry FileUtils.rm_rf(cmdLineFile) end end end end end end return true end |
#compileFile(source) ⇒ Object
164 165 166 167 168 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 208 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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/blocks/compile.rb', line 164 def compileFile(source) type = get_source_type(source) return if type.nil? @headerFilesFromDep = [] object = @object_files[source] dep_filename = calcDepFile(object, type) dep_filename_conv = calcDepFileConv(dep_filename) if type != :ASM cmdLineCheck = false cmdLineFile = calcCmdlineFile(object) return if ignore?(type) reason = needed?(source, object, type, dep_filename_conv) if not reason cmdLineCheck = true reason = config_changed?(cmdLineFile) end Thread.current[:filelist].add(File.(source, @projectDir)) if Bake..filelist if @fileTcs[source] compiler = @fileTcs[source][:COMPILER][type] defines = getDefines(compiler) flags = getFlags(compiler) else compiler = @block.tcs[:COMPILER][type] defines = @define_array[type] flags = @flag_array[type] end includes = @include_array[type] if Bake..prepro and compiler[:PREPRO_FLAGS] == "" Bake.formatter.printError("Error: No preprocessor option available for " + source) raise SystemCommandFailed.new end cmd = Utils.flagSplit(compiler[:PREFIX], true) cmd += Utils.flagSplit(compiler[:COMMAND], true) onlyCmd = cmd cmd += compiler[:COMPILE_FLAGS].split(" ") if dep_filename cmdDep = compiler[:DEP_FLAGS].split(" ") if compiler[:DEP_FLAGS_FILENAME] if compiler[:DEP_FLAGS_SPACE] cmdDep << dep_filename else if dep_filename.include?" " cmdDep[cmdDep.length-1] << "\"" + dep_filename + "\"" else cmdDep[cmdDep.length-1] << dep_filename end end end if compiler[:CUDA] if compiler[:CUDA_PREFIX] == "" Bake.formatter.printWarning("Warning: Cuda not yet supported by this toolchain.") else cmdDep.each do |c| cmd += [compiler[:CUDA_PREFIX], c] end cmdDep = nil end end cmd += cmdDep if cmdDep end cmd += compiler[:PREPRO_FLAGS].split(" ") if Bake..prepro cmd += flags cmd += includes cmd += defines offlag = compiler[:OBJECT_FILE_FLAG] offlag = compiler[:PREPRO_FILE_FLAG] if compiler[:PREPRO_FILE_FLAG] and Bake..prepro if compiler[:OBJ_FLAG_SPACE] cmd << offlag cmd << object else if object.include?" " cmd << offlag + "\"" + object + "\"" else cmd << offlag + object end end cmd << source if Bake..cc2j_filename cmdJson = cmd.is_a?(Array) ? cmd.join(' ') : cmd srcFilePath = source if Bake..abs_path_in srcFilePath = File.join(@projectDir, srcFilePath) if !File.is_absolute?(srcFilePath) cmdJson[source] = srcFilePath end cmdJson.gsub!("\"" , "\\\"") Blocks::CC2J << { :directory => @projectDir, :command => cmdJson, :file => srcFilePath } end if not (cmdLineCheck and BlockBase.isCmdLineEqual?(cmd, cmdLineFile)) BlockBase.prepareOutput(File.(object,@projectDir)) outputType = Bake..analyze ? "Analyzing" : (Bake..prepro ? "Preprocessing" : "Compiling") realCmd = Bake..fileCmd ? calcFileCmd(cmd, onlyCmd, object, compiler) : cmd printCmd(realCmd, "#{outputType} #{@projectName} (#{@config.name}): #{source}", reason, false) SyncOut.flushOutput() BlockBase.writeCmdLineFile(cmd, cmdLineFile) success = true consoleOutput = "" incList = nil if !Bake..diabCaseCheck success, consoleOutput = ProcessHelper.run(realCmd, false, false, nil, [0], @projectDir) if !Bake..dry incList = process_result(realCmd, consoleOutput, compiler[:ERROR_PARSER], nil, reason, success) end if type != :ASM && !Bake..analyze && !Bake..prepro Dir.mutex.synchronize do if !Bake..diabCaseCheck Dir.chdir(@projectDir) do incList = Compile.read_depfile(dep_filename, @projectDir, @block.tcs[:COMPILER][:DEP_FILE_SINGLE_LINE], compiler[:COMMAND]) if incList.nil? Compile.write_depfile(source, incList, dep_filename_conv, @projectDir) end end if !Bake..dry && Bake..caseSensitivityCheck wrongCase = [] if compiler[:COMMAND] == "dcc" if Bake..diabCaseCheck pos = cmd.find_index(compiler[:OBJECT_FILE_FLAG]) preProCmd = (cmd[0..pos-1] + cmd[pos+2..-1] + ["-E"]) preProCmd = calcFileCmd(preProCmd, onlyCmd, object, compiler, ".dccCaseCheck") if Bake..fileCmd success, consoleOutput = ProcessHelper.run(preProCmd, false, false, nil, [0], @projectDir) if !success Bake.formatter.printError("Error: could not compile #{source}") raise SystemCommandFailed.new end Dir.chdir(@projectDir) do incList = Compile.read_depfile(dep_filename, @projectDir, @block.tcs[:COMPILER][:DEP_FILE_SINGLE_LINE], compiler[:COMMAND]) Compile.write_depfile(source, incList, dep_filename_conv, @projectDir) end ergs = consoleOutput.scan(/# \d+ "([^"]+)" \d+/) ergs.each do |f| next if source.include?f[0] next if f[0].length>=2 && f[0][1] == ":" filenameToCheck = f[0].gsub(/\\/,"/").gsub(/\/\//,"/").gsub(/\A\.\//,"") if incList.none?{|i| i.include?(filenameToCheck) } Dir.chdir(@projectDir) do wrongCase << [filenameToCheck, realname(filenameToCheck)] end end end end else # not diab Dir.chdir(@projectDir) do incList.each do |dep| if dep.length<2 || dep[1] != ":" real = realname(dep) if dep != real && dep.upcase == real.upcase wrongCase << [dep, real] end end end unless incList.nil? end end if wrongCase.length > 0 wrongCase.each do |c| Bake.formatter.printError("Case sensitivity error in #{source}:\n included: #{c[0]}\n realname: #{c[1]}") end FileUtils.rm_f(dep_filename_conv) raise SystemCommandFailed.new end end end incList.each do |h| Thread.current[:filelist].add(File.(h, @projectDir)) end if Bake..filelist end check_config_file else if Bake..filename and Bake..verbose >= 1 puts "Up-to-date #{source}" SyncOut.flushOutput() end end end |
#execute ⇒ Object
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 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 476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/blocks/compile.rb', line 415 def execute return true if @config.files.empty? SyncOut.mutex.synchronize do calcIncludes calcDefines # not for files with changed tcs calcFlags # not for files with changed tcs calcSources calcObjects puts "Profiling #{Time.now - $timeStart}: prepareIncludes (#{@projectName+","+@config.name}) start..." if Bake..profiling prepareIncludes puts "Profiling #{Time.now - $timeStart}: prepareIncludes (#{@projectName+","+@config.name}) stop..." if Bake..profiling end odir = File.(@block.output_dir, @projectDir) Utils.gitIgnore(odir) if !Bake..dry fileListBlock = Set.new if Bake..filelist @source_files_compiled = @source_files.dup compileJobs = Multithread::Jobs.new(@source_files) do |jobs| while source = jobs.get_next_or_nil do if (jobs.failed && Bake..stopOnFirstError) or Bake::IDEInterface.instance.get_abort break end SyncOut.startStream() begin Thread.current[:filelist] = Set.new if Bake..filelist Thread.current[:lastCommand] = nil result = false begin compileFile(source) result = true rescue Bake::SystemCommandFailed => scf # normal compilation error rescue SystemExit => exSys rescue Exception => ex1 if not Bake::IDEInterface.instance.get_abort Bake.formatter.printError("Error: #{ex1.}") puts ex1.backtrace if Bake..debug end end jobs.set_failed if not result ensure SyncOut.stopStream() end self.mutex.synchronize do fileListBlock.merge(Thread.current[:filelist]) if Bake..filelist end end end compileJobs.join if Bake..filelist && !Bake..dry Bake..filelist.merge(fileListBlock.merge(fileListBlock)) File.open(odir + "/" + "file-list.txt", 'wb') do |f| fileListBlock.sort.each do |entry| f.puts(entry) end end end raise SystemCommandFailed.new if compileJobs.failed #end return true end |
#get_object_file(source) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/blocks/compile.rb', line 70 def get_object_file(source) # until now all OBJECT_FILE_ENDING are equal in all three types sourceEndingAdapted = @block.tcs[:KEEP_FILE_ENDINGS] ? source : source.chomp(File.extname(source)) srcWithoutDotDot = sourceEndingAdapted.gsub(/\.\./, "__") if srcWithoutDotDot[0] == '/' srcWithoutDotDot = "_" + srcWithoutDotDot elsif srcWithoutDotDot[1] == ':' srcWithoutDotDot = "_" + srcWithoutDotDot[0] + "_" + srcWithoutDotDot[2..-1] end adaptedSource = srcWithoutDotDot + (Bake..prepro ? ".i" : @block.tcs[:COMPILER][:CPP][:OBJECT_FILE_ENDING]) File.join([@block.output_dir, adaptedSource]) end |
#get_source_type(source) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/blocks/compile.rb', line 156 def get_source_type(source) ex = File.extname(source) [:CPP, :C, :ASM].each do |t| return t if @block.tcs[:COMPILER][t][:SOURCE_FILE_ENDINGS].include?(ex) end nil end |
#getDefines(compiler) ⇒ Object
764 765 766 |
# File 'lib/blocks/compile.rb', line 764 def getDefines(compiler) (compiler[:DEFINES] + Bake..defines).map {|k| "#{compiler[:DEFINE_FLAG]}#{k}"} end |
#getFlags(compiler) ⇒ Object
768 769 770 |
# File 'lib/blocks/compile.rb', line 768 def getFlags(compiler) Bake::Utils::flagSplit(compiler[:FLAGS],true) end |
#ignore?(type) ⇒ Boolean
86 87 88 |
# File 'lib/blocks/compile.rb', line 86 def ignore?(type) Bake..linkOnly or (Bake..prepro and type == :ASM) end |
#mutex ⇒ Object
57 58 59 |
# File 'lib/blocks/compile.rb', line 57 def mutex @mutex ||= Mutex.new end |
#needed?(source, object, type, dep_filename_conv) ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/blocks/compile.rb', line 90 def needed?(source, object, type, dep_filename_conv) return "because analyzer toolchain is configured" if Bake..analyze return "because prepro was specified and source is no assembler file" if Bake..prepro Dir.mutex.synchronize do Dir.chdir(@projectDir) do return "because object does not exist" if not File.exist?(object) oTime = File.mtime(object) return "because source is newer than object" if oTime < File.mtime(source) if type != :ASM return "because dependency file does not exist" if not File.exist?(dep_filename_conv) begin File.readlines(dep_filename_conv).map{|line| line.strip}.each do |dep| Thread.current[:filelist].add(File.(dep, @projectDir)) if Bake..filelist if not File.exist?(dep) # we need a hack here. with some windows configurations the compiler prints unix paths # into the dep file which cannot be found easily. this will be true for system includes, # e.g. /usr/lib/...xy.h if (Bake::Utils::OS.windows? and dep.start_with?"/") or (not Bake::Utils::OS.windows? and dep.length > 1 and dep[1] == ":") puts "Dependency header file #{dep} ignored!" if Bake..debug else return "because dependent header #{dep} does not exist" end else return "because dependent header #{dep} is newer than object" if oTime < File.mtime(dep) end end rescue Exception => ex if Bake..debug puts "While reading #{dep_filename_conv}:" puts ex. puts ex.backtrace end return "because dependency file could not be loaded" end end end end return false end |
#prepareIncludes ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/blocks/compile.rb', line 691 def prepareIncludes mergeCounter = 0 inmerge = false mdir = nil include_list_new = [] filesToCopy = {} destDirs = Set.new merging = false @include_list.reverse.each do |idir| idirs = idir.to_s idirs = File.(idirs, @projectDir) if !File.is_absolute?(idirs) if @include_merge[idir] if (!inmerge) mergeCounter += 1 mdir = File.(@block.output_dir+"/mergedIncludes#{mergeCounter}", @projectDir) FileUtils.rm_rf(mdir) Utils.gitIgnore(mdir) inmerge = true end if !merging puts "Profiling #{Time.now - $timeStart}: glob..." if Bake..profiling end merging = true toCopy = Dir.glob(idirs+"/**/*"). reject { |file| file.start_with?(idirs+"/build/") || file.start_with?(idirs+"/.") }. select { |file| File.file?(file) && /^\.(h|i|cfg)/ === File.extname(file) } toCopy.each do |t| dest = mdir+t[idirs.length..-1] destDirs << File.dirname(dest) if filesToCopy.has_key?(t) filesToCopy[t] << dest else filesToCopy[t] = [dest] end end include_list_new << (@block.output_dir+"/mergedIncludes#{mergeCounter}") else if (inmerge) inmerge = false end include_list_new << idir end end if merging sizeWarning = 100000 sum = filesToCopy.keys.inject(0) do |sum,t| si = File.size(t) puts "Size warning (>#{sizeWarning} byte): #{t} has #{si} byte" if si > sizeWarning and Bake..profiling sum + si end puts "Profiling #{Time.now - $timeStart}: copy #{sum} byte in #{filesToCopy.length} files..." if Bake..profiling destDirs.each {|d| Utils.gitIgnore(d) } filesToCopy.each do |t, dest| dest.each do |d| FileUtils.cp_r(t, d, :preserve => true) end end end @include_list = include_list_new.uniq.reverse @include_array = {} [:CPP, :C, :ASM].each do |type| @include_array[type] = @include_list.map do |k| if @system_includes.include?(k) "#{@block.tcs[:COMPILER][type][:SYSTEM_INCLUDE_PATH_FLAG]}#{k}" else "#{@block.tcs[:COMPILER][type][:INCLUDE_PATH_FLAG]}#{k}" end end end end |