summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2013-09-06 23:11:20 -0700
committerAndre Arko <andre@arko.net>2013-09-06 23:11:20 -0700
commitdd39f55d1ca9e3bda73a805fd80aa118c5f60e39 (patch)
tree199dbe95274aaf737b86ab3ba5460f42c4e42c4d
parent48edb4be7602bead2e452d77effade30e3e8763b (diff)
parent21bc281c4fa58fcf210c8b023177cf9fb30665c2 (diff)
downloadbundler-dd39f55d1ca9e3bda73a805fd80aa118c5f60e39.tar.gz
Merge pull request #2629 from steved555/master
Exec: add option for ruby 1.9 FD behavior for 2.0
-rw-r--r--lib/bundler/cli.rb7
-rw-r--r--man/bundle-exec.ronn9
-rw-r--r--spec/commands/exec_spec.rb38
3 files changed, 53 insertions, 1 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 232d518333..07d437ac4f 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -517,6 +517,7 @@ module Bundler
map %w(pack) => :package
desc "exec", "Run the command in context of the bundle"
+ method_option :keep_file_descriptors, :type => :boolean, :default => false
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
@@ -527,6 +528,12 @@ module Bundler
Bundler.load.setup_environment
begin
+ if RUBY_VERSION >= "2.0"
+ args << { :close_others => !options.keep_file_descriptors? }
+ elsif options.keep_file_descriptors?
+ Bundler.ui.warn "Ruby version #{RUBY_VERSION} defaults to keeping non-standard file descriptors on Kernel#exec."
+ end
+
# Run
Kernel.exec(*args)
rescue Errno::EACCES
diff --git a/man/bundle-exec.ronn b/man/bundle-exec.ronn
index 43f61c60b5..4d168d4196 100644
--- a/man/bundle-exec.ronn
+++ b/man/bundle-exec.ronn
@@ -3,7 +3,7 @@ bundle-exec(1) -- Execute a command in the context of the bundle
## SYNOPSIS
-`bundle exec` <command>
+`bundle exec` <command> [--keep-file-descriptors]
## DESCRIPTION
@@ -18,6 +18,13 @@ should run `bundle exec rspec spec/my_spec.rb`.
Note that `bundle exec` does not require that an executable is
available on your shell's `$PATH`.
+## OPTIONS
+
+* `--keep-file-descriptors`:
+ Ruby 2.0's default Kernel#exec behavior discards non-standard file descriptors.
+ This option enabled Ruby <= 1.9's default behavior and passes all file descriptors
+ to the new command.
+
## BUNDLE INSTALL --BINSTUBS
If you use the `--binstubs` flag in [bundle install(1)][bundle-install], Bundler will
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index ed03e2b0a9..0e20b4685f 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -57,6 +57,44 @@ 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}")
+
+ if RUBY_VERSION >= "2.0"
+ expect(out).to eq("")
+ else
+ expect(out).to eq("Ruby version #{RUBY_VERSION} defaults to keeping non-standard file descriptors on Kernel#exec.")
+ end
+
+ expect(err).to eq("")
+ end
+
+ it "accepts --keep-file-descriptors" do
+ install_gemfile ''
+ bundle "exec --keep-file-descriptors echo foobar"
+
+ expect(err).to eq("")
+ end
+
it "can run a command named --verbose" do
install_gemfile 'gem "rack"'
File.open("--verbose", 'w') do |f|