lib/autobuild/subcommand.rb in autobuild-1.2.15 vs lib/autobuild/subcommand.rb in autobuild-1.3.0

- old
+ new

@@ -2,11 +2,11 @@ require 'autobuild/reporting' module Autobuild::Subprocess class Failed < Exception attr_reader :status - def initialize(status = 0) + def initialize(status = nil) @status = status end end CONTROL_COMMAND_NOT_FOUND = 1 @@ -20,11 +20,13 @@ logname = "#{Autobuild.logdir}/#{target}-#{phase}.log" if !File.directory?(File.dirname(logname)) FileUtils.mkdir_p File.dirname(logname) end - puts "#{target}: running #{command.join(" ")}\n (output goes to #{logname})" + if Autobuild.verbose + puts "#{target}: running #{command.join(" ")}\n (output goes to #{logname})" + end input_streams = command.collect { |o| $1 if o =~ /^\<(.+)/ }.compact command.reject! { |o| o =~ /^\<(.+)/ } open_flag = if Autobuild.keep_oldlogs then 'a' @@ -41,11 +43,11 @@ logfile.flush pread, pwrite = IO.pipe # to feed subprocess stdin cread, cwrite = IO.pipe # to control that exec goes well - pid = fork { + pid = fork do cwrite.sync = true begin Process.setpriority(Process::PRIO_PROCESS, 0, Autobuild.nice) if Autobuild.verbose $stderr.dup.reopen(logfile.dup) @@ -66,11 +68,11 @@ raise rescue Exception cwrite.write([CONTROL_UNEXPECTED].pack('I')) raise end - } + end # Feed the input pread.close begin input_streams.each do |infile| @@ -88,21 +90,21 @@ value = cread.read(4) if value # An error occured value = value.unpack('I').first if value == CONTROL_COMMAND_NOT_FOUND - raise Failed.new, "file not found" + raise Failed.new, "command '#{command.first}' not found" else raise Failed.new, "something unexpected happened" end end childpid, childstatus = Process.wait2(pid) childstatus end if status.exitstatus > 0 - raise Failed.new(status.exitstatus), "command returned with status #{status.exitstatus}" + raise Failed.new(status.exitstatus), "'#{command.join(' ')}' returned status #{status.exitstatus}" end rescue Failed => e error = Autobuild::SubcommandFailed.new(target, command.join(" "), logname, e.status) error.phase = phase