From 75b782b66469419e545b8e3a26b3ed19c8cad784 Mon Sep 17 00:00:00 2001 From: Klaas Jan Wierenga Date: Thu, 2 May 2013 12:39:23 +0200 Subject: [PATCH] Use POSIX::Spawn to make foreman ruby 1.8 compatible and have all specs passing. --- Gemfile | 2 +- lib/foreman/process.rb | 10 +--------- spec/spec_helper.rb | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 3470ea2..da92b31 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ platform :mingw do gem "win32console", "~> 1.3.0" end -platform :jruby do +platform :jruby, :ruby_18 do gem "posix-spawn", "~> 0.3.6" end diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 2abcb82..39cb4c5 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -52,18 +52,10 @@ class Foreman::Process Dir.chdir(cwd) do Process.spawn env, expanded_command(env), :out => output, :err => output end - elsif Foreman.jruby_18? + elsif Foreman.jruby_18? || Foreman.ruby_18? require "posix/spawn" wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}" POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output - elsif Foreman.ruby_18? - fork do - $stdout.reopen output - $stderr.reopen output - env.each { |k,v| ENV[k] = v } - wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}" - Kernel.exec wrapped_command - end else wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}" Process.spawn env, wrapped_command, :out => output, :err => output diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b9f3efe..76676ee 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,7 +36,12 @@ end def forked_foreman(args) rd, wr = make_pipe - Process.spawn("bundle exec bin/foreman #{args}", :out => wr, :err => wr) + if Foreman.jruby_18? || Foreman.ruby_18? + require 'posix/spawn' + POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => wr, :err => wr) + else + Process.spawn("bundle exec bin/foreman #{args}", :out => wr, :err => wr) + end wr.close rd.read end @@ -61,7 +66,12 @@ def fork_and_capture(&blk) end def fork_and_get_exitstatus(args) - pid = Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null") + pid = if Foreman.jruby_18? || Foreman.ruby_18? + require 'posix/spawn' + POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null") + else + Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null") + end Process.wait(pid) $?.exitstatus end