#!/usr/bin/env ruby $timeStart = Time.now $:.unshift(File.dirname(__FILE__)+"/../lib") require 'common/version' require 'common/utils' Bake::Version.printBakeryVersion STDOUT.sync = true STDERR.sync = true $stars = "************************************************" require 'bake/toolchain/colorizing_formatter' require 'bake/options/options' require 'tocxx' require "bakery/model/loader" require "bakery/options/options" require "bakery/toBake" require "bakery/buildPattern" require 'common/ext/stdout' require 'common/cleanup' module Bake @options = BakeryOptions.new(ARGV) bakeOptions = Options.new([]) @options.parse_options(bakeOptions) env = nil begin loader = BakeryLoader.new env = loader.load(@options.collection_dir+"/Collection.meta") rescue SystemExit => e raise e rescue Exception => e puts e puts e.backtrace ExitHelper.exit(1) end if @options.collection_name.empty? puts "Please specify a collection name. Possible values are:" env.find(:class => BakeryModel::Collection).each { |e| puts "* " + e.name } ExitHelper.exit(0) end def self.getCollections(env, name) cols = env.find(:class => BakeryModel::Collection, :name => name) @toBuild |= getBuildPattern(cols, name) @colsAll |= cols cols[0].collections.each do |cRef| alreadyProcessed = false @colsAll.each do |ca| alreadyProcessed = true if ca.name == cRef.name end getCollections(env, cRef.name) unless alreadyProcessed end end @toBuild = [] @colsAll = [] getCollections(env, @options.collection_name) maxRuns = @toBuild.length currentRun = 0 failedRuns = [] passedParams = [] excludeParam = false wasMinus = false ARGV.each do |x| if (x=="-b" or x=="-m" or x=="--socket") excludeParam = true next end if excludeParam excludeParam = false next end if x.length > 0 if x[0] == "-" wasMinus = true else next if not wasMinus wasMinus = false end end passedParams << x end if @options.socket != 0 Bake::IDEInterface.instance.connect(@options.socket) end msg1 = "bakery " exitValue = 0 abort = false @toBuild.each do |bp| currentRun += 1 p = File.dirname(bp.proj) pRel = File.rel_from_to_project(Dir.pwd, p, false) pRel = "." if pRel.empty? cmd = (["-m", pRel, "-b", bp.conf] + passedParams) cmdWithNum = "bakery #{currentRun} of #{maxRuns}: bake " + cmd.join(" ") puts "\n#{$stars}" Bake.formatter.printInfo(cmdWithNum) puts $stars runOk = false begin Bake.options = Options.new(cmd) Bake.options.parse_options tocxx = ToCxx.new tocxx.doit() runOk = (ExitHelper.exit_code == 0) if Bake::IDEInterface.instance.get_abort abort = true msg1 << "aborted" exitValue = 1 break end rescue SystemExit runOk = (ExitHelper.exit_code == 0) rescue Exception => e puts e.message end Bake::cleanup ExitHelper.reset_exit_code if runOk == false exitValue = 1 failedRuns << "bake " + cmd.join(" ") if @options.error msg1 << "aborted" abort = true break end end end print "\n" if not abort if failedRuns.length > 0 msg1 << "summary: #{failedRuns.length} of #{maxRuns} builds failed" else msg1 << "summary: #{maxRuns} of #{maxRuns} builds ok" end timeEnd = Time.now timeDiff = timeEnd - $timeStart failedRuns.each_with_index do |f,i| msg1 << "\n#{i+1}: #{f}" end msg1 << "\ntime: %02d:%02d minutes" % [timeDiff/60, timeDiff%60] end if failedRuns.length == 0 Bake.formatter.printSuccess($stars) Bake.formatter.printSuccess(msg1) Bake.formatter.printSuccess($stars) else Bake.formatter.printError($stars) Bake.formatter.printError(msg1) Bake.formatter.printError($stars) end Bake::IDEInterface.instance.disconnect() ExitHelper.exit(exitValue) end