#! /usr/bin/ruby -w # :main: README require 'rake' require 'ostruct' require 'optparse' require 'autobuild/options' require 'autobuild/config' require 'autobuild/logging' require 'daemons' DEFAULT_HTTP_PORT = 2000 def parse_options(args) options = Options.default parser = OptionParser.new do |opts| opts.banner = "Usage: autobuild [options] config.yml" opts.separator "" opts.on("--srcdir PATH", "Find or imports sources in PATH") do |options.srcdir| end opts.on("--prefix PATH", "Packages are installed in PATH") do |options.prefix| options.logdir = "#{options.prefix}/autobuild" end opts.on("--logdir", "Where logs are saved (default: /autobuild)") do |options.logdir| end opts.on("--[no-]update", "Update already checked-out sources") do |options.update| end opts.on('--nice NICE', Integer, 'Nice the subprocesses to the given value') do |options.nice| end opts.on("--[no-]daemon", "Go into daemon mode") do |options.daemonize| end #opts.on("--http [PORT]", Integer, # "Display a HTTP information page on PORT (PORT default: #{DEFAULT_HTTP_PORT})") do |port| # options.http = (port || DEFAULT_HTTP_PORT) #end opts.on("--[no-]verbose", "Display output of commands on stdout") do |options.verbose| end opts.on("--[no-]debug", "Verbose information (for debugging purposes)") do |options.debug| end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end parser.parse!(args) if !args[0] puts parser exit end [ options, args[0], args[1..-1] ] end # Load the command line options options, conffile, targets = parse_options(ARGV) # make conffile an absolute path since daemonize mode makes # / the current directory conffile = File.expand_path(conffile, Dir.pwd) if options.daemonize puts "Going into daemon mode ..." Daemons.daemonize end File.open(conffile) do |f| Config.load(f, options) end begin if targets.empty? Rake::Task[:default].invoke else targets.each { |t| Rake::Task[t.to_sym].invoke } end success rescue BuildException => error error(error, "Error during build of #{error.target}") exit(1) end