lib/autobuild/subcommand.rb in autobuild-0.5.1 vs lib/autobuild/subcommand.rb in autobuild-0.6
- old
+ new
@@ -1,13 +1,9 @@
+require 'autobuild/exceptions'
require 'autobuild/reporting'
module Autobuild::Subprocess
- @@nice = 0
- def self.nice=(value)
- @@nice = value
- end
-
class Failed < Exception
attr_reader :status
def initialize(status = 0)
@status = status
end
@@ -17,12 +13,14 @@
CONTROL_UNEXPECTED = 2
def self.run(target, phase, *command)
# Filter nil and empty? in command
command.reject! { |o| o.nil? || (o.respond_to?(:empty?) && o.empty?) }
command.collect! { |o| o.to_s }
- logname = "#{$LOGDIR}/#{target}-#{phase}.log"
+ FileUtils.mkdir_p Autobuild.logdir unless File.directory?(Autobuild.logdir)
+ logname = "#{Autobuild.logdir}/#{target}-#{phase}.log"
+
puts "#{target}: running #{command.join(" ")}\n (output goes to #{logname})"
input_streams = command.collect { |o| $1 if o =~ /^\<(.+)/ }.compact
command.reject! { |o| o =~ /^\<(.+)/ }
@@ -31,12 +29,12 @@
cread, cwrite = IO.pipe # to control that exec goes well
pid = fork {
cwrite.sync = true
begin
- Process.setpriority(Process::PRIO_PROCESS, 0, @@nice)
- if $VERBOSE
+ Process.setpriority(Process::PRIO_PROCESS, 0, Autobuild.nice)
+ if Autobuild.verbose
$stderr.dup.reopen(logfile.dup)
$stdout.dup.reopen(logfile.dup)
else
$stderr.reopen(logfile.dup)
$stdout.reopen(logfile.dup)
@@ -90,10 +88,10 @@
if status.exitstatus > 0
raise Failed.new(status.exitstatus), "command returned with status #{status.exitstatus}"
end
rescue Failed => e
- error = SubcommandFailed.new(target, command.join(" "), logname, e.status)
+ error = Autobuild::SubcommandFailed.new(target, command.join(" "), logname, e.status)
error.phase = phase
raise error, e.message
end
end