Merge pull request #359 from kjwierenga/feature/make-ruby-18-compatible
Fix specs that were broken on ruby 1.8. Use POSIX::Spawn.spawn to make foreman robust on ruby 1.8.7.
This commit is contained in:
@@ -2,7 +2,6 @@ script: bundle exec rake spec
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- rvm: 1.8.7
|
|
||||||
- rvm: jruby
|
- rvm: jruby
|
||||||
- rvm: rbx
|
- rvm: rbx
|
||||||
- rvm: ree
|
- rvm: ree
|
||||||
@@ -16,6 +15,7 @@ notifications:
|
|||||||
- http://dx-helper.herokuapp.com/travis
|
- http://dx-helper.herokuapp.com/travis
|
||||||
|
|
||||||
rvm:
|
rvm:
|
||||||
|
- 1.8.7
|
||||||
- 1.9.2
|
- 1.9.2
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- 2.0.0
|
- 2.0.0
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -6,7 +6,7 @@ platform :mingw do
|
|||||||
gem "win32console", "~> 1.3.0"
|
gem "win32console", "~> 1.3.0"
|
||||||
end
|
end
|
||||||
|
|
||||||
platform :jruby do
|
platform :jruby, :ruby_18 do
|
||||||
gem "posix-spawn", "~> 0.3.6"
|
gem "posix-spawn", "~> 0.3.6"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
require "foreman"
|
require "foreman"
|
||||||
|
require "shellwords"
|
||||||
|
|
||||||
class Foreman::Process
|
class Foreman::Process
|
||||||
|
|
||||||
@@ -52,18 +53,10 @@ class Foreman::Process
|
|||||||
Dir.chdir(cwd) do
|
Dir.chdir(cwd) do
|
||||||
Process.spawn env, expanded_command(env), :out => output, :err => output
|
Process.spawn env, expanded_command(env), :out => output, :err => output
|
||||||
end
|
end
|
||||||
elsif Foreman.jruby_18?
|
elsif Foreman.jruby_18? || Foreman.ruby_18?
|
||||||
require "posix/spawn"
|
require "posix/spawn"
|
||||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{expanded_command(env)}"
|
||||||
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
|
POSIX::Spawn.spawn(*spawn_args(env, wrapped_command.shellsplit, {: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
|
else
|
||||||
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
wrapped_command = "#{Foreman.runner} -d '#{cwd}' -p -- #{command}"
|
||||||
Process.spawn env, wrapped_command, :out => output, :err => output
|
Process.spawn env, wrapped_command, :out => output, :err => output
|
||||||
@@ -122,4 +115,14 @@ class Foreman::Process
|
|||||||
File.expand_path(@options[:cwd] || ".")
|
File.expand_path(@options[:cwd] || ".")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def spawn_args(env, argv, options)
|
||||||
|
args = []
|
||||||
|
args << env
|
||||||
|
args += argv
|
||||||
|
args << options
|
||||||
|
args
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ describe Foreman::Process do
|
|||||||
|
|
||||||
it "should output utf8 properly" do
|
it "should output utf8 properly" do
|
||||||
process = Foreman::Process.new(resource_path("bin/utf8"))
|
process = Foreman::Process.new(resource_path("bin/utf8"))
|
||||||
run(process).should == "\xFF\x03\n".force_encoding('binary')
|
run(process).should == (Foreman.ruby_18? ? "\xFF\x03\n" : "\xFF\x03\n".force_encoding('binary'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ def mock_error(subject, message)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_pipe
|
||||||
|
IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
|
||||||
|
end
|
||||||
|
|
||||||
def foreman(args)
|
def foreman(args)
|
||||||
capture_stdout do
|
capture_stdout do
|
||||||
begin
|
begin
|
||||||
@@ -31,14 +35,19 @@ def foreman(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def forked_foreman(args)
|
def forked_foreman(args)
|
||||||
rd, wr = IO.pipe("BINARY")
|
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
|
wr.close
|
||||||
rd.read
|
rd.read
|
||||||
end
|
end
|
||||||
|
|
||||||
def fork_and_capture(&blk)
|
def fork_and_capture(&blk)
|
||||||
rd, wr = IO.pipe("BINARY")
|
rd, wr = make_pipe
|
||||||
pid = fork do
|
pid = fork do
|
||||||
rd.close
|
rd.close
|
||||||
wr.sync = true
|
wr.sync = true
|
||||||
@@ -57,7 +66,12 @@ def fork_and_capture(&blk)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fork_and_get_exitstatus(args)
|
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)
|
Process.wait(pid)
|
||||||
$?.exitstatus
|
$?.exitstatus
|
||||||
end
|
end
|
||||||
@@ -141,7 +155,7 @@ end
|
|||||||
|
|
||||||
def capture_stdout
|
def capture_stdout
|
||||||
old_stdout = $stdout.dup
|
old_stdout = $stdout.dup
|
||||||
rd, wr = IO.method(:pipe).arity.zero? ? IO.pipe : IO.pipe("BINARY")
|
rd, wr = make_pipe
|
||||||
$stdout = wr
|
$stdout = wr
|
||||||
yield
|
yield
|
||||||
wr.close
|
wr.close
|
||||||
|
|||||||
Reference in New Issue
Block a user