#! /usr/bin/ruby -w # :main: README require 'rake' require 'ostruct' require 'optparse' require 'autobuild/config' require 'autobuild/logging' require 'daemons' DEFAULT_HTTP_PORT = 2000 def parse_options(args) options = OpenStruct.new options.update = false options.srcdir = nil options.prefix = nil options.builddir = "build" options.logdir = nil options.daemonize = false options.use_http = false $VERBOSE = false 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("--verbose", "Display output of commands on stdout") do |$VERBOSE| 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-]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) if options.daemonize puts "Going into daemon mode ..." Daemons.daemonize end Config.load(conffile, options) $trace = $DEBUG = options.debug 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