From c8ab130adead37646fa7b91df0d4a1b7dc50d859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 9 Dec 2019 19:13:32 +0100 Subject: [PATCH] Fix `bundle exec rake install` not working These gem task checks for a specific string in the gem subcommand output. However, if we are inside a bundled environment (`bundle exec rake install` instead of `rake install`), the ruby process will require `bundler/setup` first thing, and initialize a silent UI for rubygems. As a result, the output string will be always empty and the condition for success will always fail. So, even if installation succeeded, user will always be notified of a failure like: ``` foo 1.0 built to pkg/foo-1.0.gem. rake aborted! Couldn't install gem, run `gem install /home/deivid/Code/bundler/tmp/1/bundled_app/pkg/foo-1.0.gem' for more detailed output ... ``` --- lib/bundler/gem_helper.rb | 2 +- spec/runtime/gem_tasks_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index b510572cb86..96c1dd807da 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -86,7 +86,7 @@ def install_gem(built_gem_path = nil, local = false) built_gem_path ||= build_gem cmd = "#{gem_command} install #{built_gem_path}" cmd += " --local" if local - out, status = sh_with_status(cmd.shellsplit) + out, status = Bundler.with_original_env { sh_with_status(cmd.shellsplit) } unless status.success? && out[/Successfully installed/] raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" end diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb index 17b1efdfb3b..4feda3605fd 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/runtime/gem_tasks_spec.rb @@ -6,15 +6,27 @@ f.write <<-GEMSPEC Gem::Specification.new do |s| s.name = "foo" + s.version = "1.0" + s.summary = "dummy" + s.author = "Perry Mason" end GEMSPEC end + bundled_app("Rakefile").open("w") do |f| f.write <<-RAKEFILE $:.unshift("#{lib_dir}") require "bundler/gem_tasks" RAKEFILE end + + system_gems :bundler + + install_gemfile! <<-G, :system_bundler => true + source "#{file_uri_for(gem_repo1)}" + + gem "rake" + G end it "includes the relevant tasks" do @@ -35,6 +47,20 @@ expect(exitstatus).to eq(0) if exitstatus end + it "defines a working `rake install` task" do + with_gem_path_as(Spec::Path.base_system_gems.to_s) do + sys_exec "#{rake} install", "RUBYOPT" => "-I#{lib_dir}" + end + + expect(err).to be_empty + + with_gem_path_as(Spec::Path.base_system_gems.to_s) do + bundle! "exec rake install" + end + + expect(err).to be_empty + end + it "adds 'pkg' to rake/clean's CLOBBER" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect')