diff options
author | Steven Davidovitz <sdavidovitz@zendesk.com> | 2013-09-05 13:59:17 -0700 |
---|---|---|
committer | Steven Davidovitz <sdavidovitz@zendesk.com> | 2013-09-05 16:09:06 -0700 |
commit | c08f17656256ad390f080645883c6984646ef412 (patch) | |
tree | a51a8711e048580526afeba9f7aad7520ec75844 | |
parent | c17c215411e62ff4de64d5bfa51ca3a74a0b89b4 (diff) | |
download | bundler-c08f17656256ad390f080645883c6984646ef412.tar.gz |
Exec: add option for ruby 1.9 FD behavior for 2.0
Ruby 2.0 changed the behavior of file descriptors when doing a Kernel.exec.
Where in 1.9 it wouldn't automatically close non-standard file descriptors
when doing a Kernel.exec, in 2.0 the default is to close them.
Issue #2628
-rw-r--r-- | lib/bundler/cli.rb | 7 | ||||
-rw-r--r-- | spec/commands/exec_spec.rb | 31 |
2 files changed, 38 insertions, 0 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index a1c54cf4fb..d180cade61 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -513,6 +513,7 @@ module Bundler map %w(pack) => :package desc "exec", "Run the command in context of the bundle" + method_options :keep_file_descriptors => :boolean long_desc <<-D Exec runs a command, providing it access to the gems in the bundle. While using bundle exec you can require and call the bundled gems as if they were installed @@ -523,6 +524,12 @@ module Bundler Bundler.load.setup_environment begin + # Ruby 2.0 changed the default file descriptor + # behavior for #exec, this option forces 1.9 behavior + if RUBY_VERSION >= "2.0" && options.keep_file_descriptors? + args << { :close_others => false } + end + # Run Kernel.exec(*args) rescue Errno::EACCES diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index ed03e2b0a9..3a932adcbc 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -57,6 +57,37 @@ describe "bundle exec" do expect(out).to eq("--verbose") end + it "handles --keep-file-descriptors" do + require 'tempfile' + + bundle_bin = File.expand_path('../../../bin/bundle', __FILE__) + + command = Tempfile.new("io-test") + command.sync = true + command.write <<-G + if ARGV[0] + IO.for_fd(ARGV[0].to_i) + else + require 'tempfile' + io = Tempfile.new("io-test-fd") + args = %W[#{Gem.ruby} -I#{lib} #{bundle_bin} exec --keep-file-descriptors #{Gem.ruby} #{command.path} \#{io.to_i}] + args << { io.to_i => io } if RUBY_VERSION >= "2.0" + exec(*args) + end + G + + install_gemfile '' + sys_exec("#{Gem.ruby} #{command.path}") + expect(out).to eq("") + expect(err).to eq("") + end + + it "accepts --keep-file-descriptors" do + install_gemfile '' + bundle "exec --keep-file-descriptors echo foobar" + expect(out).to eq("foobar") + end + it "can run a command named --verbose" do install_gemfile 'gem "rack"' File.open("--verbose", 'w') do |f| |