Class: Bake::Blocks::Block
- Inherits:
-
Object
- Object
- Bake::Blocks::Block
- Defined in:
- lib/blocks/block.rb
Constant Summary collapse
- @@block_counter =
0- @@delayed_result =
true- @@threads =
[]
Instance Attribute Summary collapse
-
#bes ⇒ Object
Returns the value of attribute bes.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#configName ⇒ Object
readonly
Returns the value of attribute configName.
-
#inDeps ⇒ Object
Returns the value of attribute inDeps.
-
#lib_elements ⇒ Object
readonly
Returns the value of attribute lib_elements.
-
#library ⇒ Object
readonly
Returns the value of attribute library.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#prebuild ⇒ Object
readonly
Returns the value of attribute prebuild.
-
#projectDir ⇒ Object
readonly
Returns the value of attribute projectDir.
-
#projectName ⇒ Object
readonly
Returns the value of attribute projectName.
-
#result ⇒ Object
Returns the value of attribute result.
-
#tcs ⇒ Object
readonly
Returns the value of attribute tcs.
-
#visited ⇒ Object
Returns the value of attribute visited.
Class Method Summary collapse
- .block_counter ⇒ Object
- .delayed_result ⇒ Object
- .inc_block_counter ⇒ Object
- .init_threads ⇒ Object
- .reset_block_counter ⇒ Object
- .reset_delayed_result ⇒ Object
- .set_delayed_result ⇒ Object
- .set_num_projects(blocks) ⇒ Object
- .threads ⇒ Object
- .waitForAllThreads ⇒ Object
- .waitForFreeThread ⇒ Object
Instance Method Summary collapse
- #blockAbort?(res) ⇒ Boolean
- #calcIsBuildBlock ⇒ Object
- #calcOutputDir ⇒ Object
- #callDeps(method) ⇒ Object
- #callSteps(method) ⇒ Object
- #childs ⇒ Object
- #clean ⇒ Object
- #cleanSteps ⇒ Object
- #convPath(dir, elem = nil, warnIfLocal = false) ⇒ Object
- #dependencies ⇒ Object
- #execute ⇒ Object
- #execute_in_thread(steps) ⇒ Object
- #executeStep(step, method) ⇒ Object
- #exits ⇒ Object
- #exitSteps ⇒ Object
- #getBlocks(method) ⇒ Object
- #getCompileBlocks ⇒ Object
- #getSubBlocks(b, method) ⇒ Object
- #independent?(method, step) ⇒ Boolean
-
#initialize(config, referencedConfigs, prebuild, tcs) ⇒ Block
constructor
A new instance of Block.
- #isBuildBlock? ⇒ Boolean
- #isMainProject? ⇒ Boolean
- #mainSteps ⇒ Object
- #parents ⇒ Object
- #postSteps ⇒ Object
- #preSteps ⇒ Object
- #qname ⇒ Object
- #set_library(library) ⇒ Object
- #startup ⇒ Object
- #startupSteps ⇒ Object
Constructor Details
#initialize(config, referencedConfigs, prebuild, tcs) ⇒ Block
Returns a new instance of Block.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/blocks/block.rb', line 72 def initialize(config, referencedConfigs, prebuild, tcs) @inDeps = false @prebuild = prebuild @visited = false @library = nil @config = config @referencedConfigs = referencedConfigs @projectName = config.parent.name @configName = config.name @projectDir = config.get_project_dir @result = true @tcs = tcs @bes = [] @lib_elements = [] calcOutputDir end |
Instance Attribute Details
#bes ⇒ Object
Returns the value of attribute bes.
26 27 28 |
# File 'lib/blocks/block.rb', line 26 def bes @bes end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def config @config end |
#configName ⇒ Object (readonly)
Returns the value of attribute configName.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def configName @configName end |
#inDeps ⇒ Object
Returns the value of attribute inDeps.
26 27 28 |
# File 'lib/blocks/block.rb', line 26 def inDeps @inDeps end |
#lib_elements ⇒ Object (readonly)
Returns the value of attribute lib_elements.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def lib_elements @lib_elements end |
#library ⇒ Object (readonly)
Returns the value of attribute library.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def library @library end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def output_dir @output_dir end |
#prebuild ⇒ Object (readonly)
Returns the value of attribute prebuild.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def prebuild @prebuild end |
#projectDir ⇒ Object (readonly)
Returns the value of attribute projectDir.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def projectDir @projectDir end |
#projectName ⇒ Object (readonly)
Returns the value of attribute projectName.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def projectName @projectName end |
#result ⇒ Object
Returns the value of attribute result.
26 27 28 |
# File 'lib/blocks/block.rb', line 26 def result @result end |
#tcs ⇒ Object (readonly)
Returns the value of attribute tcs.
25 26 27 |
# File 'lib/blocks/block.rb', line 25 def tcs @tcs end |
#visited ⇒ Object
Returns the value of attribute visited.
26 27 28 |
# File 'lib/blocks/block.rb', line 26 def visited @visited end |
Class Method Details
.block_counter ⇒ Object
163 164 165 |
# File 'lib/blocks/block.rb', line 163 def self.block_counter @@block_counter end |
.delayed_result ⇒ Object
179 180 181 |
# File 'lib/blocks/block.rb', line 179 def self.delayed_result @@delayed_result end |
.inc_block_counter ⇒ Object
159 160 161 |
# File 'lib/blocks/block.rb', line 159 def self.inc_block_counter() @@block_counter += 1 end |
.init_threads ⇒ Object
492 493 494 495 496 497 498 |
# File 'lib/blocks/block.rb', line 492 def self.init_threads() @@threads = [] @@result = true @@mutex = Mutex.new @@mutexStdinSelect = Mutex.new Bake::Multithread::Jobs.init_semaphore() end |
.reset_block_counter ⇒ Object
167 168 169 |
# File 'lib/blocks/block.rb', line 167 def self.reset_block_counter @@block_counter = 1 end |
.reset_delayed_result ⇒ Object
175 176 177 |
# File 'lib/blocks/block.rb', line 175 def self.reset_delayed_result @@delayed_result = true end |
.set_delayed_result ⇒ Object
171 172 173 |
# File 'lib/blocks/block.rb', line 171 def self.set_delayed_result @@delayed_result = false end |
.set_num_projects(blocks) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/blocks/block.rb', line 221 def self.set_num_projects(blocks) if Bake..verbose >= 2 @@num_projects = blocks.length else counter = 0 blocks.each do |b| counter += 1 if b.isBuildBlock? end @@num_projects = counter end end |
.threads ⇒ Object
183 184 185 |
# File 'lib/blocks/block.rb', line 183 def self.threads @@threads end |
.waitForAllThreads ⇒ Object
187 188 189 190 191 192 193 194 |
# File 'lib/blocks/block.rb', line 187 def self.waitForAllThreads if @@threads.length > 0 STDOUT.puts "DEBUG_THREADS: Wait for all threads." if Bake..debug_threads @@threads.each{|t| while not t.join(2) do end} @@threads = [] STDOUT.puts "DEBUG_THREADS: All threads finished." if Bake..debug_threads end end |
.waitForFreeThread ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/blocks/block.rb', line 289 def self.waitForFreeThread if @@threads.length == Bake..threads begin STDOUT.puts "DEBUG_THREADS: Wait for free thread." if Bake..debug_threads endedThread = ThreadsWait.new(*@@threads).next_wait STDOUT.puts "DEBUG_THREADS: Thread free: #{endedThread.object_id}" if Bake..debug_threads @@threads.delete(endedThread) rescue ErrNoWaitingThread end end end |
Instance Method Details
#blockAbort?(res) ⇒ Boolean
342 343 344 |
# File 'lib/blocks/block.rb', line 342 def blockAbort?(res) ((not res) || !@@delayed_result) and Bake..stopOnFirstError or Bake::IDEInterface.instance.get_abort end |
#calcIsBuildBlock ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/blocks/block.rb', line 196 def calcIsBuildBlock @startupSteps ||= [] return true if Metamodel::ExecutableConfig === @config if Metamodel::CustomConfig === @config return true if @config.step else return true if @config.files.length > 0 end if ((@config.startupSteps && @config.startupSteps.step.length > 0) || (@config.preSteps && @config.preSteps.step.length > 0) || (@config.postSteps && @config.postSteps.step.length > 0) || (@config.exitSteps && @config.exitSteps.step.length > 0) || (@config.cleanSteps && @config.cleanSteps.step.length > 0) || (@config.preSteps && @config.preSteps.step.length > 0)) return true end return false end |
#calcOutputDir ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/blocks/block.rb', line 553 def calcOutputDir if @tcs[:OUTPUT_DIR] != nil p = convPath(@tcs[:OUTPUT_DIR]) p = p[2..-1] if p.start_with?("./") @output_dir = p else qacPart = Bake..qac ? (".qac" + Bake..buildDirDelimiter) : "" if isMainProject? @output_dir = "build" + Bake..buildDirDelimiter + qacPart + Bake..build_config else @output_dir = "build" + Bake..buildDirDelimiter + qacPart + @config.name + "_" + Bake..main_project_name + "_" + Bake..build_config end end end |
#callDeps(method) ⇒ Object
280 281 282 283 284 285 286 287 |
# File 'lib/blocks/block.rb', line 280 def callDeps(method) depResult = true dependencies.each do |dep| depResult = (ALL_BLOCKS[dep].send(method) and depResult) break if (!depResult) && Bake..stopOnFirstError end return depResult end |
#callSteps(method) ⇒ Object
352 353 354 355 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 |
# File 'lib/blocks/block.rb', line 352 def callSteps(method) @config.writeEnvVars() Thread.current[:lastCommand] = nil allSteps = (preSteps + mainSteps + postSteps) # check if we have to delay the output (if the last step of this block is not in a thread) @outputStep = nil allSteps.each { |step| @outputStep = independent?(method, step) ? step : nil } while !allSteps.empty? parallel = [] while allSteps.first && independent?(method, allSteps.first) parallel << allSteps.shift end if parallel.length > 0 execute_in_thread(parallel) { lastStep = Thread.current[:steps].last begin Thread.current[:steps].each do |step| Multithread::Jobs.incThread() if !Compile === step begin @result = executeStep(step, :execute) if @result ensure Multithread::Jobs.decThread() if !Compile === step end @@delayed_result &&= @result break if blockAbort?(@result) end ensure SyncOut.stopStream() if lastStep == @outputStep if Bake..syncedOutput end } else step = allSteps.shift Blocks::Block::waitForAllThreads() @result = executeStep(step, method) if @result @outputStep = nil if !@result && blockAbort?(@result) end return @result if blockAbort?(@result) end return @result end |
#childs ⇒ Object
56 57 58 |
# File 'lib/blocks/block.rb', line 56 def childs @childs ||= [] end |
#clean ⇒ Object
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 487 488 489 490 |
# File 'lib/blocks/block.rb', line 450 def clean return true if (@visited) @visited = true depResult = callDeps(:clean) return false if not depResult and Bake..stopOnFirstError if Bake..verbose >= 2 typeStr = "Cleaning" if @prebuild typeStr = "Checking" elsif not isBuildBlock? typeStr = "Skipping" end Bake.formatter.printAdditionalInfo "**** #{typeStr} #{Block.block_counter} of #{@@num_projects}: #{@projectName} (#{@configName}) ****" end if Bake..verbose >= 2 || (isBuildBlock? && Bake..verbose >= 1) Block.inc_block_counter() end @result = callSteps(:clean) if Bake..clobber Dir.chdir(@projectDir) do if File.exist?".bake" puts "Deleting folder .bake" if Bake..verbose >= 2 if !Bake..dry FileUtils.rm_rf(".bake") end end end end cleanSteps.each do |step| @result = executeStep(step, :cleanStep) if @result return false if not @result and Bake..stopOnFirstError end return (depResult && @result) end |
#cleanSteps ⇒ Object
48 49 50 |
# File 'lib/blocks/block.rb', line 48 def cleanSteps @cleanSteps ||= [] end |
#convPath(dir, elem = nil, warnIfLocal = false) ⇒ Object
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/blocks/block.rb', line 94 def convPath(dir, elem=nil, warnIfLocal=false) if dir.respond_to?("name") d = dir.name elem = dir else d = dir end return d if Bake..no_autodir inc = d.split("/") if (inc[0] == "..") # very simple check, but should be okay for 99.9 % of the cases if elem and Bake..verbose >= 2 SyncOut.mutex.synchronize do Bake.formatter.printInfo("path starts with \"..\"", elem) end end end res = [] return d if (inc[0] == "." || inc[0] == "..") # prio 0: force local if (inc[0] == @projectName) # prio 1: the real path magic resPathMagic = inc[1..-1].join("/") # within self resPathMagic = "." if resPathMagic == "" res << resPathMagic elsif @referencedConfigs.include?(inc[0]) dirOther = @referencedConfigs[inc[0]].first.parent.get_project_dir resPathMagic = File.rel_from_to_project(@projectDir, dirOther, false) postfix = inc[1..-1].join("/") resPathMagic = resPathMagic + "/" + postfix if postfix != "" resPathMagic = "." if resPathMagic == "" res << resPathMagic end if File.exists?(@projectDir + "/" + d) # prio 2: local, e.g. "include" res << d end # prioo 3: check if dir exists without Project.meta entry Bake..roots.each do |r| absIncDir = r.dir+"/"+d if File.exists?(absIncDir) res << File.rel_from_to_project(@projectDir,absIncDir,false) end end return d if res.empty? # prio 4: fallback, no path found res = res.map{ |r| Pathname.new(r).cleanpath.to_s }.uniq if warnIfLocal && res.length > 1 if elem and Bake..verbose >= 2 SyncOut.mutex.synchronize do Bake.formatter.printInfo("#{d} matches several paths:", elem) puts " #{res[0]} (chosen)" res[1..-1].each { |r| puts " #{r}" } end end end res[0] end |
#dependencies ⇒ Object
52 53 54 |
# File 'lib/blocks/block.rb', line 52 def dependencies @dependencies ||= [] end |
#execute ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 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 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/blocks/block.rb', line 394 def execute if (@inDeps) if Bake..verbose >= 3 SyncOut.mutex.synchronize do Bake.formatter.printWarning("While calculating next config, a circular dependency was found including project #{@projectName} with config #{@configName}", @config) end end return true end return true if (@visited) @visited = true @inDeps = true depResult = callDeps(:execute) @inDeps = false return @result && depResult if blockAbort?(depResult) Bake::IDEInterface.instance.set_build_info(@projectName, @configName) begin SyncOut.mutex.synchronize do @outputStep = nil SyncOut.startStream() if Bake..syncedOutput if !Bake..skipBuildingLine && (Bake..verbose >= 2 || (isBuildBlock? && Bake..verbose >= 1)) typeStr = "Building" if @prebuild typeStr = "Using" elsif not isBuildBlock? typeStr = "Applying" end bcStr = ">>CONF_NUM<<" if !Bake..syncedOutput bcStr = Block.block_counter Block.inc_block_counter() end Bake.formatter.printAdditionalInfo "**** #{typeStr} #{bcStr} of #{@@num_projects}: #{@projectName} (#{@configName}) ****" end puts "Project path: #{@projectDir}" if Bake..projectPaths end @result = callSteps(:execute) ensure if Bake..syncedOutput if !@outputStep SyncOut.stopStream() else SyncOut.discardStreams() end end end return (depResult && @result) end |
#execute_in_thread(steps) ⇒ Object
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 |
# File 'lib/blocks/block.rb', line 301 def execute_in_thread(steps) @@mutex.synchronize do Block::waitForFreeThread() return if blockAbort?(true) tmpstdout = Thread.current[:tmpStdout].nil? ? nil : Thread.current[:tmpStdout].dup @@threads << Thread.new(Thread.current[:stdout], tmpstdout, steps) { |outStr, tmpStdout, steps| STDOUT.puts "DEBUG_THREADS: Started: #{Thread.current.object_id} (#{@projectName}, #{@config.name})" if Bake..debug_threads Thread.current[:stdout] = outStr Thread.current[:tmpStdout] = tmpStdout Thread.current[:steps] = steps exceptionOccured = false begin yield exceptionOccured = true rescue Bake::SystemCommandFailed => scf # normal compilation error rescue SystemExit => exSys rescue AbortException => exSys Bake::IDEInterface.instance.set_abort(true) rescue Exception => ex1 if !Bake::IDEInterface.instance.get_abort SyncOut.mutex.synchronize do Bake.formatter.printError("Error: #{ex1.}") puts ex1.backtrace if Bake..debug end end end if !exceptionOccured @result = false @@delayed_result = false end STDOUT.puts "DEBUG_THREADS: Stopped: #{Thread.current.object_id} (#{@projectName}, #{@config.name})" if Bake..debug_threads } Block::waitForFreeThread() return if blockAbort?(true) end raise AbortException.new if Bake::IDEInterface.instance.get_abort end |
#executeStep(step, method) ⇒ Object
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 |
# File 'lib/blocks/block.rb', line 233 def executeStep(step, method) begin @result = step.send(method) && @result rescue Bake::SystemCommandFailed => scf @result = false ProcessHelper.killProcess(true) rescue SystemExit => exSys @result = false ProcessHelper.killProcess(true) rescue Exception => ex1 @result = false if not Bake::IDEInterface.instance.get_abort SyncOut.mutex.synchronize do Bake.formatter.printError("Error: #{ex1.}") puts ex1.backtrace if Bake..debug end end end if Bake::IDEInterface.instance.get_abort raise AbortException.new end # needed for ctrl-c in Cygwin console ##################################### # additionally, the user has to enable raw mode of Cygwin console: "stty raw". # raw mode changes the signals into raw characters. # original problem: Cygwin is compiled with broken control handler config, # which might not be changed due to backward compatibility. # the control handler works only with programs compiled under Cygwin, which is # not true for Windows RubyInstaller packages. ctrl_c_found = false begin @@mutexStdinSelect.synchronize do while IO.select([$stdin],nil,nil,0) do nextChar = $stdin.sysread(1) if nextChar == "\x03" ctrl_c_found = true end end end rescue Exception => e end raise AbortException.new if ctrl_c_found return @result end |
#exits ⇒ Object
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/blocks/block.rb', line 517 def exits return true if (@visited) @visited = true depResult = callDeps(:exits) if Bake..verbose >= 1 and not exitSteps.empty? Bake.formatter.printAdditionalInfo "**** Exiting #{@projectName} (#{@configName}) ****" end exitSteps.each do |step| @result = executeStep(step, :exitStep) && @result end return (depResult && @result) end |
#exitSteps ⇒ Object
44 45 46 |
# File 'lib/blocks/block.rb', line 44 def exitSteps @exitSteps ||= [] end |
#getBlocks(method) ⇒ Object
543 544 545 546 547 |
# File 'lib/blocks/block.rb', line 543 def getBlocks(method) @otherBlocks = [] getSubBlocks(self, method) return @otherBlocks end |
#getCompileBlocks ⇒ Object
90 91 92 |
# File 'lib/blocks/block.rb', line 90 def getCompileBlocks() mainSteps.select { |m| Compile === m } end |
#getSubBlocks(b, method) ⇒ Object
534 535 536 537 538 539 540 541 |
# File 'lib/blocks/block.rb', line 534 def getSubBlocks(b, method) b.send(method).each do |child_b| if not @otherBlocks.include?child_b and not child_b == self @otherBlocks << child_b getSubBlocks(child_b, method) end end end |
#independent?(method, step) ⇒ Boolean
346 347 348 349 350 |
# File 'lib/blocks/block.rb', line 346 def independent?(method, step) method == :execute && (Library === step || Compile === step || (CommandLine === step && step.config.independent) || (Makefile === step && step.config.independent)) end |
#isBuildBlock? ⇒ Boolean
216 217 218 219 |
# File 'lib/blocks/block.rb', line 216 def isBuildBlock? return true if Bake..conversion_info @isBuildBlock ||= calcIsBuildBlock end |
#isMainProject? ⇒ Boolean
549 550 551 |
# File 'lib/blocks/block.rb', line 549 def isMainProject? @projectName == Bake..main_project_name and @config.name == Bake..build_config end |
#mainSteps ⇒ Object
36 37 38 |
# File 'lib/blocks/block.rb', line 36 def mainSteps @mainSteps ||= [] end |
#parents ⇒ Object
60 61 62 |
# File 'lib/blocks/block.rb', line 60 def parents @parents ||= [] end |
#postSteps ⇒ Object
40 41 42 |
# File 'lib/blocks/block.rb', line 40 def postSteps @postSteps ||= [] end |
#preSteps ⇒ Object
32 33 34 |
# File 'lib/blocks/block.rb', line 32 def preSteps @preSteps ||= [] end |
#qname ⇒ Object
68 69 70 |
# File 'lib/blocks/block.rb', line 68 def qname() @projectName + "," + @configName end |
#set_library(library) ⇒ Object
64 65 66 |
# File 'lib/blocks/block.rb', line 64 def set_library(library) @library = library end |
#startup ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/blocks/block.rb', line 500 def startup return true if (@visited) @visited = true depResult = callDeps(:startup) if Bake..verbose >= 1 and not startupSteps.empty? Bake.formatter.printAdditionalInfo "**** Starting up #{@projectName} (#{@configName}) ****" end startupSteps.each do |step| @result = executeStep(step, :startupStep) && @result end return (depResult && @result) end |
#startupSteps ⇒ Object
28 29 30 |
# File 'lib/blocks/block.rb', line 28 def startupSteps @startupSteps ||= [] end |