Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #4727 - asutoshpalai:exec-signal-fix, r=segiddins
Browse files Browse the repository at this point in the history
Fixes INT signal for ruby executables

Fixes #4568
  • Loading branch information
homu committed Jun 28, 2016
2 parents a13baad + 5fcd26d commit 99a9a15
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 20 deletions.
4 changes: 4 additions & 0 deletions lib/bundler/cli/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Bundler
class CLI::Exec
attr_reader :options, :args, :cmd

RESERVED_SIGNALS = %w(SEGV BUS ILL FPE VTALRM KILL STOP).freeze

def initialize(options, args)
@options = options
@cmd = args.shift
Expand Down Expand Up @@ -60,6 +62,8 @@ def kernel_load(file, *args)
ui = Bundler.ui
Bundler.ui = nil
require "bundler/setup"
signals = Signal.list.keys - RESERVED_SIGNALS
signals.each {|s| trap(s, "DEFAULT") }
Kernel.load(file)
rescue SystemExit
raise
Expand Down
18 changes: 9 additions & 9 deletions spec/commands/console_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
end

it "starts IRB with the default group loaded" do
bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("puts RACK")
input.puts("exit")
end
expect(out).to include("0.9.1")
end

it "uses IRB as default console" do
bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("__method__")
input.puts("exit")
end
Expand All @@ -34,7 +34,7 @@
G
bundle "config console pry"

bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("__method__")
input.puts("exit")
end
Expand All @@ -45,15 +45,15 @@
bundle "config console pry"
# make sure pry isn't there

bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("__method__")
input.puts("exit")
end
expect(out).to include(":irb_binding")
end

it "doesn't load any other groups" do
bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("puts ACTIVESUPPORT")
input.puts("exit")
end
Expand All @@ -62,23 +62,23 @@

describe "when given a group" do
it "loads the given group" do
bundle "console test" do |input|
bundle "console test" do |input, _, _|
input.puts("puts ACTIVESUPPORT")
input.puts("exit")
end
expect(out).to include("2.3.5")
end

it "loads the default group" do
bundle "console test" do |input|
bundle "console test" do |input, _, _|
input.puts("puts RACK")
input.puts("exit")
end
expect(out).to include("0.9.1")
end

it "doesn't load other groups" do
bundle "console test" do |input|
bundle "console test" do |input, _, _|
input.puts("puts RACK_MIDDLEWARE")
input.puts("exit")
end
Expand All @@ -96,7 +96,7 @@
G

bundle "config auto_install 1"
bundle :console do |input|
bundle :console do |input, _, _|
input.puts("puts 'hello'")
input.puts("exit")
end
Expand Down
27 changes: 27 additions & 0 deletions spec/commands/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,32 @@ def bin_path(a,b,c)

it_behaves_like "it runs"
end

context "signals being trapped by bundler" do
let(:executable) { strip_whitespace <<-RUBY }
#{shebang}
begin
Thread.new do
puts 'Started' # For process sync
STDOUT.flush
sleep 1 # ignore quality_spec
raise "Didn't receive INT at all"
end.join
rescue Interrupt
puts "foo"
end
RUBY

it "receives the signal" do
skip "popen3 doesn't provide a way to get pid " unless RUBY_VERSION >= "1.9.3"

bundle("exec #{path}") do |_, o, thr|
o.gets # Consumes 'Started' and ensures that thread has started
Process.kill("INT", thr.pid)
end

expect(out).to eq("foo")
end
end
end
end
6 changes: 3 additions & 3 deletions spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def create_temporary_dir(dir)
it "asks about test framework" do
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false"

bundle "gem foobar" do |input|
bundle "gem foobar" do |input, _, _|
input.puts "rspec"
end

Expand All @@ -766,7 +766,7 @@ def create_temporary_dir(dir)

bundle :config

bundle "gem foobar" do |input|
bundle "gem foobar" do |input, _, _|
input.puts "yes"
end

Expand All @@ -776,7 +776,7 @@ def create_temporary_dir(dir)
it "asks about CoC" do
global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false"

bundle "gem foobar" do |input|
bundle "gem foobar" do |input, _, _|
input.puts "yes"
end

Expand Down
2 changes: 1 addition & 1 deletion spec/commands/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

it "select the gem from many match gems" do
env = { "EDITOR" => "echo editor", "VISUAL" => "echo visual", "BUNDLER_EDITOR" => "echo bundler_editor" }
bundle "open active", :env => env do |input|
bundle "open active", :env => env do |input, _, _|
input.puts "2"
end

Expand Down
4 changes: 2 additions & 2 deletions spec/other/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def should_be_patchlevel_fixnum
#{ruby_version_correct}
G

bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("puts RACK")
input.puts("exit")
end
Expand All @@ -947,7 +947,7 @@ def should_be_patchlevel_fixnum
#{ruby_version_correct_engineless}
G

bundle "console" do |input|
bundle "console" do |input, _, _|
input.puts("puts RACK")
input.puts("exit")
end
Expand Down
6 changes: 4 additions & 2 deletions spec/quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def check_for_debugging_mechanisms(filename)

failing_lines = []
File.readlines(filename).each_with_index do |line, number|
failing_lines << number + 1 if line =~ debugging_mechanisms_regex
if line =~ debugging_mechanisms_regex && !line.end_with?("# ignore quality_spec\n")
failing_lines << number + 1
end
end

return if failing_lines.empty?
Expand Down Expand Up @@ -200,7 +202,7 @@ def check_for_specific_pronouns(filename)
lib_files = `git ls-files -z`.split("\x0").grep(/\.rb$/) - exclusions
lib_files.reject! {|f| f.start_with?("bundler/vendor") }
lib_files.map! {|f| f.chomp(".rb") }
sys_exec("ruby -w -I. ", :expect_err) do |input|
sys_exec("ruby -w -I. ", :expect_err) do |input, _, _|
lib_files.each do |f|
input.puts "require '#{f}'"
end
Expand Down
6 changes: 3 additions & 3 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def bundle(cmd, options = {})
end.join

cmd = "#{env} #{sudo} #{Gem.ruby} -I#{lib}:#{spec} #{requires_str} #{bundle_bin} #{cmd}#{args}"
sys_exec(cmd, expect_err) {|i| yield i if block_given? }
sys_exec(cmd, expect_err) {|i, o, thr| yield i, o, thr if block_given? }
end
bang :bundle

Expand All @@ -116,7 +116,7 @@ def bundle_ruby(options = {})
env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join
cmd = "#{env}#{Gem.ruby} -I#{lib} #{requires_str} #{bundle_bin}"

sys_exec(cmd, expect_err) {|i| yield i if block_given? }
sys_exec(cmd, expect_err) {|i, o, thr| yield i, o, thr if block_given? }
end

def ruby(ruby, options = {})
Expand Down Expand Up @@ -151,7 +151,7 @@ def gembin(cmd)

def sys_exec(cmd, expect_err = false)
Open3.popen3(cmd.to_s) do |stdin, stdout, stderr, wait_thr|
yield stdin if block_given?
yield stdin, stdout, wait_thr if block_given?
stdin.close

@out = Thread.new { stdout.read }.value.strip
Expand Down

0 comments on commit 99a9a15

Please sign in to comment.